使用Event处理程序或类似的东西

时间:2013-04-24 14:38:04

标签: button adobe flash-cs5

我正在开发Adobe Flash CS5和动作脚本3 - 我的问题是如何在点击其他四个按钮并访问场景后,只能创建一个按钮才能点击?

1 个答案:

答案 0 :(得分:0)

假设您的5个按钮始终在时间线上可用,它们位于顶层文档级别(如果没有,我们需要进行一些调整)。我们还假设,从您的问题来看,您还没有为文档类文件的最佳实践做好准备,因此这将被写为时间轴脚本。

//assumes the 4 buttons are on the stage, named button1, button2, etc.
var prerequisiteButtons:Array = [button1, button2, button3, button4];
var prerequisitesClicked:Array /*of Boolean*/ = [];

coyButton.enabled = false;//your fifth button, who plays hard to get

//loop through and listen for clicks on your prerequisite buttons
for each (var button:DisplayObject in buttons) {
    button.addEventListener(MouseEvent.CLICK, checkAllClicked);
}

//check to see if all the buttons have been clicked
function checkAllClicked(e:Event):void {
    //find the button in the prerequisite buttons array
    var buttonIndex:int = prerequisiteButtons.indexOf(e.currentTarget);
    //set the matching index to true in the array that keeps track of what has been clicked
    prerequisitesClicked[buttonIndex] = true;
    //count how many of them have been clicked
    var prerequisiteDoneCount:int = 0;
    for (var i:int = 0; i< prerequisitesClicked.length; i++) {
        if (prerequisitesClicked[i]) prerequisiteDoneCount++;
    }
    //if all the buttons have been clicked, enable the button (may also want to add a listener here)
    if (prerequisiteDoneCount==prerequisiteButtons.length) coyButton.enabled = true;
}