开发者

AS3 code equvalent of the greensock code?

i hav开发者_如何学编程e 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.


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.


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.


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.


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜