Creating symbols and associative classes

When you create symbols in Flash CS3 and export them to Actionscript in the standard way, Flash generates a class representing the symbol. This is great when you want to access the symbol from the code. Every symbol you have created and is located in the library view can be exported to actionscript. If this is new to you, please recap on the article Understanding the use of designer objects in seperate as-file(class).

linkage_associative_class2

When you want to manipulate the symbol at runtime you would want to create your own class for the symbol. When you press “Export for ActionScript”, the class name is generated from the name of the symbol. On the right side of the Class input field, there is a green “check” and an edit symbol. If you press the edit symbol, this popup will appear:

swf_generated

Press OK and Cancel.

Now, create a new Actionscript file an name it the same as your symbol e.x. “ThumbHolder”. Try to “Export for Actionscript” again press the edit button on the right side of the class input field. It opens up the class you have created. Good! If the class does not appear, your name of the class in the input field is not the same as the actual class.

Accessing objects in your symbol is now the easiest part. If you have created a textfield with the instance name “titleBar”, the only line of code to set the content in the textfield is this:


titleBar.text = "This is the content of the textfield titleBar";

The class representing the ThumbHolder will then be the following:


package
{
import flash.display.MovieClip;
public class ThumbHolder extends MovieClip
{
public function ThumbHolder()
{
titleBar.text = "This is the content of the textfield titleBar";
}
}
}

No comments yet.

Write a comment:

Captcha
Enter the letters you see above.