Here’s a little code snippet that allows you to access flashvar parameters inside a custom Flex preloader.
The custom preloader class extends Sprite and implements the IPreloaderDisplay class. Once the Sprite’s ‘root’ property becomes available, you can use the standard AS3 way of accessing flashvars, namely:
var flashvars:Object = root.loaderInfo.parameters; |
This code should be used once the ‘root’ property has been initialised – for example in the ‘initialize()’ method defined by the IPreloaderDisplay interface:
public function initialize():void { var flashvars:Object = root.loaderInfo.parameters; } |
Just for reference, compare the above approach with the standard Flex method of accessing flashvar parameters – which becomes possible once the main Application instance has been created:
var flashvars:Object = Application.application.parameters |
Tags: custom preloader, flashvars, Flex
