Game Development Reference
The last thing the code does is to display the name of the object that the mouse is released over by
using the `nklP]ncap property. If you test the project, you'll notice that when you release the mouse,
the name of the object that is directly under the tip of the mouse pointer is displayed in the Output
panel. This doesn't have any functional purpose in the program except to illustrate how the `nklP]ncap
This is the line of code that displays the name of the object that `nklP]ncap references:
Have a look at the object path:
_qnnajp@n]cK^fa_p*`nklP]ncap* l]najp *j]ia
Do you notice something odd there? Why do you need to access the l]najp property? If you're any-
thing like me, you might have thought that the path should have more logically read something like
But it doesn't. An extra l]najp has been slipped in there just to keep you on your toes. The reason
why is worth explaining—if you ever use the `nklP]ncap property in any of your games, you'll have
a few sleepless nights if you don't understand it.
`nklP]ncap is a property of the Ikrea?hel class. `nklP]ncap*j]ia gives you the name of the object
that the mouse is over inside that Movie Clip object. However, in almost any drag-and-drop scenario
imaginable, you don't need to know the name of that object (which will usually be a drawing shape
from the Od]la class or a Movie Clip subobject). What's important to know is the name of the object
that the mouse is over in the parent container .
In this case, the parent container is an object that's on the main stage. The stage is at the root of the
hierarchy for display objects, so it's also the parent container for any object on the main stage, includ-
ing the `nklP]ncap object in this case. Only when your dragable object doesn't contain any other
subobjects (or even drawing shapes) can you get by without referencing the parent object.
Remember this if you ever have problems with code that depends on being able to access the `nklP]ncap
object. More than one experienced Flash game designer has been tripped up by this! A very useful strategy
to follow while building drag-and-drop games is to set a pn]_a for both the l]najp and `nklP]ncap prop-
erties. This will help you keep things straight in your own mind while negotiating this little minefield.
A further word of caution about using `nklP]ncap: it returns only the name of the object that the
mouse is currently directly over . If part of the object that you're dragging is touching another object
when you release the mouse, but the tip of the mouse pointer isn't, `nklP]ncap doesn't register
that object. This is a limitation that could scuttle its use in many drag-and-drop games. Figure 10-3
illustrates some cases in which `nklP]ncap doesn't return any value, even though the object being
dragged is clearly over another object.