I started this blog in part to help me document my learnings and although Flash is an “old” technology as far as interactive technologies go I still find out more and more about it. Flash has many quirks… more specifically AS3 has many quirks. But that can be said about a lot of languages. Anyway, I learned a couple of things about Flash lately that I hadn’t realized or really distilled until now…
1. TLF TextFields
Working with TLF TextFields is cumbersome and can be confusing, as are working with and embedding the fonts you need to make TLF TextFields useful. But it does the job.
Related ‘stupid’ bug encounter & corresponding solution: If you find that the font that you’ve selected and embedded into your TLF Text Field is still not displaying the way you think, take a look at the number of glyphs that are available for that font in the language that you need. I was working with Hebrew font and realized that my font had only 17 out of the 400+ glyphs in Hebrew. You may not need all the glyphs but I found that if I at least have 100 of them, I’m good.
2. Properly Removing a Loaded SWF (and ensuring sounds stop)
When loading in external swfs, removing them from the current swf only removes them from the display list. A side effect to that is that your sounds will continue to play.
A couple of things to remember when you want to ‘unload’ or remove a loaded swf:
- remove the loaded swf from the stage via removeChild
- call loader.unloadandstop() on your loader; this will do the following to the loaded swf
- Sounds are stopped.
- Stage event listeners are removed.
- Event listeners for
- Timers are stopped.
- Camera and Microphone instances are detached
- Movie clips are stopped.
- call SoundMixer.stopAll() in your main swf to make sure that any sounds that were playing right before you unloaded your swf are stopped. This happened to me when my loaded swf started playing a video with sound. When I unloaded my swf, it is removed from the display list and I’ve called unloadandstop but the sound object keeps playing. This will ensure your sound is stopped. The drawback is that if you have any ambient sound in your main swf, those will stop too.
As a precaution I like to set my loader to null after all this to make sure that all of that data is marked for garbage collection.
I have to credit this post for helping me figure this out: http://stackoverflow.com/questions/5013942/unloading-swf-using-the-unloadandstop-method-but-video-sounds-remain-audible
And this post for confirming my assumptions: http://www.dremsus.com/index.php/2010/05/upload_and_unloadstop/
I hope my findings helps some of you who are still working with Flash!