572
Creating Interaction with ActionScript
Setting color values
You can use the methods of the built-in ColorTransform class (flash.geom.ColorTransform) to
adjust the color of a movie clip. The
rgb
property of the ColorTransform class assigns
hexadecimal red, green, blue (RGB) values to the movie clip. The following example uses
rgb
to change an object’s color, based on which button the user clicks.
To set the color value of a movie clip:
1.
Create a new Flash document and save it as
setrgb.fla
.
2.
Select the Rectangle Tool and draw a large square on the Stage.
3.
Convert the shape to a movie clip symbol and give the symbol an instance name of
car_mc
in the Property inspector.
4.
Create a button symbol named colorChip, place four instances of the button on the Stage,
and name them
red_btn
,
green_btn
,
blue_btn
, and
black_btn
.
5.
Select Frame 1 in the main Timeline, and select Window > Actions.
6.
Add the following code to Frame 1 of the main Timeline:
import flash.geom.ColorTransform;
import flash.geom.Transform;
var colorTrans:ColorTransform = new ColorTransform();
var trans:Transform = new Transform(car_mc);
trans.colorTransform = colorTrans;
7.
To make the blue button change the color of the
car_mc
movie clip to blue, add the
following code to the Actions panel:
blue_btn.onRelease = function() {
colorTrans.rgb = 0x333399; // blue
trans.colorTransform = colorTrans;
};
The preceding snippet of code changes the
rgb
property of the color transform object and
reapplies the color tranform effect to the
car_mc
movie clip whenever the button
is pressed.
Содержание FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
Страница 1: ...Learning ActionScript 2 0 in Flash...
Страница 8: ...8 Contents...
Страница 18: ...18 Introduction...
Страница 30: ...30 What s New in Flash 8 ActionScript...
Страница 66: ...66 Writing and Editing ActionScript 2 0...
Страница 328: ...328 Interfaces...
Страница 350: ...350 Handling Events...
Страница 590: ...590 Creating Interaction with ActionScript...
Страница 710: ...710 Understanding Security...
Страница 730: ...730 Debugging Applications...
Страница 780: ...780 Deprecated Flash 4 operators...
Страница 830: ...830 Index...