Clone Loaded Swf
To create a clone of a loaded swf:
/**
* clone a Loader by duplicating its loaded bytes; this can be performed only once
* the loader has completed loading, otherwise you'll run into problems!
*
* @param source The original loader, which remains unchanged
* @return A new Loader that is a clone of source
*/
function cloneLoader(source:Loader):Loader
{
var clone:Loader = new Loader();
clone.loadBytes(source.contentLoaderInfo.bytes);
return clone;
}
This post is as much a quick reminder for me as for everyone else, but it came up today and it’s the sort of thing I do rarely enough to forget exactly how. Since I try as far as humanly possible not to contain code and assets in the same swf (at least for big projects), this is useful because it avoids the need to do something like this:
/**
* clone a display object, only if it has an ActionScript linkage ID
* otherwise you'll end up with an empty display object of some
* description.
*
* @param source The source display object
* @return A new display object that is a clone of source
*/
function cloneClip(source:DisplayObject):DisplayObject
{
var classToCreate:Class = Object(source).constructor;
return new classToCreate();
}
which requires that the DisplayObject has an AS3 linkage ID, and therefore that code and assets are not separated.
-
Anonymous
-
http://blog.vizio360.co.uk simone
-
http://www.jacksondunstan.com/ Jackson Dunstan
-
http://www.jacksondunstan.com Jackson Dunstan
-
http://alecmce.com Anonymous
-
http://alecmce.com alec
-
Daniel
