[Solved] Get class instance for swf asset

I’ve learned how to get and use class definitions of assets in a swf file. There’s one thing I haven’t figured out.

In Flash/Animate, you can attach an instance name to a symbol and you don’t even have to declare that variable etc.

For example, in Flash/Animate if I place a SimpleButton on the stage at a particular location and give it an instance name of myButton, in my code I don’t have to declare the variable mySprite, I don’t have to use addChild to add it to the stage or set its coordinates, i.e. myButton.x = 100. I can use it right away, i.e. myButton.addEventListener(MouseEvent.CLICK, buttonClicked).

Is there a way of referencing an instance stored in a swf file?

Thanks in advance.


Have you seen this tutorial?


Use the generate="true" option, and our tools will generate classes for each of your “Export for ActionScript” classes in your SWF. These classes should have it’s named children defined for you, so you can do something like…

var symbol = new MySymbol ();
symbol.label.text = "Hello World";

…be aware, that it only works one level deep. If you reference a child that is a MovieClip, it’s children names will not be generated for you, unless the child MovieClip is itself set to Export for ActionScript

We might generate dummy classes for non export symbols in the future, but for now, this is the way it works

Thanks, this did help me figure it out. What I didn’t do was reference the symbol as a child of the parent. So I just had to say buttonParent.myButton instead of just myButton.

So in the swf, if you have myScreen and on that screen you have several children:

myScreen = new MyScreen();
myScreen.textField1.text = “Hello”;
myScreen.textField2.text = “There”;
myScreen.myButton1.addEventListener(MouseEvent.CLICK, buttonClicked);
myScreen.myButton2.addEventListener(MouseEvent.CLICK, buttonClicked);

I also figured out how to access a button that’s on a Sprite which in turn is on another Sprite, i.e. MyScreen.
myScreen = new MyScreen();
var mySprite:MySprite = myScreen.aSprite;
mySprite.spriteButton. addEventListener(MouseEvent.CLICK, buttonClicked);

As you said, just create a class by Export for ActionScript for any parent object and you can go several layers deep.