views:

190

answers:

5

hi

i have a code

var timeline:TimelineLite=new TimelineLite  ;
timeline.append(new TweenLite(MyClip,1,{y:367,ease:Expo.easeOut}));

I need the corresponding code in Action Script 3.

EDIT: How can i perform this animation with out using the GreenSock plugin functions? Here "TimelineLite" is a class, and "append" are the member functions so with out using this how can i made the animation.

A: 

The code you posted is as far as I can tell (without knowing the api for TweenLite) completely valid Actionscript 3.

grapefrukt
:) oops, please check the edit section of the Question. :)
coderex
+1  A: 

Yes, the code is valid ActionScript3. TimelineLite and TimelineMax are part of the GreenSock Tweening Engine. See here: TimelineLite – Sequence/Group Multiple Tweens, Control Them as a Whole.

bildschirmsport
+2  A: 

What the hell, you want it without a plugin?

MyClip.addEventListener(Event.ENTER_FRAME, onEnterFrame);

var time:Number = 0;
var deltaTime:Number = 1 / stage.frameRate;
var initY:Number = MyClip.y
var deltaY:Number = 367 - initY;
function onEnterFrame(event:Event):void
{
    time += deltaTime;

    if (t >= 1)
    {
        MyClip.removeEventListener(Event.ENTER_FRAME, onEnterFrame);
        MyClip.y = 367;
    }
    else
    {
        MyClip.y = deltaY * (-Math.pow(2, -10 * time) + 1) + initY;
    }
}

I think, though I haven't tested it.

Easing equation from robertpenner.com, though mighy be optimizable

Using the enter-frame may not be optimal, see my blog post on tickers for more information.

Really though, you ought to use a tweening library. They are built by clever people looking to squeeze every ounce of performance out of a performance heavy operation. You might consider looking at Grant Skinner's GTween too, as it has a less restrictive license than TweenLite/TweenMax.

alecmce
+1  A: 

You can't replicate this using the base AS3 functionality. Greensock's tweening library adds functionality in that it allows you to group many tweens into a single timeline so the tweens run sequentially. If you want to replicate this, you'd have to create Tweens for each item you want to tween and use the TweenEvent.MOTION_FINISHED event after each tween to start the next tween.

wmid
+1  A: 

EDIT: Updated the code so it creates a fake timeline. This code was based on alecmce answer. Just added the possibility of sequencing Tweens. Since your question is about how to replicate class members without a class, using dynamic actionscrip you can pseudo write a class inside a object, and giving you the same syntax when calling the functions. Rephrase: The only propose of doing this is to give you the same syntax. The same functionality can be achieved removing the timeline object.

example with 2 sequenced twens:

timeline.append( MyClip,  367);
timeline.append( MyClip2, 200 );

timeline.startAnimation();

(see updated code below)


my 10 minutes clumsy approach:

// updated code    
var timeline:Object = new Object();
timeline.memory = new Array();

timeline.append = function (tween_obj:MovieClip, toY:Number){ 
    this.memory.push ([tween_obj, toY]);
};

timeline.checkTimeline = function (){ 

    if (this.memory[0] != null) {
        this.TweenFeather(MovieClip(this.memory[0][0]));
    }
};

timeline.startAnimation = function () { 
    this.checkTimeline();
};

timeline.TweenFeather = function TweenFeather(_do:MovieClip):void 
{
    _do.addEventListener(Event.ENTER_FRAME, _onEnterFrame);

    var time:Number = 0;
    var deltaTime:Number = 1 / stage.frameRate;
    var initY:Number = _do.y;
    var deltaY:Number = this.memory[0][1] - initY;
    function _onEnterFrame(event:Event):void
    {
        time += deltaTime;

        if (time >= 1)
        {
            _do.removeEventListener(Event.ENTER_FRAME, _onEnterFrame);
            _do.y = timeline.memory[0][1];

            timeline.memory.shift();
            timeline.checkTimeline();
        }
        else
        {
            _do.y = deltaY * (-Math.pow(2, -10 * time) + 1) + initY;
        }
    }
}

timeline.append( MyClip,  367);
timeline.append( MyClip2, 200 );

timeline.startAnimation();

using dynamic actionscript you loose all the good things of as3, don't know how restrict you are about k's. G luck

dome
Why on earth would you do it this way? What's the advantage over my method? The untyped objects, anonymous functions, extra variables, extra method calls, all add weight to the application and slow it down. It looks like you took my approach, and made it slower?
alecmce
completly alecmce, I just took your code and did a pseudo timeline. thought that was obvious, since I did not change anything in your code name variable. But if you take some time reading the question you will find that there is a bit more than doing a tween. There is the need of a timeline. My clumsy code (as I said before) was just a sketch of how you could do that. Adding more functionality in startAnimation, you can easily have more control in the way each tween relation with the others. I'm I soo wrong?
dome