将外部SWF加载到AIR应用程序中

时间:2011-03-16 10:28:40

标签: flex air flash external jwplayer

我正在尝试使用 loadBytes 将外部SWF( JW Player )加载到我的AIR应用程序中。我正在使用以下代码:

import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.display.Sprite;
import flash.events.Event;
import flash.net.URLLoader;
import flash.net.URLLoaderDataFormat;
import flash.net.URLRequest;
import flash.system.ApplicationDomain;
import flash.system.LoaderContext;
import flash.utils.ByteArray;

public function Invoker()
{
trace("INIT");
var uldr : URLLoader = new URLLoader();
uldr.dataFormat = URLLoaderDataFormat.BINARY;
uldr.addEventListener(Event.COMPLETE, onBytesComplete);
uldr.load(new URLRequest("Resources/5.1.swf"));
}

private function onBytesComplete(e : Event) : void
{
trace("LOADED");
var bytes : ByteArray = (e.target as URLLoader).data;
var ldr : Loader = new Loader();
ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, onChildComplete);
var ldrC : LoaderContext = new LoaderContext();
ldrC.allowLoadBytesCodeExecution = true;
ldr.loadBytes(bytes, ldrC);

}

private function onChildComplete(e : Event):void
{
trace("COMPLETE");
var c1ad : ApplicationDomain = (e.target as LoaderInfo).applicationDomain;
var inad : ApplicationDomain = ApplicationDomain.currentDomain;
trace(c1ad);
trace(inad);
}

但是,当我把

uic.addChild(LDR); 要么 canv.addChild(ldr); (uic mx:UIComponent 且canv mx:Canvas ) 进入 onBytesComplete 函数,我收到以下错误:

SecurityError: Error #3207: Application-sandbox content cannot access this feature.
    at flash.system::Security$/allowDomain()
    at com.longtailvideo.jwplayer.media::YouTubeMediaProvider/initializeMediaProvider()
    at com.longtailvideo.jwplayer.model::Model/setMediaProvider()
    at com.longtailvideo.jwplayer.model::Model/setupMediaProviders()
    at com.longtailvideo.jwplayer.controller::PlayerSetup/setupMediaProviders()
    at com.longtailvideo.jwplayer.controller::TaskQueue/nextTask()
    at com.longtailvideo.jwplayer.controller::TaskQueue/success()
    at flash.events::EventDispatcher/dispatchEventFunction()
    at flash.events::EventDispatcher/dispatchEvent()
    at com.longtailvideo.jwplayer.view.skins::DefaultSkin/loadComplete()

主意?请帮助!

感谢您的建议!

1 个答案:

答案 0 :(得分:0)

知道了!

我更改了JW Player源类中的一些函数。

在函数 initializeMediaProvider()的 com / longtailvideo / jwplayer / media / YouTubeMediaProvider.as 中添加 Security.allowDomain(“*”); < /强>

在函数 setupMediaProviders() com / longtailvideo / jwplayer / model / Model.as 中注释了行: setMediaProvider('default',new MediaProvider('默认')); setMediaProvider('youtube',新的YouTubeMediaProvider());

我没有使用youtube,所以它运行正常!

希望这有帮助!