1
votes

I'm having trouble targeting a normal as3 swf to air mobile so i made a simple test app to check and try to understand which is the problem. I'm using flashdevelop 4 and latest AIR sdk.

I exported an SWC with a simple MC exported with class name BlackBox Here's my Main code (package and imports ommited but I even imported the BlackBox class) :

public class Main extends Sprite 
{
    public var cajaNegra:MovieClip

    public function Main():void 
    {
        stage.scaleMode = StageScaleMode.NO_SCALE;
        stage.align = StageAlign.TOP_LEFT;
        stage.addEventListener(Event.DEACTIVATE, deactivate);

        // touch or gesture?
        Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT;

        // entry point
        cajaNegra = new BlackBox();
        addChild(cajaNegra)
        cajaNegra.x = stage.stageWidth/2
        cajaNegra.y = stage.stageHeight / 2
        }
}

everything works as it should, but when I create a custom BlackBox.as in the src folder the app doesn't show anything. I added a text field named miTexto.

BlackBox.as

public class BlackBox extends MovieClip 
{
    public var miTexto:TextField

    public function BlackBox() 
    {
        super();
        if (stage) init();
        else addEventListener(Event.ADDED_TO_STAGE, init);


    }

    private function init(e:Event = null):void 
    {
        removeEventListener(Event.ADDED_TO_STAGE, init);
        // entry point
        miTexto.text = "changed text"
    }

}

In this case the debugger throws in the line miTexto.text = "changed text":

 [Fault] exception, information=TypeError: Error #1009: Cannot access a property or method of a null object reference

Thanks in advance.

1

1 Answers

0
votes

did you forget to do: addChild(miTextTo); ?