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

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

问题描述

我有一个现有的AIR应用程序,其主要内容是A​​pp.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.

这里的code为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应用程序加载的SWF和实例化所包含的在SWF在WindowedApplication子被写入其中的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.

我想这样做的原因是为了自动化方案,我必须承担,我没有源$ C ​​$ C的应用程序,我自动化,但我确实有机会获得公众的名字类和它们的公共方法暴露了自动化。我可以完全控制环境和不具备应付周围的任何约束,这样我就可以把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/

这就是所谓的开放时间从第2 ​​AIR应用程序AIR应用程序。

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

它说:

这需要双方有一件事是,你正试图启动应用程序设置为true的AIR配置文件,并在系统上安装的应用程序中的allowBrowserInvocation设置属性。

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 tells how to do this.

下面是Adobe的描述的错误。

Here is Adobe's description for the error.

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

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

这是计算结果为空可以没有属性的对象。可发生在某些意外(尽管有效)的情况下,这种错误。例如,请考虑以下code,它创建了一个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应用程序的加载和运行现有的AIR SWF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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