Hello ::- ). I have stumbled upon a Flash Player behavior about which I have some assumptions & some questions, but I would like to discuss them with somebody who has VERY good knowledge of Flash Player. If you like a good brain teaser and like to see some living proof about how Flash Player works, read on CAREFULLY. I also present inside this post the SOLUTION, which I managed to find after 10 hours of torment.
Sorry for the use of caps in this message but I wanted to emphasize some things. Imagine that as I am writing this, I am outraged and desperate ::- ).
Ok, so here is the (very simple) situation:
1. I got an ENTER_FRAME hooked on the Stage, in which sometimes, when the User moves the mouse, I move all objects on the Stage.
2. Inside a Timer, I got a hit testing function in which I test against the EDGES of some objects.
3. When the objects on the Stage are MOVED (in increments of 8 pixels / frame), this is what happens:
dispObject.visible = false; //I repeat, that's visible = false.
dispObject.hitTestPoint(x, y, true); //Returns TRUE. Yes, despite the object being hidden, the hit test SUCCEEDS.
dispObject.visible = true;
dispObject.hitTestPoint(x, y, true); //Returns FALSE when the object is VISIBLE.
Where X and Y are coordinates situated INSIDE the shape of the object, at the extremities (left or right). I got solid proof that they're inside the object, as I dumped the contents of the Stage to a BitmapData and investigated it. Without doubt, the hit testing occurs INSIDE the colored shape of the object but the result is FALSE when the object is VISIBLE=TRUE and TRUE when the object is hidden.
Also, the Hit Tests that I am doing are based on 2 moving objects: I am hit testing against a moving object (dispObject), and the X/Y location where I am doing the hit testing are dictated by the position of ANOTHER moving object.
Now... I know very well how hitTestPoint works. The object I'm hit testing is ON the Display List (I only played with the Visible property).
Instead of doing the Hit Test in the Timer, I just queued it in an Array and I moved it inside the ENTER_FRAME event, PRIOR TO MOVING THE STAGE OBJECTS. This makes it work regardless of whether the Hit Tested object is Visible or not.
1. Does Flash Player have an internal priority for event types? I am NOT talking about Event Listener Priority but about priority in executing entire TYPES of events.
2. Case in question: does ENTER_FRAME *ALWAYS* execute PRIOR to TIMER?
3. Why does hitTestPoint work differently with INVISIBLE objects? Let me rephrase that: why do INVISIBLE objects get moved AFTER the TIMER event??? Becaues obviously this is what happens. When the object is invisible, Flash Player moves it differently, so that's why the Hit Test succeeds. If the object is Visible, it gets moved in ENTER_FRAME and the Hit Test fails, EVEN THOUGH ON THE SCREEN, I actually SEE IT HIT the ACTUAL SHAPE of the object.
So yes, what I'm saying is that visibly, on the screen, it should NOT fail because I drawed some pixels at each location I am shape-hit testing and the pixels actually INTERSECT the SHAPE, but even so, the function returns FALSE. But when the object is HIDDEN, the hit test RETURNS TRUE. Okay, that's about all the ways I can explain it haha.
Sorry for repeating myself a bit, but I really want to get the point home. To conclude: I managed to fix the problem but I wonder why, God, why did I have to lose so much time with this? So here's to hoping some Guru sees this thread and guides me through the mysteries of Flash Player internals, because this sure as heck isn't documented (I looked everywhere about Event Priorities and STAGE WORKFLOW but couldn't find anything!)