加载和运行现有 AIR swf 的 AIR 应用程序 [英] AIR App that Loads and Runs Existing AIR swf

查看:30
本文介绍了加载和运行现有 AIR swf 的 AIR 应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个现有的 AIR 应用程序,其主要内容是 App.swf.我想要另一个托管和运行 App.swf 的 AIR 应用程序.当我说运行它时,我的意思是显示它是 WindowedApplication.

I have an existing AIR app whose main content is App.swf. I would like to have another AIR app that hosts and runs App.swf. When I say run it, I mean displays it's WindowedApplication.

以下是 2 个 AIR 项目的代码(为简洁起见,省略了导入):

Here's the code for the 2 AIR projects (imports are omitted for brevity):

// App AIR Project -> App.mxml -> App.swf (it's just a window)
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
<![CDATA[
public function doSomething():void {
    trace("doSomething called");
}
]]>
</mx:Script>
</mx:WindowedApplication>

// AirAppHostApplication AIR Project -> AirAppHostApplication.mxml -> AirAppHostApplication.swf
<?xml version="1.0" encoding="utf-8"?>
<custom:AirAppHostApplication xmlns:custom="components.*" />

// components/AirAppHostApplication.as
public class AirAppHostApplication extends WindowedApplication
{   
    private var ldr:Loader;

    public function AirAppHostApplication()
    {
        addEventListener (FlexEvent.CREATION_COMPLETE, handleComplete);
    }

    private function handleComplete( event : FlexEvent ) : void
    {
        loadSwf("App.swf");
    }

    private function loadSwf(swf:String):void {
        ldr = new Loader();
        var req:URLRequest = new URLRequest(swf);
        var ldrContext:LoaderContext = new LoaderContext(false, ApplicationDomain.currentDomain);
        ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler);
        ldr.load(req, ldrContext);
    }

    private function completeHandler(event:Event):void {
        var appSystemManagerCls:* = ApplicationDomain.currentDomain.getDefinition("_app_mx_managers_SystemManager") as Class;
        var appSystemManagerInstance:* = new appSystemManagerCls(Application.application);
        var appInstance:WindowedApplication = appSystemManagerInstance.create();
        appInstance.activate();
        appInstance.doSomething();
    }   
}

我在加载 App.swf 时收到以下错误:

I get the following error while App.swf is being loaded:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
    at mx.managers::SystemManager/initHandler()[C:\autobuild\galaga\frameworks\projects\framework\src\mx\managers\SystemManager.as:3001]

我认为问题与 AirAppHostApplication 的 SystemManager 与 App 的 SystemManager 冲突有关,因为它们都位于同一个应用程序域中.是否可以编写 AIR 应用程序,其中 WindowedApplication 类不是静态定义的,而是在运行时通过加载 swf 并实例化包含在 swf 中的 WindowedApplication 子类来加载的.

I believe the issue has to do with AirAppHostApplication's SystemManager conflicting with App's SystemManager because they are both living in the same app domain. Can an AIR app be written where a WindowedApplication class isn't statically defined, but loaded at runtime by loading a swf and instantiating the WindowedApplication subclass that's contained in the swf.

我想这样做的原因是在一个自动化场景中,我必须假设我没有我正在自动化的应用程序的源代码,但我确实可以访问公共类的名称及其为自动化公开的公共方法.我可以完全控制环境,无需处理任何相关限制,因此我可以将 2 个 AIR 应用程序放在同一目录中,等等.

The reason I want to do this is for an automation scenario where I have to assume I don't have the source code for the app I'm automating, but I do have access to the names of the public classes and their public methods exposed for automation. I have complete control over the environment and don't have to deal with any constraints around that, so I can put 2 AIR apps in the same directory, etc.

这可能吗?

推荐答案

是的,这是可能的.看看http://blog.everythingflex.com/2009/06/08/open-an-air-application-from-a-2nd-air-application/

Yes, this is possible. Take a look at http://blog.everythingflex.com/2009/06/08/open-an-air-application-from-a-2nd-air-application/

它被称为从第二个 AIR 应用程序打开一个 AIR 应用程序.

It is called Open an AIR application from a 2nd AIR application.

它说:

两者都需要的一件事是,您尝试启动的应用程序将 AIR 配置文件中的 allowBrowserInvocation 属性设置为 true,并且该应用程序安装在您的系统上.

one thing that is required by both is that the application you are attempting to launch has the allowBrowserInvocation property within the AIR configuration file set to true and the application installed on your system.

您还必须知道应用程序的 ID 和发布者的 ID.例如在我的 LauncherSample 中,AIR 配置文件中定义的应用程序 ID 是:

You must also know the application’s id and publisher’s id. For example within my LauncherSample, the application id defined in the AIR configuration file is:

plus 告诉如何做到这一点.

plus tells how to do this.

这是 Adob​​e 对错误的描述.

Here is Adobe's description for the error.

错误 1009 无法访问空对象引用的属性或方法.

Error 1009 Cannot access a property or method of a null object reference.

计算结果为 null 的对象可以没有属性.在某些意外(尽管有效)的情况下可能会发生此错误.例如,考虑以下创建 Sprite 对象的代码.由于此 Sprite 对象从未添加到显示列表(通过 DisplayObjectContainer 对象的 addChild() 方法),因此其 stage 属性设置为 null.因此,该示例会生成此错误,因为 Sprite 对象的 stage 属性不能具有任何属性:

An object that evaluates to null can have no properties. This error can occur in some unexpected (though valid) situations. For example, consider the following code, which creates a Sprite object. Because this Sprite object is never added to the display list (through the addChild() method of a DisplayObjectContainer object), its stage property is set to null. Thus, the example generates this error because Sprite object's stage property cannot have any properties:

import flash.display.Sprite;
var sprite1:Sprite = new Sprite();
var q:String = sprite1.stage.quality;

这篇关于加载和运行现有 AIR swf 的 AIR 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆