Posted tagged ‘animate with script’

Making a simple Motion Tween using script

August 8, 2008

Okey, this isn’t really a real motion tween, but it will basically do the same thing. It’s simple, as simple as it can get, almost….

So, I’m gonna teach you how to make a motion tween using script, and I will also learn you how to do a play and pause button for it. So, go on to step one, now!

STEP 1:

Well, let’s begin by looking at the first frame in the movie. It’s empty, for now. But soon, it won’t be. Begin with creating two buttons. They do not need any instance names. The first button should be a play button, the second one should be a pause button. Another thing you could do is to add a MC, no instance name this time either. Now, a last thing to do at this step, add the following code to the first frame!

playpause=2; //The tween is paused, change to 1 to have it play as default

STEP 2:

Now, you got two buttons. You need to add some code on them, of course. If there’s some new commands in the code, read it until you do understand the code, and don’t just copy/paste.

This one is for the play button:

on(release){ //When you release the button
_root.playpause=1; //Set the variable to 1 (play)
}

And here’s a code for the pause button:
on(release){ //When you release the button
_root.playpause=1; //Set the variable to 2 (pause)
}

Good, but there’s still the most important part missing. Take a look at step 3!

STEP 3:

Let’s finish it! You need to add some code to the MC, or it won’t work. The code you need is basically simple, and if you know how to use variables, you should have no problem to modify it. And anyway, there’s descriptions for every line with any commands.

onClipEvent(load){ //When MC have been loaded
speed=5; //Set the speed of the motion tween
startx=100; //Set the X starting position
starty=100; //Set the Y starting position
endx=220; //Set the X final position
endy=300; //Set the Y final position
}
onClipEvent(enterFrame){//When you enter the frame, this code will run itself over and over again
if(_root.playpause===1){//1 is play, pause is 2. It must be on play.
if(this._x< to >)
this._x+=speed;//The MC X axis will go higher
}
if(this._y< to >)
this._y+=speed;//The MC Y axis will go higher
}
}
}

WORDPRESS DIDN’T LIKE SOME PARTS OF THE CODE (line 10 and 13), HERE’S A WORKING ONE!

Only 17 lines! And it’s still working! In total, you used 24 lines(!), and the result is a tween using script, with a play and pause button too!

Oh yeah, maybe you can use this for something, I have no idea if you can find something to do with it, but if you use it, feel free to post links!

Advertisements

FUN: Making MC’s do some fun stuff (Part 2)

August 3, 2008

I’m just bored. That’s why I’ve been writting so much today. I’m already posting the 6th tutorial today. The blogs first day, lol. Anyway, this is the sequel to my previous FUN stuff post. Here, I’ll teach you some more fun stuff you can do!

PROJECT NUMBER 3: Making a MC fade out, and fade in, once, using script.

This was a cool experiment I did, try it out! You must first create a new MC of course. And then read trough this code, until you understand it, and THEN you’re allowed to copy/paste it. But not before you’ve finished that task. Here’s the code:

onClipEvent (load) {//When the MC loads
speed = 5;//Set the desired speed.
number = 0;//Number will go to 0
}
onClipEvent (enterFrame) {//When you enter the frame, this code will run itself over and over again.
if (number<100) {//If the number is less than 100
_alpha -= speed;//Alpha will go lower
number += speed;//Number will go higher
} else if (number>=100) {//But what if the number is 100 or more?
number = 200;//Sets "number" to 200
_alpha += speed;//Alpha will go up
number -= speed;//Number will go down
}
}

It’s really cool, try it out!

PROJECT NUMBER 4: Making something like an animation with script.

So, now I’ve added a few new commands onto the code. This do now acctually look like an animation, but it’s all made out of script!

onClipEvent (load) {//When the MC loads
speed = 5;//Set the desired speed for changing the alpha.
rot_speed= 15; //Set the desired speed for rotating
sca_speed= 0.5; //Set the desired speed for scaling the MC
number = 0;//Number will go to 0
}
onClipEvent (enterFrame) {//When you enter the frame, this code will run itself over and over again.
if (number<100) {//If the number is less than 100
_alpha -= speed;//Alpha will go lower
number += speed;//Number will go higher
} else if (number>=100) {//But what if the number is 100 or more?
number = 200;//Sets "number" to 200
_alpha += speed;//Alpha will go up
number -= speed;//Number will go down
}
this._rotation+=rot_speed;//This will make the MC rotate
this._xscale+=sca_speed;//This MC will get a higher x scale
this._yscale-=sca_speed;//This MC will get a higher y scale
}

BTW guys, if you like these “fun” tutorials, tell me and I’ll make more!