2012-07-03 110 views
2

禁用火花按鈕欄按鈕,我可以通過索引值禁用星火按鈕欄按鈕或我通過按鍵皮膚做它用標籤所示的here通過索引

和例子我想做些什麼:

public function disableButton(index:uint):void 
{ 
    var button:ButtonBarButton = this.getChildAt(index) as ButtonBarButton; 

    button.enabled = false; 


} 

的按鈕對象回來空這是行不通的。

回答

2

你想要的代碼是:

public function disableButton(index:int):void 
{ 
    // Bounds check 
    if (index < 0 || index >= this.dataGroup.numElements) return; 

    var btn:ButtonBarButton = this.dataGroup.getElementAt(index) as ButtonBarButton; 
    if (btn) 
    { 
     btn.enabled = false; 
    } 
} 

這裏是一個complete working example

+0

正是我需要的,感謝了一堆。 – user1210003