2012-02-22 47 views
0

我該怎麼做?AS3 - 點擊按鈕後,使其保持「結束」模式

我有樹按鈕。一次只能選擇一個。他們玩不同的動畫。

我需要的是設置按鈕(它具有不同的bg顏色,取決於它的上,下和向下狀態)到它的關閉狀態。

簡而言之;點擊時,我需要凍結處於關閉狀態的按鈕。 當我點擊其他按鈕之一時,它應該返回到正常狀態,並且新按鈕將被凍結在它的關閉狀態。

我正在使用Flash,AS3 ..

謝謝! =)

+0

發現此問題.. http://stackoverflow.com/questions/560490/flash-toggle-button – 2012-02-22 11:49:29

+0

但是,當我點擊一個新按鈕時,如何將狀態交換回來? – 2012-02-22 11:50:55

+0

我只是在init()中存儲每個狀態;並清除切換每次我點擊一個按鈕..(不能回答我自己的問題..:P) – 2012-02-22 12:00:26

回答

2

簡單地說:

當您設置=北部唐斯泰特表明項被選定,你已經失去了回到原來北部的能力。因此,將upState作爲變量存儲是一件非常簡單的事情,以便您始終能夠回到它。

//capture upstate as a variable 

var buttonUpVar:DisplayObject = button.upState; 

//button stays selected or in downState when released. 

button.upState = button.downState; 

//deselect button by going back to original upState 

button.upState = buttonUpVar; 

完成,用最少的代碼。

1

試試我從你鏈接的解決方案改編的這段代碼。

private toggledButton:SimpleButton; 

private function buttonToggle(button:SimpleButton){ 
    var currDown:DisplayObject = button.downState; 
    button.downState = button.upState; 
    button.upState = currDown; 
} 

private function clickEvent(e:MouseEvent){ 
    if (toggledButton != e.target) { 
     buttonToggle(e.target); 
     if (toggledButton) 
      buttonToggle(toggledButton); 
     toggledButton = e.target; 
    } 
} 
1
private function onClick(event:MouseEvent):void { 
    if(prevSelected) { 
     //change the skin of selected 
    } 
    //save the current selected button 
    //change the current selected button skin 
}