Стадия вспышки является нулевой - PullRequest
0 голосов
/ 08 февраля 2011

Вот очень простой проект AS3.Этап не является нулевым в основном классе, но находится в классе AppMan, и я хочу получить к нему доступ.Почему?

Вот мой основной класс, который называется StageText.as:

package
{
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageQuality;
import flash.display.StageScaleMode;

stage.scaleMode = StageScaleMode.NO_SCALE; //here, the stage is not null.
stage.align     = StageAlign.TOP_LEFT;

public class StageText extends Sprite
{
    private var appMan:AppMan = new AppMan();

    public function StageText()
    {
        appMan.startApp();

    }
}
}

Затем в той же папке у меня есть класс AppMan.as.

package
{
import flash.events.Event;
import flash.display.Sprite;
import flash.text.TextField;
import flash.display.StageAlign;
import flash.display.StageQuality;
import flash.display.StageScaleMode;

public class AppMan extends Sprite
{
    public var textField:TextField;

    // Application Width, Height
    public var appW:Number;
    public var appH:Number;

    public function AppMan()
    {
        super();
    }

    public function startApp():void {

        // create textfield
        textField = new TextField();
        textField.wordWrap = true;
        textField.width = 540;
        textField.height = 400;
        textField.text  = "Hello World";
        addChild(textField);
                    //if I try to run init in response to Event.ADDED_TO_STAGE, it never runs
        this.addEventListener(Event.ADDED_TO_STAGE, init); 
                    //Or, if I run init() without the eventListener, I get a runtime error
                    //indicating that the stage is null
        //init();


    }

    private function init(e:Event):void {
    //private function init():void {

        stage.scaleMode = StageScaleMode.NO_SCALE;
        stage.align     = StageAlign.TOP_LEFT;
        stage.quality   = StageQuality.HIGH;
        appW = stage.stageWidth;
        appH = stage.stageHeight; 
    }
}
}

1 Ответ

3 голосов
/ 08 февраля 2011

Я предполагаю, но добавлен ли экземпляр appMan на сцену?

 public function StageText()
 {
    this.AddChild(appMan);
    appMan.startApp();

 }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...