Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You check <code>Event.target</code> and <code>Event.currentTarget</code>. <code>target</code> is the object that originally dispatched the event and <code>currentTarget</code> is the latest object to dispatch it (generally the object your listener is attached to).</p> <p>Quick overview of that. Assume obj2 is wrapped by obj1 which is on the stage. Quick hierarchy:</p> <pre><code>-Stage --obj1 ---obj2 </code></pre> <p>If you were to trigger an event (that bubbles, that is important as it allows an event to go through its parents until it reaches an event handler. I believe all <code>MouseEvent</code>s do this ) in obj2 and had a listener attached to Stage, obj2 would be the target and Stage would be the currentTarget.</p> <p>So how does this work for you? Well, you just need to check what target and currentTarget are to determine where the event started and where it currently is at.</p> <p>Plug this into Flash and click on the object and release in various locations and take a look at your console (I did test this):</p> <pre><code>import flash.display.*; var mySprite:Sprite = new Sprite(); mySprite.graphics.beginFill(0x000000); mySprite.graphics.drawRect(0,0,100,100); mySprite.graphics.endFill(); addChild( mySprite); stage.addEventListener(MouseEvent.MOUSE_UP, handleStageMouseUp); function handleStageMouseUp(e:MouseEvent):void { trace( "handleStageMouseUp - target == stage: " + (e.target == this.stage) ); trace( "handleStageMouseUp - target == mySprite: " + (e.target == mySprite) ); trace( "handleStageMouseUp - currentTarget == stage: " + (e.currentTarget == this.stage) ); trace( "handleStageMouseUp - currentTarget == mySprite: " + (e.currentTarget == mySprite) ); trace( "--------" ); } </code></pre> <p>For the most part, in your stageUp handler, you can check if <code>e.target == mySprite</code> to determine if it also happened to mySprite.</p> <p>There is a caveat here, though. If your Sprite has children, one of those children will be the target. However, if you set <code>mySprite.mouseChildren = false</code>, it will not register mouse events on children which means it will behave as it does in the above example.</p> <p>Hopefully that helps</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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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