Game Development Reference
In-Depth Information
Because you have to specify the rectangle as the second argument, you also have
to supply a first argument, which is where b]hoa comes from. b]hoa refers to the
hk_g?ajpan parameter that you looked at in the previous section. Setting it to b]hoa
tells the program that you don't want the object to snap to the mouse's center point.
You can set it to pnqa if you want to; it's entirely up to you.
After you follow those steps, you'll have an invisible rectangle that you can't drag your object out of. If
you create a Na_p]jcha object the same size as the stage, the object will be confined within the stage
Dragging and dropping the object-oriented way
When you design drag-and-drop environments and interfaces, you'll almost certainly find the
object-oriented way a little more flexible, easier to code, and easier to manage than the procedural
approach you just looked at. I could have left you on your own after the first example, but there are
some important quirks regarding AS3.0's drag-and-drop system that you need to know in order to
get an object-oriented drag-and-drop system working in the way that you might expect it to. I'm also
going to show you how you can use some of the techniques you looked at earlier, such as using an
AJPAN[BN=IA event, to put you on the path to creating quite complex drag-and-drop objects if you
need to.
1. In this chapter's source files, you'll find a folder called @n]c]j`@nkl.. Open it as a project
in the Project panel.
2. Test the project. It works exactly the same as the first example except for two improvements:
The objects ease gently into position over the targets.
The objects are prevented from moving beyond the edges of the stage.
In this example, both the na`Omq]na and ^hqaOmq]na objects have been bound to the same class:
@n]c]^haK^fa_p. You can check this by doing the following:
1. Open the `n]c=j`@nkl.*bh] file.
2. Select either the na`Omq]na or ^hqaOmq]na symbol in the Library .
3. Click the small Lnklanpeao button at the bottom of the Library panel.
4. You'll see a window open that looks something like Figure 10-4. Both symbols have
@n]c]^haK^fa_p as their base class, which allows both objects to use the same class.
Search Nedrilad ::

Custom Search