# Changing Color

 So far we have learned to move and change the size and rotation of our shapes. Now we will learn to change their colors. A) Begin as always by opening our html page and begining our php code block setLine(5,0,0,255); \$myShape1->setRightFill(255,0,0); \$myShape1->movePen(-30,-30); \$myShape1->drawLine(60,0); \$myShape1->drawLine(0,60); \$myShape1->drawLine(-60,0); \$myShape1->drawLine(0,-60); C) Then, we create our movie as always \$myMovie=new SWFMovie(); \$myMovie->setDimension(200,200); \$myMovie->setBackground(255,255,255); D) Now add our shape to our movie and move it into place \$movingSquare=\$myMovie->add(\$myShape1); \$movingSquare->moveTo(100,100); E) Next, we start a loop to go through the steps of our color change, don't forget the opening bracket at the end! for(\$i=0; \$i<20; \$i++){ F) Our loop is creating a form of animation for our color change, so we need it to advance the frame as with previous animations \$myMovie->nextFrame(); G) Next, we use the multColor function to multiply our shapes color values. By using the loop's value, the \$i variable, we can make the change gradual. Here I have set it to multiply the red color by an increasingly smaller value, making the red slowly fade away. Notice that we multiply the green and blue values by 1 so that we do not change them \$movingSquare->multColor(1.0-\$i/20, 1.0, 1.0); H) Don't forget to close off the loop with the closing bracket! } I) Let's do it again for the blue color in our shape, just for practice for(\$i=0; \$i<20; \$i++){ \$myMovie->nextFrame(); \$movingSquare->multColor(1.0, 1.0, 1.0-\$i/20); } J) Then we finish up by saving our movie and displaying it with our object tags as always \$myMovie->save("lesson9.swf"); ?> Next lesson we will learn to do simple morphs from one shape to another! Code summary for lesson 9: setLine(5,0,0,255); \$myShape1->setRightFill(255,0,0); \$myShape1->movePen(-30,-30); \$myShape1->drawLine(60,0); \$myShape1->drawLine(0,60); \$myShape1->drawLine(-60,0); \$myShape1->drawLine(0,-60); \$myMovie=new SWFMovie(); \$myMovie->setDimension(200,200); \$myMovie->setBackground(255,255,255); \$movingSquare=\$myMovie->add(\$myShape1); \$movingSquare->moveTo(100,100); for(\$i=0; \$i<20; \$i++){ \$myMovie->nextFrame(); \$movingSquare->multColor(1.0-\$i/20, 1.0, 1.0); } for(\$i=0; \$i<20; \$i++){ \$myMovie->nextFrame(); \$movingSquare->multColor(1.0, 1.0, 1.0-\$i/20); } \$myMovie->save("lesson9.swf"); ?> Result: