uɐʎɹ ррoʇ uɐʎɹ bio photo

uɐʎɹ ррoʇ uɐʎɹ

Hello. Is is me you're looking for?
robotic life signs.
makes noise, hears sounds, intafon.
affe auf deux roues.

Email Github Github Gist Last.fm Soundcloud Flickr

This is somewhat trivial though not entirely intuitive — passing flashvars from an embedded flash movie to a flash movie that the swf is loading. I was working on some code recently that accomplished this task using one solution that I have seen most often — by passing the flashvars as query string parameters. In other words:

SwfA.swf is embedded on the page and has the flash var “userName” with the value “Voytek”. SwfB.swf is loaded by SwfA.swf, and must utilize the userName variable. Often this will be accomplished by loading SwfB using the URL “SwfB.swf?userName=Voytek”. This works just fine for most cases. There are, however some cases where this can be problematic. For example, suppose the site this is to be deployed on is a high traffic site and a caching system is employed to cache the swf files. Depending on the caching server, it may be that files are cached according to their *full* URL, which means that if we now need to load the swf with the userName “Milgrim”, we have cached the file a second time referenced by the URL “SwfB.swf?userName=Milgrim”. Now deploy this on a site with hundreds of thousands of users, and you might as well not even cache the swf files at all.

Fortunately, it came to my attention that the loaded swf SwfB can access the flashVars just as easily as SwfA, it just so happens that that action of getting the flashVars needs to be made asynchronously. As long as the loaded swf SwfB has already been added to the stage, it can access the flashVars via “stage.loaderInfo.parameters” (rather than accessing the flashVars in the embedded SwfA using “root.loaderInfo.parameters”). In order for this to be possible however, SwfB must be loaded and added to the display list of the stage.

As you can see from the code above, SwfA just loads SwfB just like you would normally do. SwfB just listens for its own ADDED_TO_STAGE event and then grabs the flashVars from the stage’s loaderInfo. The only catch is that if the UI build or some other immediate process depends on the flashVars, then you need to make sure and wait for the ADDED_TO_STAGE event in order to proceed.