【发布时间】:2014-02-01 07:03:17
【问题描述】:
我正在用 AS3 制作游戏。
我有一个名为“UseBox”的类来调度一个事件。
如果 thisThing.buyable not 事件被调度并且子“建筑物”是可见的,其中 2 个建筑物可见,2 个不可见。
如果 thisThing.destructible 则发送事件“upgradable”,并且子“Building”可见,其中 4 个建筑物可见。
问题是调度“可升级”现在总是开启。
是否可以在每次孩子“建筑”可见时销毁该事件?
感谢您的回答,
这是我的代码:
使用框
public function UseBox(stageRef:Stage, thisThing:Object){
if (thisThing.buyable){
useButton.gotoAndStop("buy");
useButton.addEventListener(MouseEvent.CLICK, buyIt, false, 0, true);
}
if (thisThing.destructible){
this.gotoAndStop("upgrade");
upgradeButton.buttonMode = true;
upgradeButton.addEventListener(MouseEvent.CLICK, upgradeIt, false, 0, true);
}
public function buyIt(e:MouseEvent):void{
boxClicked();
showBatiments();
lookButton.removeEventListener(MouseEvent.CLICK, buyIt);
}
public function upgradeIt(e:MouseEvent):void{
boxClicked();
showBatiments();
stageRef.dispatchEvent(new Event("upgradable"));
lookButton.removeEventListener(MouseEvent.CLICK, buyIt);
}
private function showBatiments():void{
Engine.batiments.visible = true;
}
哦,还有我的 buidling.as 代码:
poulaillerPlusBtn.visible = false;
poulaillerImpossible.visible = true;
poulaillerBtn.addEventListener(MouseEvent.CLICK, poulaillerConstruction, false, 0, true);
stageRef.addEventListener("upgradable", checkConstruction, false, 0, true);
private function checkConstruction(Event):void{
trace("I've heard upgradable");
poulaillerPlusBtn.visible = true;
poulaillerImpossible.visible = false;
poulaillerPlusBtn.addEventListener(MouseEvent.CLICK, poulaillerAmelioration, false, 0, true);
trace("on a vérifé, tu peux améliorer le batiment");
}
因此,如果听到事件“upgradable”,则调用函数“checkConstruction”,否则不调用。
但是,一旦“upgradable”事件被分派,它似乎始终保持分派,因此当“Building”可见时,总是调用函数“checkConstruction”......
【问题讨论】:
-
很抱歉,你的英文真的很难读。
标签: actionscript-3