Adobe AIR application and Splash
October 21, 2010 | No Comment | Tags: Adobe AIR, Adobe FlexI am working on an AIR project, which I would explain it later, and I want to open a splash windows before opening main window. However, it seems easy but it is not bad to see my solution.
For this reason, we should have a component called SplashWindow that can be either MXML or AS class. When splash window open the main windows should not be visible and their content have not to be created. When splash close and remove then main application window should appear and create their children.
Have a deep looking on WindowedApplication attributes.
<?xml version="1.0" encoding="utf-8"?> <s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" creationComplete="init()" creationPolicy="none" visible="false"> ...
The attribute creationPolicy="none" says that content must be created manually by calling the createDeferredContent() method and visible="false" make the main window of application hidden unless it get true.
When WindowedApplication creation complete the init() function run. This function in start point of showing splash.
...
<fx:Script>
<![CDATA[
import flash.events.TimerEvent;
import flash.utils.Timer;
import spark.components.Window;
private splash:Window;
private function init() : void
{
splash = new SplashWindow();
splash.open();
var timer:Timer = new Timer(2000, 1);
timer.addEventListener(TimerEvent.TIMER, timerHandler);
timer.start();
}
private function timerHandler(event:TimerEvent) : void
{
var timer:Timer = event.target as Timer;
timer.removeEventListener(TimerEvent.TIMER, timerHandler);
timer = null;
splash.close();
splash = null;
this.createDeferredContent();
this.visible = true;
this.nativeWindow.activate();
}
]]>
</fx:Script>
...
First of all splash window open, then a timer to keep splash open start. When the timer dispatch TimerEvent.TIMER event, splash close and the main application start to create their children and get visible and active.
This is so simple. The only thing that we have to attend is this fact that the children of the main window should not create until splash is open and this is not possible unless using creationPolicy attribute.timerHandler