我正在为大学项目开发一个步测序器。我为每个按钮创建了一个文档类,每个按钮的所有代码都在按钮类中。按下按钮时,声音将被推入此课程的数组中。如何在主类中访问该数组,因此当按下该按钮时,它将以当前步骤播放声音
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 :(得分:0)
您需要访问Main类中的按钮。
如果您已手动将按钮添加到舞台,则需要为其指定实例名称。单击舞台上的按钮,在“属性”面板中输入一些名称,“实例名称”输入字段。
然后在你的主类中你应该能够访问:this.myButtonName.tomsoundArray