PDA

View Full Version : Tween.isPlaying


Jessy_UV
11-16-2007, 08:06 PM
Using Tween.isPlaying gives errors unless the tween already exists. If you only want something else to be happening while the tween is not playing, and don't want the tween to play at the beginning of the overall animation, how could Tween.isPlaying be useful in an if statement?

stompwampa
11-16-2007, 09:52 PM
of course it gives you errors if the tween doesn't exist...you can't ask flash to look for something that doesn't exist....
I'm not sure what you're asking...

Jessy_UV
11-16-2007, 10:58 PM
When you create a new Tween, it calls the Tween into action. Creating a Tween variable type is not enough to use isPlaying without getting errors, apparently.

http://www.actionscript.org/forums/showthread.php3?t=148812

stompwampa
11-17-2007, 11:45 PM
create your tween inside of a funtion and then call the function when you want the tween to play.

Jessy_UV
11-17-2007, 11:55 PM
I've already done that. Upon a click on the movieclip, one of two Tweens plays. While the tween is happening, I don't want a click to trigger a further tween, however. As such, I think using "if (!Tween.isPlaying) { (function that makes the tween happen) }" ought to work great. But it does not, because the Tween is not in existence until it is created within the function (even if the variable that stores the Tween is created outside of the tweening function).

stompwampa
11-18-2007, 01:09 AM
ok, I get it...try this:




var myTween:Tween;

function tweenStart():void
{
myTween = new Tween(/*tween properties here*/);
}

myButton.addEventListener(MouseEvent.CLICK, onClick);

function onClick(event:MouseEvent):void
{
tweenStart();
myButton.removeEventListener(MouseEvent.CLICK, onClick);
}

myTween.addEventListener(TweenEvent.MOTION_FINISH, tweenFinish);

function tweenFinish(event:TweenEvent):void
{
myButton.addEventListner(MouseEvent.CLICK, onClick);
}


You'll have to change it for your instance names and what not, but basically, your just telling Flash to not listen for anymore clicks until the tween finishes playing, and then when the tween is done, it tells flash to listen for mouse clicks again.

Jessy_UV
11-18-2007, 06:35 PM
I figured that listening for TweenEvent.MOTION_FINISH was the route I was going to have to take, and with a bit of tweaking to fit into my project, your code worked great. Thanks a bunch! :cool:

However, I don't really see how the isPlaying property could be useful. I can't get it to trace as false when the Tween has completed.

stompwampa
11-18-2007, 06:36 PM
Glad to help :-)

I've never had to use isPlaying for anything...I've never really found it that useful since MOTION_START and MOTION_FINISH event listeners can do the same thing...