Droptarget / Target
|
Top Previous Next |
1. | Continue from the previous tutorial or load the file "dragging.swi". Save the file as "mydroptarget.swi"
|
2. | Copy and paste the Object "ball". Rename the object "ball2" and change its color to blue
|
3. | Select the Scene in the 'Outline' Panel and add the following script commands (see the tutorial on Variables and Flow Control for more information):
|
The onLoad() Event is used to initialise the variables dt1 and dt2.
|
|
|
The onEnterFrame() Event is called on each Frame. If the value of ball._droptarget or ball2._droptarget has changed from the previous value(s), then the trace statements are executed.
|
|
Your 'Script' Panel should look like this:
|
4. | Select the 'Debug' tab, then return to the 'Layout' Panel and press play. In the 'Debug' Panel you should see:
|
Drag the blue ball over the red one. In the 'Debug' Panel you should now see:
|
This means that the blue ball (ball2) now sees /ball as its "droptarget". "/ball" is the name of _root.ball expressed in slash notation. Now "ball2._droptarget: /ball" appears the exact instant the mouse pointer crosses the boundary of the red ball.
|
Drag the blue ball away from the red ball and drag the red ball over the blue ball
|
· | The red ball appears under the blue ball because of the current layer ordering. This can be altered by selecting the ball in the 'Outline' Panel, then using the Menu items Modify | Order
|
· | When the red ball is under the blue ball the onSelfEvent (release) is not detected, so it is impossible to stop dragging the red ball while its center is obscured by the blue ball
|
|
The line "ball._droptarget: /ball2" indicates that the red ball (ball) now sees /ball2 as its "droptarget". "/ball2" is the name of _root.ball2 expressed in slash notation.
|
Press the 'Stop' button.
|
5. | Add the following script to ball2:
|
Your script should now look like:
|
6. | Select the 'Debug' tab, then return to the 'Layout' Panel and press play. Drag the blue ball over the red ball and you should see the following in the 'Debug' Panel:
|
The word MATCH indicates that the comparison "_droptarget==_parent.ball._target" has returned the value true. The _target property is used to return the name of the target Object in slash notation.
|
|
This type of comparison can be used to check when an Object has been dragged over another specific Object
|