我在加载 SWF 并通过 Adobe AIR 2.6 for Android 中的类链接访问它们的元素时遇到问题。请帮忙,如果有人知道。
问题:
我有两个不同的 .swf 文件:
file1.swf(其中名称为 1 的 MovieClip 具有类链接“mainScreen”)
file2.swf(其中名称为 2 的 MovieClip 具有类链接“mainScreen”)
他们有一些动作脚本代码,我需要在我的应用程序域中导入这些代码。
文件下载很棒。
下载后它们位于不同的应用程序域
但是当我通过类链接获取元素并将它们添加到阶段时 - 仅显示第二个加载的元素。看起来第二个具有相同类链接的影片剪辑取代了第一个。
为此,我正在使用这种方法:
请帮助我如何加载两个不同元素的 SWF 文件,它们具有具有相同类链接的元素,或者解释为什么我不能这样做?当元素具有不同的类链接时 - 一切正常。但!!!它适用于网络,但对于空气它不想工作。
package
{
import flash.display.*;
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.errors.*;
import flash.events.*;
import flash.net.*;
import flash.system.ApplicationDomain;
import flash.system.LoaderContext;
import flash.system.Security;
import flash.system.SecurityDomain;
import flash.utils.*;
import flash.utils.ByteArray;
import org.bytearray.explorer.SWFExplorer;
import org.bytearray.explorer.events.*;
public class LoadSWFTest extends Sprite
{
private static const LOADERS_COUNT:int = 2;
private var asset_loader1:Loader;
private var asset_loader2:Loader;
private var finishedLoaders:int;
private var urlLoader1:URLLoader;
private var urlLoader2:URLLoader;
private var finishedURLLoaders:int;
private var movAssets:MovieClip;
private var movReels:MovieClip;
private static const initAssetsStr:String = "http://dl.dropbox.com/u/11/name1.swf";
private static const reelsStr:String = "http://dl.dropbox.com/u/11/name2.swf";
public function LoadSWFTest()
{
super();
// support autoOrients
//stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.EXACT_FIT;
this.scaleX = 0.5;
this.scaleY = 0.5;
this.addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
}
private function onAddedToStage(event:Event):void
{
this.removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
//draw black background
with( graphics )
{
beginFill(0x0)
drawRect(0,0,stage.stageWidth,stage.stageHeight);
}
initURLLoaders();
}
private function initURLLoaders():void
{
finishedURLLoaders = 0;
trace("finishedLoaders: " + finishedURLLoaders);
//first loader
urlLoader1 = new URLLoader();
urlLoader1.dataFormat = URLLoaderDataFormat.BINARY;
urlLoader1.addEventListener(Event.COMPLETE, loadCompleteURLLoaders);
var url1:URLRequest = new URLRequest(initAssetsStr);
urlLoader1.load(url1);
//reels
urlLoader2 = new URLLoader();
urlLoader2.dataFormat = URLLoaderDataFormat.BINARY;
urlLoader2.addEventListener(Event.COMPLETE, loadCompleteURLLoaders);
var url2:URLRequest = new URLRequest(reelsStr);
urlLoader2.load(url2);
}
private function loadCompleteURLLoaders(event:Event):void
{
finishedURLLoaders += 1;
trace("loadCompleteURLLoaders. finishedURLLoaders: " + finishedURLLoaders);
if (finishedURLLoaders == LoadSWFTest.LOADERS_COUNT)
{
init();
}
}
//init
private function init():void
{
finishedLoaders = 0;
trace("finishedLoaders: " + finishedLoaders);
var context1:LoaderContext = new LoaderContext(true);
context1.checkPolicyFile = false;
context1.allowCodeImport = true;
context1.applicationDomain = ApplicationDomain.currentDomain;
var context2:LoaderContext = new LoaderContext(true);
context2.checkPolicyFile = false;
context2.allowCodeImport = true;
context2.applicationDomain = ApplicationDomain.currentDomain;
var arr1:ByteArray = urlLoader1.data as ByteArray;
var arr2:ByteArray = urlLoader2.data as ByteArray;
//first loader
asset_loader1 = new Loader();
asset_loader1.contentLoaderInfo.addEventListener(Event.COMPLETE, loadComplete);
asset_loader1.loadBytes(arr1, context1);
//reels
asset_loader2 = new Loader();
asset_loader2.contentLoaderInfo.addEventListener(Event.COMPLETE, loadComplete);
asset_loader2.loadBytes(arr2, context2);
}
private function loadComplete(event:Event):void
{
finishedLoaders += 1;
trace("loadComplete. finishedLoaders: " + finishedLoaders);
if (finishedLoaders == LoadSWFTest.LOADERS_COUNT)
{
downloadCompleted();
}
}
private function downloadCompleted():void
{
trace("downloadCompleted");
movAssets = getSkinAsset(asset_loader1, 'mainScreen1') as MovieClip;
movReels = getSkinAsset(asset_loader2, 'mainScreen2') as MovieClip;
addChild(movAssets);
setTimeout( showMovie, 5000 );
}
private function showMovie():void
{
addChild(movReels);
}
///////////////////////////////////////////////
public function hasAsset(asset_loader:Loader, assetName:String):Boolean
{
try
{
var assetClass:Class = asset_loader.contentLoaderInfo.applicationDomain.getDefinition(assetName) as Class;
return assetClass!=null;
}
catch(e:Error)
{
trace(e);
return false;
}
return false;
}
public function getSkinAsset(asset_loader:Loader, assetName:String):DisplayObject
{
try
{
trace("getSkinAsset: " + assetName);
var memoryHash:String;
try
{
FakeClass(asset_loader);
}
catch (e:Error)
{
memoryHash = String(e).replace(/.*([@|\$].*?) to .*$/gi, '$1');
}
trace("asset_loader: " + memoryHash);
try
{
FakeClass(asset_loader.contentLoaderInfo.applicationDomain);
}
catch (e:Error)
{
memoryHash = String(e).replace(/.*([@|\$].*?) to .*$/gi, '$1');
}
trace("app domain: " + memoryHash);
trace("Loader: " + asset_loader.contentLoaderInfo.url + " appDomain: " + asset_loader.contentLoaderInfo.applicationDomain);
var assetClass:Class = asset_loader.content.loaderInfo.applicationDomain.getDefinition(assetName) as Class;
var disObj:DisplayObject = new assetClass();
return disObj;
}
catch(e:Error)
{
throw new IllegalOperationError( 'getSkinAsset( '+assetName + ' ) - error msg: ' + e.message );
}
return null;
}
}
}
内部最终类 FakeClass { }