04May2011
Author
Dave
Category
Flash
Tags
, ,
Motion tween with actionscript Thumbnail

Motion tween with actionscript

If you ever wanted to do a motion tween with actionscript this tutorial will be very useful.

If you ever wanted to do a motion tween with actionscript this tutorial will be very useful.

The actionscript goes in the frame. Make a button in my example I gave it an instance name of bt.

make a movieclip of the item you want to tween give it an instance name in my example i have given it a name of a1

 
// button has an instance name of bt when it's pressed the tween is performed
 
bt.onPress = function() {// call function to do the tween
tweenFeat();
}
 
function tweenFeat() {
 
easeType = mx.transitions.easing.Regular.easeOut;
// define what type of tween to be used to see other tween effects visit http://www.oman3d.com/tutorials/flash/tweenclasseasing/
var begin_x = 1061; // define where object is on stage _x
var begin_y = 144.3; // define where object is on stage _y
var end_x = 531; // define where object will end on stage _x
var end_y = 144.3; // define where object will end on stage _y
var time = 2; // define speed
 
//putting it together
// new tween your mc name
featTween = new mx.transitions.Tween(a1, "_x", easeType, begin_x, end_x, time, true);
featTween = new mx.transitions.Tween(a1, "_y", easeType, begin_y, end_y, time, true);
}

if you wanted to make another tween right after the first you can use onMotionFinished see example below

 
bt.onPress = function() {
 
 
 
// call function to do the tween
 
 
 
tweenFeat();
 
 
 
}
 
 
 
function tweenFeat() {
 
 
 
easeType = mx.transitions.easing.Regular.easeOut;
 
 
 
// define what type of tween to be used to see other tween effects visit http://www.oman3d.com/tutorials/flash/tweenclasseasing/
 
 
 
var begin_x = 1061; // define where object is on stage _x
 
 
 
var begin_y = 144.3; // define where object is on stage _y
 
 
 
var end_x = 531; // define where object will end on stage _x
 
 
 
var end_y = 144.3; // define where object will end on stage _y
 
 
 
var time = 2; // define speed
 
 
 
//putting it together
 
 
 
// new tween your mc name
 
 
 
featTween = new mx.transitions.Tween(a1, "_x", easeType, begin_x, end_x, time, true);
 
 
 
featTween = new mx.transitions.Tween(a1, "_y", easeType, begin_y, end_y, time, true);
 
 
 
featTween.onMotionFinished = function (){ // when first tween has finished do this tween
 
 
 
easeType = mx.transitions.easing.Bounce.easeOut; // define what type of tween to be used
 
 
 
var begin_x = 454; // define where object is on stage _x
 
 
 
var begin_y = 1670; // define where object is on stage _y
 
 
 
var end_x = -1650; // define where object will end on stage _x
 
 
 
var end_y = 1630; // define where object will end on stage _y
 
 
 
var time = 2; // define speed
 
 
 
//putting it together
 
 
 
// new tween your mc name
 
 
 
featTween = new mx.transitions.Tween(a1, "_x", easeType, begin_x, end_x, time, true);
 
 
 
featTween = new mx.transitions.Tween(a1, "_y", easeType, begin_y, end_y, time, true);
 
 
 
}
 
 
 
}

With this code is relatively easy to do motion tweens with actionscript just make sure you set instance names for your buttons and movieclips and have them in the actionscript (in the frame).

Author
Dave

About the Author

has written 72 articles on Dave is my name.

My name is David Carr I'm a PHP web developer based in Hull it is my passion to design and develop clean, accessible and usable websites using PHP and other web technologies, I'm an avid Twitter user why not follow me? https://twitter.com/daveismynamecom

Visit this author's website   ·   View more posts by

Sharing is caring.
  • Subscribe to our feed
  • Share this post on Delicious
  • StumbleUpon this post
  • Share this post on Digg
  • Tweet about this post
  • Share this post on Mixx
  • Share this post on Technorati
  • Share this post on Facebook
  • Share this post on NewsVine
  • Share this post on Reddit
  • Share this post on Google
  • Share this post on LinkedIn

Discussion

No responses to "Motion tween with actionscript"

There are no comments yet, add one below.

Leave a Comment