package { import flash.display.Loader; import flash.display.MovieClip; import flash.display.Stage; import flash.utils.ByteArray; import com.codeazur.as3swf.SWF; import com.codeazur.as3swf.SWFData; import com.codeazur.as3swf.tags.TagDefineShape; import com.codeazur.as3swf.tags.TagFileAttributes; import com.codeazur.as3swf.tags.TagPlaceObject; import com.codeazur.as3swf.data.SWFMatrix; import com.codeazur.as3swf.tags.TagShowFrame; import com.codeazur.as3swf.tags.TagEnd; public class CreateSWF extends MovieClip { protected static const SHAPE_CHARACTER_ID:uint = 1; public function CreateSWF() { // loaderInfo.bytes is a ByteArray containing the raw, // uncompressed SWF of the document class instance. // Parse the SWF this code is running in: var swf:SWF = new SWF(loaderInfo.bytes); // Get a shape tag var shape:TagDefineShape = swf.getCharacter(SHAPE_CHARACTER_ID) as TagDefineShape; // Create a new empty SWF var swfTemp:SWF = new SWF(); // The first tag must be a FileAttributes tag swfTemp.tags.push(new TagFileAttributes()); // The second tag is the shape swfTemp.tags.push(shape); // The third tag is a PlaceObject tag // This tells the Flash Player to actually place the shape on the display list var placeObject:TagPlaceObject = new TagPlaceObject(); placeObject.characterId = SHAPE_CHARACTER_ID; placeObject.depth = 1; placeObject.matrix = new SWFMatrix(); placeObject.hasCharacter = true; placeObject.hasMatrix = true; swfTemp.tags.push(placeObject); // The forth tag is a ShowFrame tag swfTemp.tags.push(new TagShowFrame()); // The last tag is the End tag swfTemp.tags.push(new TagEnd()); // Publish the generated SWF var ba:ByteArray = new ByteArray(); swfTemp.publish(ba); // Load the published SWF and add it to the display list: var loader:Loader = new Loader(); loader.x = 200; loader.loadBytes(ba); addChild(loader); } } }