Monday, November 3, 2008

Creating Dynamic Tween Variables In a Timed Sequence

Say you want to have a number of tweens perform in a sequence but you don't want to type out all the tweens. Here is how you do it using a timer to animate some menus one at a time with a delay of 50 milliseconds between each:
import fl.transitions.Tween;
import fl.transitions.easing.*;
import fl.transitions.TweenEvent;

var timerCounter:uint=0;
var theTimer:Timer=new Timer(50,6);/
theTimer.addEventListener(TimerEvent.TIMER, display);

function display(e:TimerEvent):void {
var thisLoopNode:Object=menu_mc.getChildByName("node"+timerCounter);
this["tweenx"+timerCounter]=new Tween(thisLoopNode,"x",Regular.easeOut,0,100,1,true);
this["tweeny"+timerCounter]=new Tween(thisLoopNode,"y",Regular.easeOut,0,timerCounter*10,1,true);
this["tweenalpha"+timerCounter]=new Tween(thisLoopNode,"alpha",Regular.easeOut,0,1,1,true);


ajitpal said...

hi that was great example, i was trying it in another way, but it is giving error. I don't know whether it correct or not..

var str:String="fl.transitions.Tween";
var obj=getDefinitionByName(str) as Class;
var dynamicObj=new obj();

it is giving error like this :-
ReferenceError: Error #1065: Variable Tween is not defined.
at global/flash.utils::getDefinitionByName()
at Untitled_fla::MainTimeline/frame1()

Peoples said...

You seem like you know lots about AS3.0 ...

I am trying to learn it but am finding that people horde the knowledge and are unwilling to share.

I am trying to make a webpage out of Flash and am trying to incorporate a Fade in / Out Tween that works when a page is clicked.

I got the fade in to work.

OKay guys,

I've got some very rudimentary AC3.0 skillz that I got from some online tutorials and have created this simple Ease Out Tween ....

[QUOTE]//obj_mc animate in
var objTween:Tween = new Tween(obj_mc, "alpha", Regular.easeOut, 0, 1, 1, true);[/QUOTE]

This obviously fades the selected movie clip INTO the stage.

The problem that I am having is that I am not skilled enough to figure out how to fade the movie clip OUT and where it goes ....

Does the fade out script go directly above or below the code I have created? Or does it go somewhere entirely different?

And is it as simple as replacing the easeOut with easeIn? - This, I know, is not the case because doing so produces nothing.

//obj_mc animate in
var objTween:Tween = new Tween(obj_mc, "alpha", Regular.easeOut, 0, 1, 3, true);

But I am unable to figure out the Fade OUT process .... can you please help me out?