我在AS3做一个游戏。
我有一个名为“UseBox”的类来调度一个事件。
如果thisThing.buyable not event is dispatch且子视图“Building”可见,其中2个建筑物可见且2个不可见。
如果thisThing.destructible那么事件“升级”是发送和孩子“建筑物”可见4个建筑物可见。
问题是发送“可升级”现在一直在进行。
每次儿童“建筑物”变得可见时,是否有可能破坏事件?
Thanx为你的答案,
这是我的代码:
UseBox
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"); }因此,如果听到事件“可升级”,则调用函数“checkConstruction”,否则不调用。
但是,一旦发送了“可升级”事件,它似乎始终保持调度,因此当“建筑物”可见时,总是调用“checkConstruction”功能...
I'm making a game in AS3.
I've got a class named "UseBox" that dispatch an event.
If thisThing.buyable not event is dispatch and the child "Building" is visible whith 2 buildings visible and 2 not visible.
If thisThing.destructible then the event "upgradable" is dispatch and the child "Building" is visible whith 4 buildings visible.
The problem is that the dispatch "upgradable" is always on now.
Is it possible to destroy the event each time the child "Building" become visible ?
Thanx for your answers,
Here's my code :
UseBox
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; }Oh, and my buidling.as code :
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"); }So, if the event "upgradable" is heard, the function "checkConstruction" is called, else not.
But, once the event "upgradable" has been dispatched, it seems that it stay always dispatch so the function "checkConstruction" is always called when "Building" is visible...
最满意答案
我不是100%确定这是你正在寻找的,但如果你只想要处理一次事件,那么一旦你通过调用checkConstruction接收它,你就可以将它从侦听事件中移除:
private function checkConstruction(Event):void{ //Here, you would remove the function from listening to any more "upgradable" events being dispatched. stageRef.removeEventListener("upgradable", checkConstruction); 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"); }I'm not 100% sure this is what you're looking for, but if your only looking to handle an event once, then once you've recieved it by checkConstruction being called, you can remove it from listening for the event again:
private function checkConstruction(Event):void{ //Here, you would remove the function from listening to any more "upgradable" events being dispatched. stageRef.removeEventListener("upgradable", checkConstruction); 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"); }更多推荐
发布评论