简体   繁体   中英

AIR Application

I have my AIR application ie 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 :

  1. My AIR application ( ie MyAIRApplication ) is not showing up, on completing the splash screen.
  2. My Splash Screen is getting shown on top left corner always

Can anyone please provide me with a solution ?

  1. 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 with trace (rewrite to Event.CLOSE if needed.)

  1. Windows aren't centered by default. Get screen size with Capabilities.screenResolutionX/Y , calculate x/y for centered window and call splash.move(x, y) .

It also might have something to do with you casting your splash var as type Window,

private var splash:Window;

But then instantiating it as a new Splash

private function showSplash():void {
                splash = new Splash();

They should both be either Window or Splash.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM