我正在尝试复制使用greensocks LoaderMax加载的swf,但我似乎无法
我正在使用以下代码:
private var _assetCache : Dictionary;
public function getAssetById(assetId:String):DisplayObject
{
var asset:DisplayObject;
if (!_assetCache[assetId])
{
_assetCache[assetId] = LoaderMax.getContent(assetId).rawContent;
}
asset = _assetCache[assetId];
// duplicate bitmap
if (asset is Bitmap)
{
var bmd:BitmapData = new BitmapData(asset.width, asset.height, true, 0);
return new Bitmap(bmd, "auto", true);
}
// otherwise return
return SpriteUtils.duplicateDisplayObject(asset);
//return asset; // if previous line is commented out, this works well but there will be only a single copy of the loaded swf, kinda negating the use of a cache
}
这是SpriteUtils.duplicateDisplayObject(资产)(取自this
static public function duplicateDisplayObject(target:DisplayObject, autoAdd:Boolean = false):DisplayObject
{
// create duplicate
var targetClass:Class = Object(target).constructor;
var duplicate:DisplayObject = new targetClass();
trace(duplicate, duplicate.height); // traces [MovieClip, 0]
// duplicate properties
duplicate.transform = target.transform;
duplicate.filters = target.filters;
duplicate.cacheAsBitmap = target.cacheAsBitmap;
duplicate.opaqueBackground = target.opaqueBackground;
if (target.scale9Grid)
{
var rect:Rectangle = target.scale9Grid;
// WAS Flash 9 bug where returned scale9Grid is 20x larger than assigned
// rect.x /= 20, rect.y /= 20, rect.width /= 20, rect.height /= 20;
duplicate.scale9Grid = rect;
}
// add to target parent's display list
// if autoAdd was provided as true
if (autoAdd && target.parent)
{
target.parent.addChild(duplicate);
}
return duplicate;
}
如果我只是从_assetCache(这是一个字典)返回资产而不复制它,它可以作为MovieClip工作和跟踪但是当我尝试复制它时,即使跟踪告诉我复制是一个movieclip。请注意,正在加载的剪辑是时间轴根
阶段的简单矢量图形提前致谢
奥比
答案 0 :(得分:1)
我认为简单地调用构造函数不会起作用。
尝试这样做(我已经假设某些先前的知识,因为你能够获得上面的rawContent):
1)在二进制模式下使用DataLoader加载数据....在LoaderMax的上下文中它将是:swfLoader = new LoaderMax({name:“swfLoader”,onProgress:swfProgressHandler,onChildComplete:swfLoaded,auditSize: false,maxConnections:2}); swfLoader.append(new DataLoader(url,{format:'binary'})); (重点是使用格式='二进制'的DataLoader)
2)完成后,将ByteArray存储到您的字典中。上面代码的第一部分基本上没有变化,尽管bytearray可能是内容而不是rawContent
3)每当您需要复制副本时,请在ByteArray上使用Loader.loadBytes()。即var ldr:Loader = new Loader(); ldr.contentLoaderInfo.addEventListener(Event.COMPLETE,swfReallyLoaded); ldr.loadBytes(_assetCache [由assetid]);
与所有加载一样,您可能需要设置LoaderContext,如果在AIR- allowLoadBytesCodeExecution = true中; allowCodeImport = true;