2015-01-18 3 views
0

Я просто новичок в ActionScript, и мы должны сделать игру с помощью ActionScript 2.Actionscript 2 Отключить кнопку после сцены

Итак, у меня есть главная сцена с тремя кнопками, при нажатии одной кнопок, он пойдет в мини-игру. Когда игрок преуспеет в мини-игре, он вернется к основной сцене, и нажатая кнопка будет отключена. Прямо сейчас, что я могу сделать только тогда, когда он нажат, кнопка отключена, она не переходит на сцену для мини-игры. Может кто-нибудь мне помочь?

вот код:

stop(); 

var places:Array = [flood_btn, earthquake_btn, landslide_btn]; 
var pressedbtn; 

function Dplaces():Void { 

    pressedbtn.enabled = true; 
    this.enabled = false; 

} 

for (ctr = 0; ctr < places.length; ctr++) { 
    places[ctr].onRelease = Dplaces; 
} 

ответ

0

В своем коде, я не видел, как вы идете к другим сценам от основного и, конечно, вы должны понимать, что каждый раз, когда вы возвращаетесь к главная сцена каждая вещь будет инициализирован, поэтому вы должны относиться, что с помощью, например, глобальные переменные, как это:

stop(); 

// verify if this is our first run, so create our global pressed_btn var 
// otherwise, pressed_btn contains the current pressed button index 
if (pressed_btn == undefined) 
{ 
    _global.pressed_btn = -1; 

} 

var places:Array = [flood_btn, earthquake_btn, landslide_btn]; 

// init our buttons and disable, if we have, the current pressed one 
for (ctr = 0; ctr < places.length; ctr++) 
{ 
    var btn:Button = places[ctr]; 
    if (ctr != pressed_btn) 
    { 
     // we add the index attribut to identify our button when it's pressed to go to the appropriate scene 
     btn['index'] = ctr;  
     btn.onRelease = Dplaces; 
    } else { 
     // if we have a pressed button, disable it 
     btn.enabled = false; 
    } 
} 

function Dplaces():Void { 

    // save the current pressed button index 
    _global.pressed_btn = this.index; 

    switch (this.index) 
    { 
     case 0 : 
      gotoAndStop("game1", 1); 
      break; 
     case 1 : 
      gotoAndStop("game2", 1); 
      break; 
     case 2 : 
      gotoAndStop("game3", 1); 
      break; 
    } 

} 

Надежда, которая может помочь.

Смежные вопросы