简体   繁体   English

Adobe AIR HTML启动画面

[英]Adobe AIR HTML Splash Screen

I have an Adobe AIR application built in HTML/JavaScript. 我有一个内置HTML / JavaScript的Adobe AIR应用程序。

The XML is as follows: XML如下:

<?xml version="1.0" encoding="UTF-8"?>
<application xmlns="http://ns.adobe.com/air/application/4.0">
    <id>examples.html.HelloWorld</id>
    <versionNumber>0.1</versionNumber>
    <filename>HelloWorld</filename>
    <initialWindow>
        <title>Hello World</title>
        <content>HelloWorld.html</content>
        <visible>false</visible>
        <minimizable>true</minimizable>
        <maximizable>false</maximizable>
        <resizable>false</resizable>
        <width>800</width>
        <height>600</height>
        <systemChrome>none</systemChrome>
        <transparent>true</transparent>
    </initialWindow>
</application>

What I want is to show a splash screen first and then show the main application window once all the files have loaded in etc. 我想要的是先显示一个初始屏幕,然后在所有文件加载完毕后显示主应用程序窗口。

One idea was to make the intialWindow in the XML file the actual web app but then hide it by default using visible false then add: 一种想法是使XML文件中的intialWindow成为实际的Web应用程序,但默认情况下使用visible false将其隐藏,然后添加:

$(document).ready(function(){

    // Create a new window that will become the splash screen
    var options = new air.NativeWindowInitOptions(); 
    options.systemChrome = air.NativeWindowSystemChrome.STANDARD; 
    options.transparent = false; 
    var newWindow = new air.NativeWindow(options);

// Add content to new window
var htmlView:HTMLLoader = new HTMLLoader(); 
htmlView.width = 300; 
htmlView.height = 500;  
newWindow.stage.align = "TL"; 
newWindow.stage.scaleMode = "noScale"; 
newWindow.stage.addChild( htmlView );
htmlView.load( new URLRequest('splash.html') );

    // Check for loading of app
    $(window).load(function(){

        // Hide splash
        window.nativeWindow.close();

        // Activate the initial Window
        window.nativeWindow.activate(); 

    }); 

});

The questions I have with this approach are: 我对这种方法的疑问是:

  1. How do I provide the content for the splash screen (I've added some code to create a window and load in a splash.html page, but it currently breaks as I believe the code is ActionScript rather than JavaScript) 如何为初始屏幕提供内容(我添加了一些代码来创建窗口并加载在splash.html页面中,但是由于我认为代码是ActionScript而不是JavaScript而目前无法使用)
  2. Close the new splash screen (how do I choose which window to close) 关闭新的启动屏幕(如何选择要关闭的窗口)
  3. Show the correct initial screen on load (how do I choose the correct window) 在加载时显示正确的初始屏幕(如何选择正确的窗口)

I've started with: 我开始于:

$(window).load(function () {

    loaded = true;

});

function appLoaded()
{
    if(loaded)
    {
        // Hide splash
        window.nativeWindow.close();


        // Activate the initial Window
        window.nativeWindow.activate();
    }
    else
    {
        appLoaded(); // keep checking until the loaded becomes true
    }
}

One issue with the above code, is that the appLoaded function could run hundreds of times. 上面的代码的一个问题是appLoaded函数可以运行数百次。 Any suggestions for fixing this? 对解决这个问题有什么建议吗? As I want to make sure that the splash ONLY hides once the app has loaded and the splash has appeared. 我想确保只有在应用程序加载并且启动画面出现后,启动画面才隐藏。

I did something similar but with another approach: 我做了类似的事情,但是有了另一种方法:

  • I didn't opened a second window for a splash screen but rather put the content of the splash screen in a div inside the index.html and put it before the actual content. 我没有为启动屏幕打开第二个窗口,而是将启动屏幕的内容放在index.html内的div中,并将其放在实际内容之前。
  • I set the initial width and height to splash screen measures. 我将初始宽度和高度设置为初始屏幕尺寸。
  • After the application has completely loaded I removed the splash screen div from the DOM and set width and height to application measures. 应用程序完全加载后,我从DOM中删除了初始屏幕div,并为应用程序设置了宽度和高度。

UPDATE : 更新

How do I provide the content for the splash screen (I've added some code to create a window and load in a splash.html page, but it currently breaks as I believe the code is ActionScript rather than JavaScript)? 如何为初始屏幕提供内容(我添加了一些代码来创建窗口并加载在splash.html页面中,但是由于我认为代码是ActionScript而不是JavaScript而目前无法使用)?

First: There is no ActionScript. 第一:没有ActionScript。 It's JavaScript but you have to use it in the right way. 它是JavaScript,但是您必须以正确的方式使用它。 You missed air. 你错过了空气。 which represents the library object for Air. 代表Air的库对象。

// Create a new window that will become the splash screen
var options = new air.NativeWindowInitOptions(); 
options.systemChrome = air.NativeWindowSystemChrome.STANDARD; 
options.transparent = false; 

// Add content to new window
var htmlLoader = air.HTMLLoader.createRootWindow(false, options, false);    
htmlLoader.window.nativeWindow.width = 300;
htmlLoader.window.nativeWindow.height = 500;
htmlLoader.window.nativeWindow.visible = true;
htmlLoader.load(new air.URLRequest('splash.html'));

Close the new splash screen (how do I choose which window to close)? 关闭新的启动屏幕(如何选择要关闭的窗口)?

// That is your splash screen
htmlLoader.window.nativeWindow.close();

Show the correct initial screen on load (how do I choose the correct window)? 在加载时显示正确的初始屏幕(如何选择正确的窗口)?

// This is your main window
window.nativeWindow.visible = true;

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

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