Cara’s Flash Heart Tutorial: Pretty Nifty Stuff.
In this tutorial you will learn how to make your movie clip move away from your cursor
using the actionscript provided. I will be using a heart image and the name “heart” for my
movie clip. Feel free to use whatever image you’d like and name it whatever you’d like.
Step 1:
Open Flash and create a stage at least 300 x 300 pixels.
Step 2:
Create a new movie clip:
Insert > New Symbol > Movie Clip > ”heart”
-Or-
Cntrl+F8 > Movie Clip > ”heart”
Step 3:
Create 2 layers for this movie clip. 1st layer = actions, 2nd layer = heart image
Step 4:
In actions layer, insert 3 blank keyframes in a row. In heart layer, insert one blank
keyframe and insert image. Extend the frames over 2 spaces, covering your action
keyframes.
Step 5:
In actions layer, on 1st blank keyframe, type in this code
x00 = _x;
y00 = _y;
MAAI = 400;
Step 6:
In actions layer, on 2nd blank keyframe, type in this code
x0=_x
y0=_y
x=_root._xmouse
y=_root._ymouse
a=x-x0
b=y-y0
r=Math.sqrt(a*a+b*b)
quer_fugir_x=this._x-(a/r)*MAAI/r
quer_fugir_y=this._y-(b/r)*MAAI/r
quer_voltar_x=(x00-x0)/2
quer_voltar_y=(y00-y0)/2
this._x=quer_fugir_x+quer_voltar_x
this._y=quer_fugir_y+quer_voltar_y
Step 7:
In actions layer, on 3rd blank keyframe, type in this code
gotoAndPlay(2);
Step 8:
Go back to the stage on Scene 1 and drag movie clip onto stage in multiple places. When
you publish your movie, you should find that your movie clip moves away from your
cursor.