Coloring Book - The Code
       by Zelwyn : 17 August
2004

In the previous page, you separated the outlines and the fills, and converted the fills into movie clips containing buttons. In this section you'll add code to them in order to change their color.

The Code
We're going to add the code now.
Add this code to the first frame of the top layer:

_root.fillColor = 0xFFFFFF;

Add this code to the BUTTON inside each movie clip:

on (press) {
color = new Color(this);
color.setRGB(_root.fillColor);
delete color;
}
Optional Step
You can group the outlines together if you want, with Ctrl+G, or Modify > Group.

Now it's on to...

More Code
I'm going to show you the code now.
The code that we put in the first frame of the top layer is:

_root.fillColor = 0xFFFFFF;

And all that does is make it so that when you click before having selected a color, the piece doesn't turn black. If that piece of code wasn't there, the _root.fillColor variable would be undeclared, and would default to 0x000000, or black.

The code that you added to each of the fill buttons was:

on (release) {
color = new Color(this);
color.setRGB(_root.fillColor);
delete color;
}

That makes it so that when you click on the fill, it fills with whatever color _root.fillColor is currently holding, and then deletes that current state of the variable color, so that particular instance is not used again.

This section showed you the first part of the code, and the next section will deal with making buttons, and changing the color contained in _root.fillColor.

Note
You can change the variables "color", not to be confused with "Color", to anything you like, as long as all the references match.

The next page will cover more of the code that makes this color-book style of an animation work.


page 2 of 3


 




SUPPORTERS:

kirupa.com's fast and reliable hosting provided by Media Temple.