• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL

Chapter 15. Using Basic ActionScripts > Applying Properties and Methods to an O...

Applying Properties and Methods to an Object

Once you’ve gotten the hang of writing ActionScripts, the next step is to apply properties and methods to objects in a Flash document. You can have an object, and let your visitor control its color. Changing the color is an example of changing an object’s properties. To make an object change color, you will need a Flash document that contains a MovieClip and button symbols. An easy script translation would be: Flash, when my visitor clicks (release) on the button, I want you to assign a new color to an object that I gave a unique instance name (change it), and I’m defining that property as objectColor, and change the color (setRGB) to red (0x990000). When you attach ActionScripts to buttons, you’re not limited to just a single use. For example, you could drag three instances of the same button symbol on the Stage, and repeat the previous code with one exception: change the SetRGB value of one to (0x990000) for red, another to (0x009900) for green, and the third one to (0x000099) for blue.

Apply Properties and Methods

Drag the movie clip onto the Stage.

Enter a unique instance name in the Property Inspector.

Drag the button symbol onto the Stage, and then select the symbol.

Click the Window menu, and then click Actions to open the Actions panel.

Did You Know?

You can now edit ActionScript code using external editor applications. MetaData (Windows), BBEdit (Macintosh), or any editor that saves files using the .as (ActionScript) extension gives you the ability to edit and save ActionScript code. The file can then be opened in Flash (click the File menu, and then click Open), or imported into the Flash Actions panel (click the Actions Options button, and then click Import Script).

Enter the script as shown in the illustration.

Click the Control menu, and then click Test Movie.

Click the button to change the color of the object to red.

IMPORTANT Button objects can have triggering events other than a user click. You can create a button instance that uses the rollover event, and have an object change color as the user rolls over the button. Or, you can create an invisible button with a rollover event that triggers a property change when the user rolls over a specific portion of the image.



Not a subscriber?

Start A Free Trial

  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint