Why not just include the detection logic inside the handlers you already have?
On Tue, Dec 23, 2008 at 9:52 AM, Alexander Farber < [email protected]> 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 > [email protected] > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > -- --Joel Stransky stranskydesign.com _______________________________________________ Flashcoders mailing list [email protected] http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

