Accessing Imported Objects in ActionScript 3

April 26, 2010

I learned the bulk of my understanding of ActionScirpt 3 with UNC’s “Bringing Education to Life Campaign”. I rewrote the code for the base flash file 3 different times, each time updating the code with what I had learned. The site was created using modules, in which if we wanted to add something new, we just changed a few parameters in an XML file. The first module we created was the “Photo Tour“.

UIloaders:

The Photo Tour, connects to an XML document that tells flash where to place the marker and what photo to bring up when clicked. Back when I started this project I was fairly new at ActionScript so I created a UILoader for each marker and loaded the same image into it each time. This created huge performance issues.

Import to Library

The best way to add these objects is to import them into your library and convert them to a MovieClip. In the Library, right click on your movie clip and go to “Properties”.

Check the box that says “Export for ActionScript” and in the “Class” box, enter:

assets.symbolName

Indicate “assets” in front of the object to maintain organization in your code.

Code:

To access your object in ActionScript first you need to import it. Next create a variable based on your object and add it to the stage:

package {

import flash.display.Sprite;

import assets.mySymbol;

public class importObjects extends Sprite{

public function importObjects(){

var newSymbol = new mySymbol;

addChild(newSymbol);

}

}

}

Tags: ,

Leave a Reply