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
movieClipsand 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
movieClipslayer. Place the instance on the left side of the Stage. Name the instancecircle_mcusing the Property inspector.Open the Components panel (Window → Components) and drag four instances of the ScrollBar component onto the Stage on the
movieClipslayer. 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
actionslayer 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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access