I have my AIR application i.e MyAIRApplication ready. I am trying to make a splash screen for it.
Here’s my code so far ..
main.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml"
creationComplete="showSplash()"
visible="false"
layout="absolute"
showFlexChrome="false">
<mx:Script>
<![CDATA[
import components.Splash;
import mx.core.Window;
import mx.controls.Alert;
import mx.events.AIREvent;
private var splash:Window;
private var splashTimer:Timer;
private function showSplash():void {
splash = new Splash();
splash.systemChrome = "none";
splash.transparent = true;
splash.type = NativeWindowType.LIGHTWEIGHT;
splash.addEventListener(AIREvent.WINDOW_COMPLETE, boot);
splash.open();
}
private function boot(event:AIREvent):void {
splashTimer = new Timer(3000, 2);
splashTimer.addEventListener(TimerEvent.TIMER_COMPLETE, showApp);
splashTimer.start();
this.removeEventListener(AIREvent.WINDOW_COMPLETE, boot);
}
private function showApp(event:Event):void {
splash.close();
splash = null;
splashTimer.stop();
splashTimer.removeEventListener(TimerEvent.TIMER_COMPLETE, showApp);
splashTimer = null;
// My Application .. where I wrote all components
var mainWin:WindowedApplication = new MyAIRApplication();
mainWin.activate();
mainWin.visible = true;
}
]]>
</mx:Script>
</mx:WindowedApplication>
Splash.mxml :
<?xml version="1.0" encoding="utf-8"?>
<mx:Window xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="400" height="300"
showFlexChrome="false" >
<mx:Image x="0" y="0" width="600" height="400" source="@Embed('../images/splash-bg.png')" scaleContent="false"/>
</mx:Window>
But I am facing 2 problems :
- My AIR application ( i.e MyAIRApplication ) is not showing up, on completing the splash screen.
- My Splash Screen is getting shown on top left corner always
Can anyone please provide me with a solution ?
var mainWin:WindowedApplication = new MyAIRApplication();WindowedApplication isn’t created like this. You already have one when your app start, use it. Just make its contents hidden to be shown after the splash.
Also I’m not sure that closing splash window with
splash.close()will fire WINDOW_COMPLETE event, check this too withtrace(rewrite to Event.CLOSE if needed.)Capabilities.screenResolutionX/Y, calculate x/y for centered window and callsplash.move(x, y).