0
votes

i've just started actionscript-ing and I encountered problems about tween... Basically, i want my object to fade out in 5 seconds...

here's my code :

import flash.display.Sprite;
import fl.transitions.Tween;
import fl.transitions.easing.*;
import fl.transitions.TweenEvent;
import flash.text.TextField;
import flash.events.MouseEvent;

var object:Sprite = new Sprite();
object.graphics.beginFill(0xff00ff);
object.graphics.drawRoundRect(200, 200, 100, 75, 10, 10);

var button:TextField = new TextField();
button.x = 10;
button.y = 10;
button.width = 125;
button.height = 25;
button.text = "Click here to Animate";
button.border = true;

addChild (button);
addChild (object);

button.addEventListener(MouseEvent.CLICK, animate);

function animate (e : MouseEvent)
{
    var myTween:Tween = new Tween(object, "alpha", None.easeIn, 1, 0, 5, true);
}

When i started the movie clip and clicked the textfield, it somehow won't animate... can anyone point out the mistake??? THX b4...

1

1 Answers

0
votes

It is running the tween, you just can't see it. In your animate function change:

var myTween:Tween = new Tween(object, "alpha", None.easeIn, 1, 0, 5, true);

to

var myTween:Tween = new Tween(object, "alpha", None.easeIn, 0, 1, 5, true);

And you can see it fires just fine.

Edit

As far as making it fade out in 5 seconds it seems to work fine in my tests with your original code, just make sure not to click it again within the 5 seconds or it will reset the tween. Depending on what you are using it for, within your function you can set button.mouseEnabled = false; to prevent additional clicks.