Actionscript 3 AS3:从另一个类调用switch case不起作用

Actionscript 3 AS3:从另一个类调用switch case不起作用,actionscript-3,class,function,flash-cs5,switch-statement,Actionscript 3,Class,Function,Flash Cs5,Switch Statement,我正在用flash制作一个游戏,我遇到的问题是有两个类,一个是“欢迎屏幕菜单”类,它有一个StartName按钮,另一个是engine类,当我第一次运行游戏时,它运行所有的东西,我设置菜单自动显示,代码如下: public var state:int; public const MENU:int = 0; public const GAME:int = 1; // create the variable for the menu private var _

我正在用flash制作一个游戏,我遇到的问题是有两个类,一个是“欢迎屏幕菜单”类,它有一个StartName按钮,另一个是engine类,当我第一次运行游戏时,它运行所有的东西,我设置菜单自动显示,代码如下:

    public var state:int;
    public const MENU:int = 0;
    public const GAME:int = 1;
    // create the variable for the menu
    private var _menu:Menu;

    public var sBg1:ScrollBg;
    public var sBg2:ScrollBg;
    public function Engine(menu:Menu) 
    {

        _menu = menu;
        //we add event listener when the engine is added to the stage
        addEventListener(Event.ADDED_TO_STAGE, onAdded);
    }
    private function onAdded(e:Event):void {
        //then we remove the event listener and initiate the init function
        removeEventListener(Event.ADDED_TO_STAGE, onAdded);

        init();
    }
    private function init():void {
        //the init function set the game state at first to menu and run the drawUI function
        state = MENU;
        drawUI();

    }

    public function drawUI():void 
    {
        //the drawUI function draw the needed elements on stage according to the state of the game
        switch(state){
            case MENU:
                _menu = new Menu();
                addChild(_menu);
                break;
            case GAME:
                sBg1= new ScrollBg();   
                addChild(sBg1);
                sBg1.x = 0;
                sBg1.y = 0;
                //if(contains(_menu)){
                //removeChild(_menu);}

                trace('this the game');
                break;
                    }
    }
我在menu类中使用以下代码将状态从menu更改为实际游戏:

    public var start_btn:MovieClip;
    private var _engine:Engine;
    public function Menu() 
    {
        addEventListener(Event.ADDED_TO_STAGE, displayMenu);
    }

    private function displayMenu(e:Event):void 
    {
        removeEventListener(Event.ADDED_TO_STAGE, displayMenu);
        start_btn = new startBtn();
        start_btn.x = 100;
        start_btn.y = 200;
        addChild(start_btn);
        start_btn.addEventListener(MouseEvent.CLICK, startGame);
    }

    private function startGame(e:MouseEvent):void 
    {
        start_btn.removeEventListener(MouseEvent.CLICK, startGame);
        _engine = new Engine(this);
        _engine.state = 1;
        _engine.drawUI();
    }
我每次都使用drawUI函数来显示菜单,例如,它会放置开始按钮,而对于游戏,它会放置背景,但出于某种原因,我只会收到跟踪语句,其中说明了游戏的情况,但背景不会显示任何线索

我花了4个多小时试图找出问题所在,但我仍然无法确定是否有人能帮助我,这将是非常好的


如果您在屏幕上看到跟踪,但没有看到任何内容,则非常感谢,因为ScrollBg类没有任何内容可显示。确保类中有一些精灵或图像。

该类链接到我的库中包含背景的movieclip。请评论您的代码并解释神秘对象是什么。此外,请在代码中显示更完整的类,例如,类菜单扩展…背景可能正在添加。添加用于验证sBg1的wid/ht、x/y和可见性的跟踪。最后,添加一个tracethis.getChildIndexsBg1。这一切都应该进入相关的开关命令。