A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: Flash MX Tween help

  1. #1
    Member
    Join Date
    Mar 2001
    Posts
    44

    Flash MX Tween help

    Hi, i have managed to get the following code to work and it does the job nicely, but what i would like to know if there is a way to way "once this has moves to where its supposed to be - do something"

    I have all my code on frame 1 of the root. is there a way to do this without having a loop movie clip running to check if sceney = endsceney ?

    Thanks for your help!


    Code:
    function moveY(movName, moveTo, moveType){
    	var time = 25;
    	var sceney = movName._y;
    	var endsceney = moveTo;
    	new mx.transitions.Tween(movName, "_y", moveType, sceney, endsceney , time);
    slammin

  2. #2
    Senior Member
    Join Date
    Oct 2005
    Posts
    148
    The tween class has the Tween.onMotionFinished method, which is an event handler that will execute once the tween has finished.

    Give your tween a variable name and you'll be able to use it, like so (new code in highlighted in bold):

    Code:
    function moveY(movName, moveTo, moveType){
    	var time = 25;
    	var sceney = movName._y;
    	var endsceney = moveTo;
    	var myTween = new mx.transitions.Tween(movName, "_y", moveType, sceney, endsceney , time);
    	myTween.onMotionFinished = function() {
    		trace("tween is finished");
    		myTween.yoyo();
    	};
    }
    In the above code, I assigned the variable name "myTween" to the tween instance. This allows me to reference the tween and access the onMotionFinished method of the tween class (ie. myTween.onMotionFinished)

    Once the tween has finished, I output a msg in the trace window, and also reverse the tween animation by using the Tween class yoyo() method.

    Just an example, and ofcourse you can put anything inside the onMotionFinished function yourself.

  3. #3
    Member
    Join Date
    Mar 2001
    Posts
    44
    Wow thanks a lot. This is exactly what i wanted. i want the mc to move off the stage, change to a different keyframe then pop back on with the new content.
    Cheers!
    slammin

  4. #4
    Member
    Join Date
    Mar 2001
    Posts
    44
    Is there any way to make the yoyo run just once? its going craaazy!
    slammin

  5. #5
    Senior Member
    Join Date
    Oct 2005
    Posts
    148
    Yeah a number of ways to accomplish that.

    For example, use a conditional statement (ie. if statement) to check if the yoyo tween has been completed. I do this by using creating a boolean variable (true/false variable) that gets toggled true or false if the yoyo has or hasn't been executed.

    Code:
    //create a boolean variable
    var yoyoIsFinished = false;
    function moveY(movName, moveTo, moveType){
    	var time = 25;
    	var sceney = movName._y;
    	var endsceney = moveTo;
    	var myTween = new mx.transitions.Tween(movName, "_y", moveType, sceney, endsceney , time);
    	myTween.onMotionFinished = function() {
        	trace("tween is finished");
    		trace(yoyoIsFinished);
    		//
    		if(yoyoIsFinished) {
    			yoyoIsFinished = false;
    		} else {
    			myTween.yoyo();
    			yoyoIsFinished = true;
    		}
    	};
    }
    Notice that I created a yoyoIsFinished variable, and then I made an "if" statement to check the value of the yoyoIsFinished variable. If true, which means the yoyo tween has been done, then reset the yoyoIsFinished variable back to false. If false, then execute the yoyo tween, and set the the yoyoIsFinished variable to true.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center