Re: [Flashcoders] AS3: Dispatching events to further listeners, but not to itself
- Original Message - From: Alexander Farber alexander.far...@gmail.com To: Flash Coders List flashcoders@chattyfig.figleaf.com Sent: Sunday, December 28, 2008 10:13 AM Subject: Re: [Flashcoders] AS3: Dispatching events to further listeners,but not to itself Hello, may I please rephrase my question, maybe someone will have a hint for me? By my PlayingCard objects I'd like to dispatch 2 events: Event.CHANGE and MouseEvent.CLICK I do it because in my game you can drag cards, but also you can select them from a list and click a button. So I could use same handler functions. My problem with the MouseEvent.CLICK is however that I receive it twice - 1 event comes from the PlayingCard and another one seems to be dispatched automatically. Is there please a way to prevent the latter event from being sent? A far better strategy is to stop using generic events and use custom events to differentiate between the individual situations. So, you would have a CardSelectedEvent.CARD_SELECTED being used in your game logic, not generic events. It will make your life much easier. The click of a chosen card would set the current card in your list. The button click would dispatch the CardSelectedEvent.CARD_SELECTED event. In general try and avoid using generic handlers for controlling game logic. Paul Thank you Alex ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] AS3: Dispatching events to further listeners, but not to itself
Hello, may I please rephrase my question, maybe someone will have a hint for me? By my PlayingCard objects I'd like to dispatch 2 events: Event.CHANGE and MouseEvent.CLICK I do it because in my game you can drag cards, but also you can select them from a list and click a button. So I could use same handler functions. My problem with the MouseEvent.CLICK is however that I receive it twice - 1 event comes from the PlayingCard and another one seems to be dispatched automatically. Is there please a way to prevent the latter event from being sent? Thank you Alex ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
RE: [Flashcoders] AS3: Dispatching events to further listeners, but not to itself
I think your event is bubbling. -Original Message- From: flashcoders-boun...@chattyfig.figleaf.com [mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Alexander Farber Sent: zondag 28 december 2008 11:14 To: Flash Coders List Subject: Re: [Flashcoders] AS3: Dispatching events to further listeners, but not to itself Hello, may I please rephrase my question, maybe someone will have a hint for me? By my PlayingCard objects I'd like to dispatch 2 events: Event.CHANGE and MouseEvent.CLICK I do it because in my game you can drag cards, but also you can select them from a list and click a button. So I could use same handler functions. My problem with the MouseEvent.CLICK is however that I receive it twice - 1 event comes from the PlayingCard and another one seems to be dispatched automatically. Is there please a way to prevent the latter event from being sent? Thank you Alex ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders No virus found in this incoming message. Checked by AVG - http://www.avg.com Version: 8.0.176 / Virus Database: 270.10.0/1866 - Release Date: 27-12-2008 20:49 ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] AS3: Dispatching events to further listeners, but not to itself
I haven't studied your code in depth - however, I would say this this is wrong (whatever you are doing): private function handleMouseMove(event:MouseEvent):void { // XXX trying to reuse the MOUSE_MOVE event // XXX and to dispatch it to PlayingTable - fails :-( dispatchEvent(event); } The Flash event system doesn't like redispatching the same event object. To redispatch an event like this, try the following: private function handleMouseMove(event:MouseEvent):void { // XXX trying to reuse the MOUSE_MOVE event // XXX and to dispatch it to PlayingTable - fails :-( dispatchEvent(event.clone()); } HTH, Ian On Sun, Dec 28, 2008 at 10:16 AM, Cor c...@chello.nl wrote: I think your event is bubbling. -Original Message- From: flashcoders-boun...@chattyfig.figleaf.com [mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Alexander Farber Sent: zondag 28 december 2008 11:14 To: Flash Coders List Subject: Re: [Flashcoders] AS3: Dispatching events to further listeners, but not to itself Hello, may I please rephrase my question, maybe someone will have a hint for me? By my PlayingCard objects I'd like to dispatch 2 events: Event.CHANGE and MouseEvent.CLICK I do it because in my game you can drag cards, but also you can select them from a list and click a button. So I could use same handler functions. My problem with the MouseEvent.CLICK is however that I receive it twice - 1 event comes from the PlayingCard and another one seems to be dispatched automatically. Is there please a way to prevent the latter event from being sent? Thank you Alex ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders No virus found in this incoming message. Checked by AVG - http://www.avg.com Version: 8.0.176 / Virus Database: 270.10.0/1866 - Release Date: 27-12-2008 20:49 ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] AS3: Dispatching events to further listeners, but not to itself
Mousechildren = false ? Sent from my iPhone On 28 Dec 2008, at 10:13, Alexander Farber alexander.far...@gmail.com wrote: Hello, may I please rephrase my question, maybe someone will have a hint for me? By my PlayingCard objects I'd like to dispatch 2 events: Event.CHANGE and MouseEvent.CLICK I do it because in my game you can drag cards, but also you can select them from a list and click a button. So I could use same handler functions. My problem with the MouseEvent.CLICK is however that I receive it twice - 1 event comes from the PlayingCard and another one seems to be dispatched automatically. Is there please a way to prevent the latter event from being sent? Thank you Alex ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
[Flashcoders] AS3: Dispatching events to further listeners, but not to itself
Hello, I have 2 classes: PlayingCard and PlayingTable. The PlayingCard listens on MOUSE_UP, DOWN and MOVE to call startDrag() and stopDrag(). I do not want to introduce custom events, so I try to subscribe the PlayingTable to MOUSE_MOVE and MOUSE_UP events of each PlayingCard, so that the table can: 1) Detect that a PlayingCard is being dragged to a right spot (depending on the current phase of the game - for ex. from the dealer to the player), so that it can change color (like glow in green) 2) Detect that the mouse has been released after dragging a PlayingCard and check if the move been valid. My problem is that when I try to dispatch the MOUSE_MOVE events, then the PlayingCard receives it again and again and gives me the runtime error: Error #2094: Event dispatch recursion overflow. at flash.events::EventDispatcher/dispatchEventFunction() at flash.events::EventDispatcher/dispatchEvent() at Card/handleMouseMove() Has anybody please a solution for this probably often occuring problem? Thank you Alex PS: Here is my current troublesome code: public function PlayingCard() { .. addEventListener(MouseEvent.MOUSE_DOWN, handleMouseDown); } private function handleMouseDown(event:MouseEvent):void { addEventListener(MouseEvent.MOUSE_UP, handleMouseUp); addEventListener(MouseEvent.MOUSE_MOVE, handleMouseMove); ... startDrag(); } private function handleMouseUp(event:MouseEvent):void { removeEventListener(MouseEvent.MOUSE_UP, handleMouseUp); removeEventListener(MouseEvent.MOUSE_MOVE, handleMouseMove); .. stopDrag(); } private function handleMouseMove(event:MouseEvent):void { // XXX trying to reuse the MOUSE_MOVE event // XXX and to dispatch it to PlayingTable - fails :-( dispatchEvent(event); } ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] AS3: Dispatching events to further listeners, but not to itself
you might find that using MOUSE_MOVE is a little heavy on the processor as it can fire multiple times, even within the same frame it's probably better to use Event.ENTER_FRAME and check for the mouseX and mouseY and while you're at it, you might as well use the same listener to move the card rather than startDrag()/stopDrag() don't know if it would help, though a On Tue, Dec 23, 2008 at 4:49 PM, Joel Stransky stranskydes...@gmail.comwrote: Why not just include the detection logic inside the handlers you already have? On Tue, Dec 23, 2008 at 9:52 AM, Alexander Farber alexander.far...@gmail.com wrote: Hello, I have 2 classes: PlayingCard and PlayingTable. The PlayingCard listens on MOUSE_UP, DOWN and MOVE to call startDrag() and stopDrag(). I do not want to introduce custom events, so I try to subscribe the PlayingTable to MOUSE_MOVE and MOUSE_UP events of each PlayingCard, so that the table can: 1) Detect that a PlayingCard is being dragged to a right spot (depending on the current phase of the game - for ex. from the dealer to the player), so that it can change color (like glow in green) 2) Detect that the mouse has been released after dragging a PlayingCard and check if the move been valid. My problem is that when I try to dispatch the MOUSE_MOVE events, then the PlayingCard receives it again and again and gives me the runtime error: Error #2094: Event dispatch recursion overflow. at flash.events::EventDispatcher/dispatchEventFunction() at flash.events::EventDispatcher/dispatchEvent() at Card/handleMouseMove() Has anybody please a solution for this probably often occuring problem? Thank you Alex PS: Here is my current troublesome code: public function PlayingCard() { .. addEventListener(MouseEvent.MOUSE_DOWN, handleMouseDown); } private function handleMouseDown(event:MouseEvent):void { addEventListener(MouseEvent.MOUSE_UP, handleMouseUp); addEventListener(MouseEvent.MOUSE_MOVE, handleMouseMove); ... startDrag(); } private function handleMouseUp(event:MouseEvent):void { removeEventListener(MouseEvent.MOUSE_UP, handleMouseUp); removeEventListener(MouseEvent.MOUSE_MOVE, handleMouseMove); .. stopDrag(); } private function handleMouseMove(event:MouseEvent):void { // XXX trying to reuse the MOUSE_MOVE event // XXX and to dispatch it to PlayingTable - fails :-( dispatchEvent(event); } ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders -- --Joel Stransky stranskydesign.com ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] AS3: Dispatching events to further listeners, but not to itself
Why not just include the detection logic inside the handlers you already have? On Tue, Dec 23, 2008 at 9:52 AM, Alexander Farber alexander.far...@gmail.com wrote: Hello, I have 2 classes: PlayingCard and PlayingTable. The PlayingCard listens on MOUSE_UP, DOWN and MOVE to call startDrag() and stopDrag(). I do not want to introduce custom events, so I try to subscribe the PlayingTable to MOUSE_MOVE and MOUSE_UP events of each PlayingCard, so that the table can: 1) Detect that a PlayingCard is being dragged to a right spot (depending on the current phase of the game - for ex. from the dealer to the player), so that it can change color (like glow in green) 2) Detect that the mouse has been released after dragging a PlayingCard and check if the move been valid. My problem is that when I try to dispatch the MOUSE_MOVE events, then the PlayingCard receives it again and again and gives me the runtime error: Error #2094: Event dispatch recursion overflow. at flash.events::EventDispatcher/dispatchEventFunction() at flash.events::EventDispatcher/dispatchEvent() at Card/handleMouseMove() Has anybody please a solution for this probably often occuring problem? Thank you Alex PS: Here is my current troublesome code: public function PlayingCard() { .. addEventListener(MouseEvent.MOUSE_DOWN, handleMouseDown); } private function handleMouseDown(event:MouseEvent):void { addEventListener(MouseEvent.MOUSE_UP, handleMouseUp); addEventListener(MouseEvent.MOUSE_MOVE, handleMouseMove); ... startDrag(); } private function handleMouseUp(event:MouseEvent):void { removeEventListener(MouseEvent.MOUSE_UP, handleMouseUp); removeEventListener(MouseEvent.MOUSE_MOVE, handleMouseMove); .. stopDrag(); } private function handleMouseMove(event:MouseEvent):void { // XXX trying to reuse the MOUSE_MOVE event // XXX and to dispatch it to PlayingTable - fails :-( dispatchEvent(event); } ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders -- --Joel Stransky stranskydesign.com ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders