Export Library Button Symbol for ActionScript

Export Library Button Symbol for ActionScript

Flash CS4 ActionScript 3.0 Tutorial


How to Access Flash Library Symbols with ActionScript



Once you create a Symbol, it is added to the Library. ActionScript can talk to Movie Symbols or Button Symbols.

To make this happen, we must first assign the Symbol a Class Name. Once the Class is defined, we call the Class with ActionScript and assign our new object a unique variable name. There are a few rules about Class naming conventions. For more information, see topic, Class (Naming).

Tutorial Elements

Movie Symbol with name GrayOval


Step One

Add a oval object to the workspace with the Oval tool (o key).

Step Two

With the oval selected, press F8 to convert it to a Button Symbol (Modify > Convert to Symbol).

Step Three

In the dialog box, name your symbol GrayOval and choose Button for the symbol type.

Step Four

Double-click the button and add Over, Down and Hit states by pressing F6 three times.

Step Five

Return to the main stage and delete the original oval object from the stage.

Step Six

Open the Library (Cmd/L (PC - Ctrl/L) and select the new symbol.

Step Seven

Choose Properties from the Library pull-down menu.

Step Eight

In the Linkage section, click Export for ActionScript and a Class Name appears. Make sure you class name starts with a capital letter.

Step Nine

Add a new layer at the top of the stack, named Actions.

Step Ten

Open the ActionScript panel for your keyframe in the Actions layer by Option double-clicking (PC - Alt double-clicking) the keyframe.

Step Eleven

Copy/Paste the following code in the ActionScript Panel:

var grayOval_btn = new GrayOval();




Step Twelve

Test your movie by pressing Cmd/Return (PC - Ctrl/Enter).

Dissecting the Code

The first line of the code creates a new GrayOval object with the variable name of grayOval_btn.

The next two lines place the object 100 pixels from the left side of the stage and 50 pixels down from the top. The final line adds the new object to the stage.