Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Actually, the answer depends on which platform you are targeting. In <strong>FlashPlayer</strong>, <strong>hitTestObject</strong> just checks if the bounding boxes of the objects overlap, so as long as you have the correct x and y positions and the correct width and height for your objects you don't need them to actually be on the stage. </p> <p>However, in <strong>AIR</strong>, probably some kind of code optimization is taking place, and if one of the objects is not actually on the stage it will return false</p> <p>Let's just tinker a little with the example from the docs, removing just one addChild: </p> <pre><code>import flash.display.Shape; var circle1:Shape = new Shape(); circle1.graphics.beginFill(0x0000FF); circle1.graphics.drawCircle(40, 40, 40); //addChild(circle1); var circle2:Shape = new Shape(); circle2.graphics.beginFill(0x00FF00); circle2.graphics.drawCircle(40, 40, 40); circle2.x = 50; addChild(circle2); var circle3:Shape = new Shape(); circle3.graphics.beginFill(0xFF0000); circle3.graphics.drawCircle(40, 40, 40); circle3.x = 100; circle3.y = 67; addChild(circle3); trace(circle1.hitTestObject(circle2)); trace(circle1.hitTestObject(circle3)); trace(circle2.hitTestObject(circle3)); </code></pre> <p>In FP10 we get the following output:</p> <pre><code>true false true </code></pre> <p>However, in AIR we get:</p> <pre><code>false false true </code></pre> <p>The key difference is that hitTestObject between the circle1 and circle2 is false in AIR because circle1 has not been added to the stage, but in FlashPlayer is true anyways. Thanks to @user1113426 for pointing there was something amiss here!</p>
    singulars
    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