-
[F8] onMotionFinish tween
Here is a little sample I have been playing with to try to solve a bigger problem. On the stage are two MC's with the name img1 and img2. Both Mc's tween across the stage. When finished I want one to go back. When that's done I want the other to slide to the top of the stage.
In short animate, finish, animate, finish, animate, finish. Instead only the last tween is completed. Why? What happened to the other two tween inbetween?
Code:
import mx.transitions.Tween;
for (i=1; i<=2; i++) {
target = eval("img"+i);
var myTween:Tween = new Tween(target, "_x", mx.transitions.easing.Elastic.easeOut, 0, Stage.width-target._width, 5, true);
trace("running"+i);
myTween.FPS = 30;
myTween.onMotionFinished = function() {
trace("running Finish "+i);
//myTween.yoyo();
var myTween:Tween = new Tween(img1, "_x", mx.transitions.easing.Elastic.easeOut, img1._x, 0, 5, true);
};
myTween.onMotionFinished = function() {
trace("running Finish "+i);
//myTween.yoyo();
var myTween:Tween = new Tween(img1, "_y", mx.transitions.easing.Elastic.easeOut, img1._y, 0, 5, true);
};
myTween.onMotionFinished = function() {
trace("running Finish "+i);
//myTween.yoyo();
var myTween:Tween = new Tween(img2, "_x", mx.transitions.easing.Elastic.easeOut, img2._x, 100, 5, true);
};
}
-
sureley it would be easier just to place the next animation inside the function for the finished motion?
for instance
var tweenOne(mcOne,"alpha"...parameters...);
tweenOne.onMotionFinished=function(){
var tweenTwo(mcTwo,"alpha"...parameters...);
tweenTwo.onMotionFinished=function(){
var tweenThree(mcOne,"_x"...parameters...);
tweenThree.onMotionFinished=function(){
var tweenFour(mcTwo,"_y"...parameters...);
}
}
}
where ...parameters... is all the other parameters i couldnt be arsed to fill in!! lmao!
hope this helps!
-
That definitely works but I was trying to be more elegant. In other words I can't be arsed to write line after line of the same dang tween. Instead I want something slimmer.
ie:*note I'm paraphrasing the code in "english"
function tweenThis(target, property, start, end, duration)
tweenthis(object1_mc, _x, 0, 100, 2);
tweenthis.onMotionFinished(tweenthis(object2_mc, _x, 0, 100, 2);
tweenthis.onMotionFinished(tweenthis(object3_mc, _x, 0, 100, 2);
ect…
Then I could get really fancy and make it a loop
tweenthis(object1_mc, _x, 0, 100, 2);
for(i=1;i<=45;i++){
tweenthis.onMotionFinished(tweenthis(eval("object" +i+"_mc"), _x, 0, 100, 2);
}
This would save reams of redundant code.
But it doesn't work : (
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|