My friends and family are under attack in Ukraine.
Donate to protect them directly or help international organizations.
Donate to protect them directly or help international organizations.
Flex: working with MovieClips
June 16th, 2008
You do not do everything with Flex components, especially if you develop games or cool interfaces. You often need to load SWF files and use the MovieClips inside them. A previous article talks about Instantiating and displaying MovieClips from loaded SWF.
Here are a few considerations when loading MovieClips into Flex:
- If you embed a symbol, you will lose all timeline actions. Embed the whole SWF instead.
- If you have a stop on the first frame of a multi-frame MovieClip, it might never execute. Add the action on the second frame.
- When you say gotoAndStop (or gotoAndPlay), you cannot immediately reference the children on that frame. You have 3 choices:
- Use stage.invalidate() and listen to RENDER events
- Listen to ADDED events and check if the target of the event is the object that you need.
- Forget about frames and do like Flex intended: one symbol per MovieClip state (button states for example)
- If your MovieClip is 1-frame long, it will still loop indefinitely, consuming precious resources. Use stop() on the first frame.
- When you use the addChild method with the MovieClip, the clip will not be copied. It will be removed from its previous parent (firing the REMOVED_FROM_STAGE event) and then added to the new parent.
- You cannot duplicate a MovieClip. If you want to be able to create multiple instances, link these MovieClips in you SWFlibrary and instantiate as many as you want.
- A MovieClip cannot be added directly to Flex containers. Add it as a child of a SWFLoader or an Image and add that control.
- The Loader class is a DisplayObject but has trouble resizing itself. You can always grab the loader.content as a MovieClip and add it where you need it.
Previous: codeFest 2.1 Conclusion Next: Garbage collection with SWF loading