Making a simple Motion Tween using script


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
Explore posts in the same categories: ActionScript 2.0, Basic

Tags: , , , , , , , ,

You can comment below, or link to this permanent URL from your own site.

One Comment on “Making a simple Motion Tween using script”

  1. emalik Says:

    it seems u did not use startx and start y in your code, i was just doing some experiment and come up with with little modification to above code.

    just add this in onload event for setting the intial position

    this._x = startx;
    this._y = starty;

    am i right ….? but anyways it worked for me

    btw its just simple and useful thanks for help!


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: