Advertisement |
In this tutorial you will learn how to follow an
object with the mouse in Actionscript 3.0. This means that when you move the
mouse the object will follow. I have created two different variations in this
tutorial for the ‘follow object’. The first variation follows the mouse’s x and
y position which will means the object moves when the mouse moves. The second
variation follows the mouse’s position with a slight delay, so when you move
the mouse the object will follow with a small pause.
Follow object with mouse in Actionscript 3
Step 1
Open a new Flash AS3 file.
Select Oval tool (O) and create a simply circle shape on the stage like below. You can alternatively create a different shape or import an image if you wish.
Step 2
Convert your circle shape into a symbol by selecting F8. Give your symbol appropriate name, check movie clip, choose the centre registration point and click ok.
Select your movie clip and give it the instance name “ball_mc”.
Step 3 (first variation)
On the timeline create a new layer called “Actions”. Select the first frame and hit F9 to open up the actions panel and enter the following code:
Follow object with mouse in Actionscript 3
Step 1
Open a new Flash AS3 file.
Select Oval tool (O) and create a simply circle shape on the stage like below. You can alternatively create a different shape or import an image if you wish.
Step 2
Convert your circle shape into a symbol by selecting F8. Give your symbol appropriate name, check movie clip, choose the centre registration point and click ok.
Select your movie clip and give it the instance name “ball_mc”.
Step 3 (first variation)
On the timeline create a new layer called “Actions”. Select the first frame and hit F9 to open up the actions panel and enter the following code:
//1.
stage.addEventListener(MouseEvent.MOUSE_MOVE,followBall);
//2.
function followBall(event:MouseEvent):void {
ball_mc.x=mouseX;
ball_mc.y=mouseY;
}
0 comments: