Flash animations in Flex ignoring their stop() actions?

Posted by on November 6, 2008

Remember that issue I had with getting Flash and Flex to play nice and give me events from Flash swfs loaded into a Flex application? Well, it’s the same project, same files, and with a new wrinkle.

So we have the near final files from the client’s agency, and they look good, and perform all the interactions that are needed for the launch in a few weeks. Great! Only one problem. The animations never stop, flash on and off, and do all sorts of other things that are strange.

All of it though, is explained by there being no stop() actions in the Flash swf. To remind you, our gentle reader, both Flash and Flex are published in AS3 for Flash Player 9. I had the foresight to request the original FLA files, so even though I don’t have the fonts available, I can still look at the code, and tweak it to see if any changes I suggest to the agency will actually work. The stop() actions are there! What the frell?

So I do some searching, and searching, and searching. Nothing. I did find out that the default frame rate for Flex movies is 24 fps. So taking that, I thought that the frame rates might not be syncing, since the Flash swfs are set at 30 fps. So I change the setting in the Flash swfs down to 24 fps. Nothing, same errors with things spinning, and button states flashing.

Then I noticed that when I rolled over the buttons, that they stopped flashing, even when I was no longer interacting with them. It was like they caught the stop() that was on their timeline. So after a bit of tinkering I found out this. In our Flex application, when these swfs were loaded, if the loaded swfs had Tweens that tweened an animated movieClip, the animation would ignore the stop() actions in it’s clip.

To solve this, I found out that stop() actions needed to be added to every keyframe that the animation had, and it needed to target the movie that was animating. So if a sign was twirling around, it was, I had to add sign.stop(); to every keyframe where I wanted the sign to not move. I added this on the timeline that had the fade in tween of the sign movieClip.

I still don’t know why this happens, but adding the stop() actions that directly target the movie clip that needs to not move fixes it. If anyone has more insight into this, please let me know. I’m stumped as to why it is happening, and why this workaround is needed.

NOTE: I created a test Flex application, with nothing but a swfLoader to see if I could give that to the agency for testing purposes. In that, the animation behaved 100% correctly. So it’s not all Flex applications, just the one I am working on.