3.9. Controlling a Movie Clip’s Color with Sliders
This recipe presents a full application that creates sliders for the red, green, blue, and alpha values that control a movie clip’s color:
Create a new Flash document and save it.
On the main timeline, rename the default layer as
movieClips
and create a new layer namedactions
.Create a movie clip symbol and draw a circle in it. The circle should be approximately 120 × 120 pixels.
Return to the main timeline and create an instance of the circle movie clip on the Stage on the
movieClips
layer. Place the instance on the left side of the Stage. Name the instancecircle_mc
using the Property inspector.Open the Components panel (Window → Components) and drag four instances of the ScrollBar component onto the Stage on the
movieClips
layer. Name these instancesred_sb
,green_sb
,blue_sb
, andalpha_sb
. Line them up horizontally on the right side of the Stage.Select the keyframe of the
actions
layer and open the Actions panel.Add the following code to the Actions panel and test the movie (Control → Test Movie). The scrollbars are automatically colorized to indicate the color components they control. Moving the thumb sliders on the scrollbars adjusts the circle’s color.
// Define a function that will initialize the scrollbar instances as sliders to // control the color values. function initSliders ( ) { // First, set the scroll properties of each of the scrollbars. For the red, // green, and blue scrollbars, the values should range from 0 to ...
Get Actionscript Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.