2013-11-20 40 views
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); 


     } 
+0

我在主类我不得不遍历轨道和按键的阵列中的每个跟踪和做再检查如果按钮的alpha值小于1,如果是播放声音形式的数组,但数组是在按钮类中的,并且我有96个按钮实例,所以如果我以每个实例为目标,我最终会得到3000行代码 –

回答

0

您必须在主类中的一些访问按钮播放声音。

如果您手动将按钮添加到舞台上,则需要为它们指定实例名称。点击舞台上的按钮,并在“属性”面板的“实例名称”输入字段中输入一些名称。

然后在你的主类,你应该能够访问:this.myButtonName.tomsoundArray