[AS3] Super Simple Custom Component in CS4
In AS2, you could simply add a component definition to a clip in the library, then add a variable, and it would be instantly accessible from within that clip. In AS3, this doesn't work.
I have a variable myNum in the component definition, but my class file can't get to it. I added an ADDED_TO_STAGE listener thinking that maybe it couldn't get to the variable because it wasn't declared yet, but still no dice. And if I don't put var myNum:Number; I get an error. So I'm likely just overwriting the myNum in the component inspector with the myNum in the class definition.
I looked at the Adobe Tutorial on Creating ActionScript 3.0 Components, but if there is a simple solution in the many pages there I can't seem to find it.
Any ideas? All I need to do is access a single variable that is defined via the component inspector.
Code:
package {
import flash.display.MovieClip;
import flash.events.Event;
public class Component extends MovieClip {
public var myNum:Number;
public function Component() {
trace(this.myNum);
addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
}
private function onAddedToStage(event:Event):void{
trace(this.myNum);
removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
}
}
}