View comments | RSS feed

Tween.onMotionFinished

Availability

Flash Player 6 (6.0.79.0).

Edition

Flash MX 2004.

Usage

tweenInstance.onMotionFinished = function() {
    // ...
};

Description

Event handler; invoked when the animation reaches the end of its duration. Handling this event allows your code to react at the point at which the tweened animation is finished.

Example

In the following example, a tween is applied to the img1_mc movie clip. When the tween reaches the end of its animation, it invokes the onMotionFinished event handler which calls the Tween.yoyo()method. The tween is therefore able to complete its animation before the Tween.yoyo() method is called to reverse the animation. A movie clip instance named img1_mc is required on the Stage for this example:

import mx.transitions.Tween;
var myTween:Tween = new Tween(img1_mc, "_x", mx.transitions.easing.Elastic.easeOut,0, Stage.width-img1_mc._width, 3, true);
myTween.FPS = 30;
myTween.onMotionFinished = function() {
    myTween.yoyo();
};

Version 8

Comments


Fumio Nonaka said on Sep 23, 2005 at 6:09 PM :
In the Tween class in Flash MX 2004 the onMotionFinished is not
declared as an instance property. Therefore the sample script should
yield an compile error. To avoid this error (1) the Tween instance should
be typed as Object, or (2) the onMotionFinished event handler method
should be set with the bracket ([]) access instead of with the dot (.)
access.

(1) var myTween:Object = new Tween (arguments);
(2) myTween["onMotionFinished"] = function () {statement(s)}
!lja said on Sep 28, 2005 at 5:18 AM :
After the execution of onMotionFinished, how can I determine which MovieClip had been tweened?

Is there a method available of the Tween object that retreives this information?
peterd_mm said on Sep 28, 2005 at 10:36 AM :
!lja,

try the following code:
myTween.onMotionFinished = function() {
myTween.yoyo();
trace(myTween.obj); // _level0.img1_mc
};

HTH,
_peter
ben_marker said on Sep 30, 2005 at 7:08 AM :
If you set a stop action to the tween(in my case a rollOver), does this trigger the onMotionFinished event? Does it assume it is "finished"? Or does it have to reach the final destination assigned when you init the class? It is triggering the onMotionFinished when I assign a stop action to the Tween for some reason. Or is it supposed to work like this?
noname.i.said said on May 15, 2006 at 2:32 AM :
ben_marker : since you have a Tween.onMotionStopped event handler, i suppose you that it is triggered when you stop the anim, and Tween.onMotionFinished is called when the anim "reaches its end" (as written)

!lja : personnaly i've subclassed the Tween class to track the target object of the tween and also keep back a reference to an object that handle event.

import mx.transitions.Tween;

class ControlledTween extends Tween {
private var controller:Object;
private var target:Object;

public function ControlledTween(obj:Object,
prop:String,
func:Function,
begin:Number,
finish:Number,
duration:Number,
useSeconds:Boolean,
useController:Object) {
super(obj, prop, func, begin, finish, duration, useSeconds, useController);
controller = useController;
target = obj;
}
}

You can then access in the event handlers to the tweened object via the target member, and to an abitrary object via the controller member. (i use it when i try to follow MVC for the flash application, with code separation)
rmarchione said on Apr 28, 2007 at 3:45 PM :
I want to play these transitions in sequence. This code doesn't work:
import mx.transitions.*;
import mx.transitions.easing.*;
var moonTween:Object = new Tween(mx.transitions.TransitionManager.start(mcMoon, {type:mx.transitions.Wipe, direction:0, duration:2, easing:mx.transitions.easing.Bounce.easeOut, param1:empty, param2:empty}));
var squareTween = new Tween(mx.transitions.TransitionManager.start(mcSquare, {type:mx.transitions.Blinds, direction:0, duration:2, easing:mx.transitions.easing.Bounce.easeOut, param1:empty, param2:empty}));
var oddTween = new Tween(mx.transitions.TransitionManager.start(mcOdd, {type:mx.transitions.Iris, direction:0, duration:1, easing:mx.transitions.easing.Bounce.easeOut, param1:empty, param2:empty}));

// alas this doesn't work
moonTween["onMotionFinished"] = function(){
squareTween();
}
Any idea how to make this work?

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flash/8/main/00004155.html