Note that there are some explanatory texts on larger screens.

plurals
  1. POActionScript 3, handling mouse event cases
    primarykey
    data
    text
    <p>I'm learning ActionScript 3 and at the moment, following a tutorial here <a href="http://www.senocular.com/flash/tutorials/as3withmxmlc/" rel="nofollow">http://www.senocular.com/flash/tutorials/as3withmxmlc/</a> . It describes a simple application which put a ball on the stage and lets the user drag it around. But it has bugs, especially because it doesn't handle the case that the user drags the pointer off the stage. This has gotten me thinking about a better way to handle cases. For starters, I'm considering how to handle MOUSE_UP events. I'd like to write something like this:</p> <pre><code>public class Test extends Sprite { public function Test(stage:Stage) { mySprite = SomeSpriteClass() stage.addEventListener(MouseEvent.MOUSE_UP, handleStageMouseUp); mySprite.addEventListener(MouseEvent.MOUSE_UP, handleSpriteMouseUp); } private function handleStageMouseUp(event:MouseEvent):void { // how do I determine here if there was also a MOUSE_UP on the Sprite? // Perhaps I could check the click coordinates of 'event' to see if // they are superimposed on the Sprite. } private function handleSpriteMouseUp(event:MouseEvent):void { // I don't need this method if I can handle all cases in the // method above. } } </code></pre> <p>This issue that arises is that with the event model ActionScript3 uses, I don't know how to look for cases that involve combination of events. Alternatively as I wrote in the comment above in handleStageMouseUp() I could check to see if a mouse event occurs over 'mySprite' (how would I do that?) </p> <p>What I'd really like to do is be able to combine all my case logic in something like this:</p> <pre><code>private function handleAllCases(...):void { if (..mouse up on stage but not sprite..) { .. handle case ..; } else if ( .. mouse up on both stage and sprite .. ) { .. handle case .. ; } } </code></pre> <p>Is there a way to do this, or perhaps a better way to think about it?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload