2012-04-28 12 views
0

私はフラッシュゲームを作成していますが、私が抱えている問題は、開始ゲームボタンとエンジンを持つウェルカムスクリーンのメニューという2つのクラスですAS3:別のクラスからスイッチケースを呼び出すことはできません

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; 
        } 
    } 

と私は、メニューのクラスでこのコードを使用して、メニューから実際のゲームの状態を変更します。私は、このコードによって自動的に表示されるようにメニューを設定して、初めてゲームを実行、すべてを実行しますクラス:

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関数を使用します例えばスタートボタンを置いて、バックグラウンドを置くゲームの場合は何らかの理由でトレースステートメントを得るだけですが、この背景には手がかりが表示されません。

私は問題が何であるかを調べようとするより多くの時間を費やしています。誰かが私を助けて偉大になるなら、私はまだできません。

おかげ

+0

コードをコメントし、謎のオブジェクトが何であるか説明してください。 – iND

+0

また、より完全なクラスをコードに表示してください(たとえば、 'class Menu extends ...')。 – iND

+0

背景が(おそらく)追加されています。 'sBg1'のwid/ht、x/y、および可視性を検証する' trace() 'を追加してください。最後に、 'trace(this.getChildIndex(sBg1))'を追加します。これは、すべて関連するswitchコマンドで実行する必要があります。 – iND

答えて

0

あなたはScrollBgクラスが表示するように何も持っていないため、最も可能性があり、画面上のトレースが、何も表示された場合。クラスにスプライトや画像があることを確認してください。

+0

このクラスは、バックグラウンドを含む私のライブラリのムービークリップにリンクされています –

関連する問題