Black Friday sale is now on! 50% off Laravel: The Modular Way. Learn more

Motion tween with actionscript

David Carr

Flash Tutorials

    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).

    Laravel Modules Book by David Carr

    Help support the blog so that I can continue creating new content!

    Subscribe to my newsletter

    Subscribe and get my books and product announcements.

    © 2009 - 2022 DC Blog. All code MIT license. All rights reserved.