简体   繁体   English

AIR应用

[英]AIR Application

I have my AIR application ie MyAIRApplication ready. 我已经准备好AIR应用程序,即MyAIRApplication。 I am trying to make a splash screen for it. 我正在尝试为此创建一个初始屏幕。 Here's my code so far .. 到目前为止,这是我的代码。

main.mxml 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 : 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. 在完成启动屏幕时,我的AIR应用程序(即MyAIRApplication)没有显示。
  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. WindowedApplication不是这样创建的。 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.) 另外,我不确定用splash.close()关闭启动窗口splash.close()会触发WINDOW_COMPLETE事件,也请通过trace检查(如果需要,请重写为Event.CLOSE。)

  1. Windows aren't centered by default. Windows默认情况下不居中。 Get screen size with Capabilities.screenResolutionX/Y , calculate x/y for centered window and call splash.move(x, y) . 使用Capabilities.screenResolutionX/Y获取屏幕尺寸,为居中窗口计算x / y并调用splash.move(x, y)

It also might have something to do with you casting your splash var as type Window, 它也可能与您将初始var强制转换为Window类型有关,

private var splash:Window;

But then instantiating it as a new Splash 但随后将其实例化为新的Splash

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

They should both be either Window or Splash. 它们都应该是Window或Splash。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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