Search code examples
flashactionscript-3flash-builderswc

FlashBuilder edit Class of Symbol defined in Flash IDE


When coding in the Flash IDE, i very often use the following procedure to create specialized versions of MovieClip classes:

I design my object in the IDE, for example, i add two buttons and give them the instance names "btn1" and "btn2". Then i select them together and convert them to a symbol. I then select Export for ActionScript and give them a classname, let's say "MyClass".

Then I go and write a specialized MyClass.as for it, like this:

public class MyClass extends MovieClip{
    private var _button1:Button;
    private var _button2:Button;

    public function MyClass(){
        this.addEventListener(Event.ADDED_TO_STAGE, init);
        ....
    }

    private function init(e:Event){
        _button1 = this["btn1"];
        _button2 = this["btn2"];
    }

    ...
}

(ps: i know that i wouldn't have to assign the values to the private variables _button1 and _button2 and instead could directly make calls to btn1, but I like to use only Typesafe variables in my code)

This works very well in Flash IDE. when I create a new instance of MyClass() it will contain all the elements that i positioned in the Flash IDE when defining the Symbol. This is very convenient and straight forward.

Now I want to do the same in FlashBuilder.

For this i designed the MyClass Symbol as before in Flash IDE, gave it the classname MyClass and then select the library symbol and export it to MyClass.SWC

In Flash Builder i add MyClass.SWC to the buildpath and I write a MyClass.as with the same code as in the Flash IDE example. but this time, the code won't work. on

_button1 = this["btn1"];

i will get an Error #1069 stating that "btn1" was not defined.

So - how to do this properly if developing with Flash Builder?

PS: i use the default package in Flash IDE when setting the Classname for the symbol as well as in FlashBuilder for the as file

Thanks!


Solution

  • Might I suggest that now you are moving to Flash Builder that you change your approach slightly. Although there is nothing wrong with using a swc, your assets are embedded at compile time, which means you need to recompile your app if you change them.

    I have been using an approach of putting movieclips in a swf and loading it in, and then to keep the type safety that you describe I use the IMediaLibrary approach. See the following article:

    Runtime Class Extraction

    Doing it this way means you can also share this swf with other applications, it may contain icons or whatever you want, but I think you will find the approach very flexible.