Moving children out of a loader object has a pitfall
A common practice to utilize content from a Loader is to cast the loader's content property to a DisplayObject (or anything that extends it) and then addChild that object to wherever you want to use the loaded content in the display list outside the context of the loader itself, which then allows you to reuse that loader object, shaving some overhead and assisting in garbage collection if you manage those children properly. The problem arises when you reuse that loader object. You may be inclined to call the loader.unload() method (which will reset the properties of the loader to a null state for next load, clearing the content property in the process). Normally not an issue
since you've already referenced the child content for use elswehere, so it lives on despite the loader resetting. The problem is that the unload method dispatches an Event.UNLOAD to that child even though you added a reference to it elsewhere (its still a child of the loader so it receives events). This means any content in that SWF that listens for the event will think it has been unloaded and perform any associated actions - not good, especially when designing a framework for use by other developers. To make matters worse, the Loader class overrides removeChild (among others) blocking the ability to bypass this Event.UNLOAD dispatch by removing the object from its parent by hand - you simply cant do it. A custom loader class may be in order to pull this one off.
Creating partial package SWC files
If you're a Flex developer, SWC's are nothing new to you. But for Flash dev's, SWC files are one of those 'yea I've seen those, but I don't totally understand how, what, or why I'm supposed to use them' things in Flash development. They're incredibly useful - if you know exactly how to use them. Especially in CS3 (CS4 made it a little less painless with the explicit abiliy to specify SWC files as internal or external libraries). Unfortunately, generating them can be even more confusing. there just isn't much documentation, and if you use the flex sdk and/or FlashDevelop, the compc.exe command line options are daunting.
Dispatching custom events between child SWFs in AS3
I've written about this before, but this time around I have an answer to this one. The issue goes a little something like this:
a parent SWF
a child SWF, dispatches a custom event
another child swf, nested in either the parent or the other child, listens for that custom event.
The error you'll receive is a type coercion error that looks like a mistake - can't convert [custom event name] to [custom event name]. So what gives? They're the same class, both SWF files have imported the event class correctly, yet they are colliding through the event dispatch. Well, it turns out it is a security violation due to the way in which the SWF was loaded. Change your loader context to new LoaderContext(false, ApplicationDomain.currentDomain) when loading in those child SWFs and suddenly they can talk to each other more openly than before and type checking correctly returns that all important 'true' - in other words, no coercion error. All of those imported classes match up - and you can even instantiate objects of a type defined in the other child SWF without importing it into your class. To get Flash to export it without referencing it though requires a SWC file for the SWF to reference the classes from (CS4 modified this process a bit with the ability to specify external libs, and Flex has had the same functionality for a while i believe). Colin Moock's Essential Actionscript has a chapter on doing just that, right at the end of the book. If you're interested in that process, he says it better than i ever could.
FYI - the fix mentioned in my previous post on the subject is still valid if you can't/don't want to change the application domain for the loader. Adding the reference to the document class of the top level parent SWF still rectifies the issue.
Fosfr .9 nightly builds available now on google code
I started releasing nightly builds of Fosfr .9 Beta, complete with Flash develop templates, to google code. The documentation is super thin right now but definitely check it out...especially if the phrase 'AS3 code injection' makes you raise a curious eyebrow. Check out the wiki and the downloads at:
Fosfr .9 beta update, iPhone Apps
Fosfr .9 is very much underway, and I'm happy to announce that implementations are now easier than ever, with a much less cluttered package structure coming along with it. Error handling has been integrated as well as audio, see the full change list in progress at:
In other news, 'QuickText', my first iPhone app store app, has been out for a few weeks, I'll add more detail on that soon.
Fosfr .8 nearing 300 downloads this month
Thanks to the recent article at infoq.com, Fosfr is starting to move around the web. In the past week and a half, downloads of the latest beta have shot through the roof ( for a project that was intnetionally below the radar for a while) and are now approaching 300. I'm glad to see that there are new hands on the codebase out there, and as always I want to make sure everyone is aware that this is a beta release and I am actively taking suggestions from users about what works, what doesnt, and what makes the most/least sense. I have a few code to-do's left on this project but the bulk of the work to be done is getting the quickstart guides out of the way. The more I know about what is confusing the better, so please let me know!
Thanks for taking the time to check out the framework, get in touch and let me know how it is working out for you.
Interview on Fosfr at infoq.com
I was recently interviewed by Moxie Zhang of infoq.com about Fosfr, have a read over at: infoq.com
For those of you reaching my blog from that article, Fosfr is available on google code by clicking the link in the sidebar or following this link: fosfr on googlecode
and documentation is available here: http://www.jeffdepascale.com/documentation/fosfr
All questions and comments are very welcome as this is still a work in progress, please feel free to contact me directly.
Tabulate – new open source project on google code
Tabulate is an AS3 tab management package that handles all the oddities of working with tabs - including moving between display objects and text fields as well as components, which typically results in unexpected tab movement. Makes closed looping of tab groups much simpler. Additionally, Tabulate allows you to override the standard focusRect - that yellow, ugly box that pops up when you tab in flash. Make it look like you want it to.
Lots of additional features planned here, including incorporation into Fosfr after the 1.0 release of that. Currently Tabulate is a 1.0 alpha with no docs since it is all likely to change.
Using addThis in flash as3 builds
This may exist elsewhere, it may not ( I couldn't find it), but here's a super simple static class for tying addThis functionality to your flash applications. This is a real basic release that is offered as-is. Currently it only has 5 static constants for the msot popular sites, obviously you can add to that list.
Fosfr .8 BETA released
Well, it doesn't have Prequel 1.1 since, well, I haven't finished it yet
Sorry! It is coming. In the meantime, I decided it was time to update the release to the substantially more stable .8 release I've been sitting on for two months. Documentation and example site will be updated to .8 within 24 hours.
EDIT - Documentation, sample files, and example site have all been released using .8 BETA.
Notable changes include (there were alot of additional small fixes in there too):
- loadSubSWF method now contains the parameter 'deepLink' as the second parameter. deeplink values throughout fosfr are now arrays, allowing for unlimited depth on deeplink foldering via swfaddress.
- new top level method 'setSubLink', to match up to handleSubLink. Shortcuts to swfaddresshandler.setaddress() method. similarly to handleSubLink, the paramter is an array representing the deeplink folder structure.
- SWFfAddressHandler model rebuilt, new methods detailed in documentation.
- Custom error and notification handling, with the ability to trap errors to the debug panel. Debug panel highlights errors in red.
- new property 'available' in both loader classes, specifies that the loader is available for use.
- new method in navigation, 'initialSubload()'. If autosubload is false, call this method instead of loadSubSWF to ensure any stray deeplinks from the intial load are processed through.
- JSONHandler bug fixed where the ...rest statement was improperly passing values as a single array instead of individual unique parameters.
- Changes to tracking package: new property, 'trackAllMethods', specifies whether all methods instantiated for tracking receive the tag specified in the 'track' method. If true, every method will fire for each tag. If false, only the default (the first) method specified will fire. Using specific methods can now be acheived using the second parameter of the 'track' method, 'forceMethod'. This is a string value from the new 'TrackingMethods' class in the tracking package, specifying the name of the method to fire. If trackAllMethods is true, specifying a name here will force only that method to be used.
- new flashvars parameter, 'checkDeeplink', gets around the '#' issue with SWFAddress links. Addresses can be written instead as 'http://www.domain.com/?deeplink=subpage/sublink' and it will be converted on load to: 'http://www.domain.com/#/subpage/sublink'for proper swfaddress formatting.
- Fixed numerous glitches in FosfrLiteSWF.
- SubSWF files are now not required and Main/Shell only implementations can now be created. Config files need not include the navigation node in this use case.
- Bug fix in SWFAddressHandler, addressed improper handling of 'showProjectInTitle' property.
- Bug fix in SWFAddressHandler addressing false dispatches of an empty array for sublinks when a deeplink is cached on load, subLinks is now defaulted to null at all times.
- Bug fix in SWFAddressHandler addressing unrequested dispatch of a change event when sub link is set via setSubLink().


