576
Creating Interaction with ActionScript
8.
Enter the following code into the Actions panel:
balance_mc.top = balance_mc._y;
balance_mc.bottom = balance_mc._y;
balance_mc.left = balance_mc._x;
balance_mc.right = balance_mc._x + 100;
balance_mc._x += 50;
balance_mc.handle_btn.onPress = function() {
startDrag(this._parent, false, this._parent.left, this._parent.top,
this._parent.right, this._parent.bottom);
};
balance_mc.handle_btn.onRelease = function() {
stopDrag();
var level:Number = Math.ceil((this._parent._x - this._parent.left -
50) * 2);
this._parent._parent.song_sound.setPan(level);
};
balance_mc.handle_btn.onReleaseOutside =
balance_mc.handle_btn.onRelease;
The
startDrag()
parameters
left
,
top
,
right
, and
bottom
are variables set in a
movie clip action.
9.
Select Control > Test Movie to use the balance slider.
For more information about the methods of the Sound class, see Sound in the
ActionScript 2.0 Language Reference
.
Detecting collisions
The
hitTest()
method of the MovieClip class detects collisions in a SWF file. It checks to
see if an object has collided with a movie clip and returns a Boolean value (
true
or
false
).
You would want to know whether a collision has occurred either to test if the user has arrived
at a certain static area on the Stage, or to determine when one movie clip has reached another.
With
hitTest()
, you can determine these results.
You can use the parameters of
hitTest()
to specify the
x
and
y
coordinates of a hit area on
the Stage or use the target path of another movie clip as a hit area. When you specify
x
and
y
,
hitTest()
returns
true
if the point identified by (
x
,
y
) is a non-transparent point. When a
target is passed to
hitTest()
, the bounding boxes of the two movie clips are compared. If
they intersect,
hitTest()
returns
true
. If the two boxes do not intersect,
hitTest()
returns
false
.
You can also use
hitTest()
to test a collision between two movie clips.
The following example shows how to detect a collision between a mouse and movie clips on
the Stage.
Содержание FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
Страница 1: ...Learning ActionScript 2 0 in Flash...
Страница 8: ...8 Contents...
Страница 18: ...18 Introduction...
Страница 30: ...30 What s New in Flash 8 ActionScript...
Страница 66: ...66 Writing and Editing ActionScript 2 0...
Страница 328: ...328 Interfaces...
Страница 350: ...350 Handling Events...
Страница 590: ...590 Creating Interaction with ActionScript...
Страница 710: ...710 Understanding Security...
Страница 730: ...730 Debugging Applications...
Страница 780: ...780 Deprecated Flash 4 operators...
Страница 830: ...830 Index...