If you want to access your FlashVars in your Cairngorm Commands, For example to load your ModelLocator at initialisation.
Solution
The aim is to make sure your FrontController is initialised after the creation of the Application. So that the FrontController can pass in a reference to the Application.application object to the Event that triggers the Command.
OR
Trigger your initialisation Event in the CreationComplete Event Handler in your Application Class, and pass the Application.application to your Event from there.
Detailed explanation
Hi Everyone,
I thought I would share this Trick with you...
Today I was trying to use a "Initialisation" Command to load up my ModelLocator with the variables passed in via the flashvars.
I found that if I tried to Access the Application.application object
from the Command directly it was null... I guess cos its not a UI
component (I read that some where)...
So here is how I got around it...
Normally in my Application Component, I have my FrontController implementation as
In my Constructor of my FrontController I wanted to dispatch an Event to load up the Application FlashVars...
However at the point it was running the Application.application was
null... I am sure someone at Adobe can fill in the details why...
So to get around it...
I made my FrontController (TextModerationController) as a public var,
and call the InitApp() on CreationComplete of the Application...
public var textModerationController : TextModerationController;
public function InitApp() : void
{
textModerationController = new TextModerationController();
}
So when my FrontController Implementation uses the
Application.application, it now has the correct value with the
parameters loaded, to pass to the Event which will trigger the command.
I hope this helps someone out there... I am working with Cairngorm 2.2 but I imagine this will work with any version of Cairngorm.
UPDATE: Thanks to gotjosh819i on the CairngormDocumentation group in Yahoo Groups for this Alternative Method.
In your Applcation MXML use the normal approach of defining your services