Endless cycle between 2 tween animations in Flex
I'm trying to cycle between 2 different tween actions in Flex. Here is what I'm trying so far:
In declarations:
<fx:Declarations>
<s:Animate id="goRight"
duration="3000" target="{nShape}" >
<s:SimpleMotionPath property="x" valueFrom="0" valueTo="400" />
</s:Animate>
</fx:Declarations>
Running the animation:
var animate:Boolean = true;
var isLeft:Boolean = true;
while (animate)
{
if (isLeft)
{
goRight.play(null);
while (goRight.isPlaying){};
}
else {
goRight.play(null, true); // play it backwards
while (goRight.isPlaying){};
}
isLeft = !isLeft;
}
The problem is that once I start the animation (by clicking a button), I get a timeout error saying the script has been running for longer than 15 seconds, with no tweening ever occurring. The animation works if I were simply animating it开发者_StackOverflow社区 once. Does anyone know how I can get this perpetual cycling of tweens working?
...You have 3 while loop that never breaks....
Flash is not threaded (yet) and it's an event based language. How about you use events to check the progress or figure when the animation is done (which should dispatch a complete event).
This isn't Java. This is a visual, threadless, asynchronous, frame based language.
The issue is here:
while (goRight.isPlaying){};
Once you call goRight.play(null);
, the while
statement above will simply loop indefinitely because goRight.isPlaying
is true.
If you want proof of this, add the following to your while
loop:
trace("I'm playing");
You need to get rid of the while
loops and use some other construct; perhaps event handlers? I'm not sure what the best practice is now... it's been a while since I've worked with tweens, but I know back in the day there used to be events that you could hook into for when the tween animation ends.
精彩评论