0
我正在開發大學項目的步驟順序器。我爲每個按鈕創建了一個文檔類,每個按鈕的所有代碼都在按鈕類中。當按下按鈕時,聲音被推入該類中的數組中。我如何可以訪問陣列中的主類,所以當按鈕被按下它會在當前步驟如何訪問數組構成另一個文檔類
public var tomsoundArray:Array = new Array();
[Embed(source = "sounds/tom.mp3")]
public var tomSoundClass:Class;
public var tomSound:Sound = new tomSoundClass() as Sound;
public function TomButton()
{
// constructor code
//checkIfBtActive = true;
this.addEventListener(MouseEvent.CLICK, checkButtonState);
}
public function checkButtonState(event:MouseEvent)
{
if (this.alpha == 1)
{
this.alpha = 0.5;
tomsoundArray.push(tomSound);
trace(tomsoundArray);
tomSound.play();
trace("ButtonActive: " + this.alpha);
trace(this.parent.name);
trace(this.name);
}
else if (this.alpha == 0.5)
{
this.alpha = 1;
tomsoundArray.splice(0);
trace(tomsoundArray);
trace("Button Deactivated: " + this.alpha);
}
我在主類我不得不遍歷軌道和按鍵的陣列中的每個跟蹤和做再檢查如果按鈕的alpha值小於1,如果是播放聲音形式的數組,但數組是在按鈕類中的,並且我有96個按鈕實例,所以如果我以每個實例爲目標,我最終會得到3000行代碼 –