R – Adding Flash Components to Stage Dynamically from AS3 File

actionscript-3flashflash-v3-components

When I attempt to create a new flash list component from my as3 file (FrontEnd.as) and add it to the stage, I get the following error: "1046: Type was not found or was not a compile-time constant: List". Below is the code:

package {

import flash.display.MovieClip;
import fl.controls.List;

public class FrontEnd extends MovieClip {

    public function FrontEnd():void {
        trace("FrontEnd Here");
        init();
    }

    private function init() {
        var userSelect:List = new List();
        addChild(userSelect);
        userSelect.move(200, 100);
        userSelect.width = 120;
    }
}

}

Someone commented on a livedocs page that you have to drag the component to the .fla library and cannot create it solely from as3. Is this really true? Hoping someone can set me straight, thanks.

Best Answer

That is true, Think of the UI Components in Flash as made of 2 parts:

  1. The classes that manage the components
  2. The visual assets of the components.

When you import the classes from actionscript alone, they will be missing the visual elements that go hand in hand with that, so just drag the List component to the Library and you should be fine.

Related Topic