How to Change an Object's Color Using ActionScript 2.0

Written by john valles
  • Share
  • Tweet
  • Share
  • Pin
  • Email
How to Change an Object's Color Using ActionScript 2.0
Use ActionScript to apply any colour to a movie clip. (Photos.com/Photos.com/Getty Images)

You can change the colour of a movie clip in Flash using the ActionScript 2.0 "Color" object. Objects in ActionScript 2.0 allow access to certain types of information. The Color object lets you set the colour of movie clips within your Flash movie using code.

Skill level:
Moderately Easy

Other People Are Reading

Things you need

  • Flash software

Show MoreHide

Instructions

    Create a Movie Clip

  1. 1

    Draw a shape with the Rectangle tool on the main stage in Flash. Fill it with the colour of your choice.

  2. 2

    Select the shape you just created and convert it to a movie clip by pressing "F8" or selecting "Modify/Convert to Symbol."

  3. 3

    Enter "color_mc" for the name and "Movie Clip" for the type in the Convert to Symbol dialogue box. Press "OK."

  4. 4

    Select the movie clip you just created, and in the Properties box enter "color_mc" for the instance name. Since Flash creates a movie clip with no instance name by default, you must enter an instance name in order to reference the movie clip in your code.

    Write the Code

  1. 1

    Create a layer in your timeline and name it "Actions." You will write your code in the first frame of this layer.

  2. 2

    Call the Color object by entering the following code:

    var changeColor = new Color();

  3. 3

    Enter the name of the movie clip in the parentheses. This tells the Color object which movie clip it will affect:

    var changeColor = newColor(color_mc);

    Assign the Colors

  1. 1

    Create a function that will change the colour to blue when the mouse rolls over the movie clip by entering the following code:

    color_mc.onRollOver = function(){

    changeColor.setRGB(0x3333FF);
    

    }

    You can change the hexadecimal value within the setRGB() parentheses if you want to apply a different colour to your movie clip.

  2. 2

    Create a function that will change the colour to red when the mouse rolls out of the movie clip by entering the following code:

    color_mc.onRollOut = function(){

    changeColor.setRGB(0xCC0000);
    

    }

    You can change the hexadecimal value within the setRGB() parentheses if you want to apply a different colour to your movie clip when the mouse rolls out.

  3. 3

    Test the movie by selecting "Control/Test Movie." Move your mouse over the rectangle and its colour will change to blue. Move your mouse out of the rectangle and its colour will change to red.

Don't Miss

Filter:
  • All types
  • Articles
  • Slideshows
  • Videos
Sort:
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the eHow.co.uk site, you consent to the use of cookies. For more information, please see our Cookie policy.