Welcome!

Adobe Flex Authors: Liz McMillan, RealWire News Distribution, Maureen O'Gara, Yakov Fain, Keith Swenson

Related Topics: Adobe Flex

Adobe Flex: Article

Integrating a Flash Interface into Flex 2

A proof of concept

Worse, states have the nice feature of removing children from the DisplayList that aren't being drawn in the current state. My guess is, Flash Player uses this as an opportunity to run Garbage Collection on the not-being-drawn-assets. Remember, the unofficial ways the Flash Player 8 garbage collector works is a) every 60 seconds and/or b) when RAM usages increase by 20% or more. In the case of 60 PNGs , each utilizing a meg of RAM (compressed!), that's a ton of memory usage. Naturally, as soon as that animation is removed from the DisplayList, it's a prime candidate for collection. Meaning, the PNGs are no longer in RAM. When the animation is played again, it's slow because the frames have to be loaded into memory yet again. That's my theory too.

For the preload, my fix was pretty simple. You basically make a frame called "asset preload", and throw everything that animation needs on that frame. You can even put it at the front of the animation, in a graphic, alpha'd to 0. This forces Flash Player to throw all the assets in RAM. Since Flash Player is generally good at not running Garbage Collection while animations are going, you can usually be sure your animation will then run well. It did in my tests, anyway. This does not work if your computer itself is running low on RAM. For example, I ran a bunch of these examples at once, and my computers GC + Flash's I guess were running at the same time, because it would freeze during the animations.

I'm not sure what to do - in Flash, this was easy: you just made a MovieClip's visible property false. It's still there, just not being shown, but as soon as you make visible true, it draws immediately. It is being drawn, though, and taking up system resources. The DisplayList does the same thing with remove child. You can actually have an animation playing, but not in the DisplayList , taking up resources. It's better than visible = false, that's for sure. Either way, my guess is, visible = false is a better safeguard against Garbage Collection unloading your preloaded animation from memory vs. removing it from the DisplayList altogether. This is easy in Flash, hard in Flex if you are using states.

Sound compression is frustrating too. In Flash, there is a multitude of ways to compress it with more codecs. In Flex, it's a little harder. If you are sharing a lot of assets, you may run across the same sound sounding different because Flex compressed it differently. Really annoying. Or, you forgot to re-comment-in your code that you commented out to compile an ebmedded SoundAsset in Flash... thus you never compiled your sound into the SWF. How's your brain's cookie trail?

Resource usage is the biggest kicker. Eclipse 3.1 on my PC came, get this, standard with a max of 40 megs in the Eclipse ini. That's right, 40 megs! Ah, to be a full-time Java developer, and need only that much. When dealing with multimedia content, we Flashdevs need all the RAM we can get, and then some. Especially since Flex Builder can actually render some of those SWFs in real-time in Design View. It actually got so bad at one point, I couldn't even compile: Java 1.5 would collapse on my Windows XP page file faster than Mike Foley, the guy who lives in a trailer down by the river, does on your coffee table. I closed every program to no avail. For the record, I didn't have this problem on my Intel MacBook using the standalone install of Flex Builder. In fact, I gave up looking for the Eclipse.ini on the Flex Builder install (non-plugin) because the performance was acceptable.

That's the worst of the minefield.

The rest really have to do with the new ways Mouse, Keyboard, and focus events mesh with the updated and now built-in EventDispatcher. It's also key to make sure you know exactly how things are working in ActionScript 3. For example, when listening for MouseEvent.CLICK events from your Flash created button, you'll get two. This is normal. By default, it sends one, as does your UIComponent. Since MouseEvent click events bubble, they'll get to whoever's listening. You should intercept it in your UIComponent wrapper, call stopPropagation on the event, create a new event, and dispatch something more meaningful.

Application Example
Flash Design in Flex Application Proof of Concept: www.jessewarden.com/flex/flash_flex/source/

Code Walkthrough
Here is a video tutorial walking through the code. In it, you'll see animations created in Flash and then used in Flex in a variety of ways. I've also implemented someCairngorm 2 action with real dynamic data to showcase this isn't just a proof of concept with no substance.
Code Walkthrough Video Tutorial: www.jessewarden.com/flex/flash_flex/captivate/

Source Code
Please note: I cannot give you access to FLAs and fonts because I legally don't own the design. The video tutorial should show you enough about how they are made. The actual code that made them I did include, as well as theSWFs. Therefore, you CAN compile this in Flex using the provided SWFs.

If you want the design, you can purchase it at Templatemonster.com, direct link to the design here: www.templatemonster.com/flash-templates/5393.html.

Source Code to Flash Design in Flex App Example - View Source:
www.jessewarden.com/flex/flash_flex/source/srcview/ |
ZIP: www.jessewarden.com/flex/flash_flex/source/srcview/JXLDownloadsv3.zip.

More Stories By Jesse Randall Warden

Jesse R. Warden, a member of the Editorial Board of Web Developer's & Designer's Journal, is a Flex, Flash and Flash Lite consultant for Universal Mind. A professional multimedia developer, he maintains a Website at jessewarden.com where he writes about technical topics that relate to Flash and Flex.

Comments (1) View Comments

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


Most Recent Comments
Peter Beckwith 03/15/07 12:02:08 PM EDT

< in compiling when out code specific sound that comment to have you preloading, without via control can so your tag Embed the use if So, example. for mx.core.BitmapAsset and mx.core.SoundAsset not does currently alpha 9 Flash Flex. assets embed are interop with encounter you?ll problems only classes 3 ActionScript same share You future. solution viable a is thus coming? ?is since fourth about said be much there said, That flow. work production of part major software want don?t typically yet, released isn?t 9) (Flash Blaze Fourth,>

???????????????????????????

want to explain why it reads like a korean spam e-mail?