/// <summary> /// Initializes a new instance of a sprite by cloning another timeline. /// </summary> /// <param name="srcTimeline">The timeline to clone.</param> /// <param name="className">If the cloned timeline is a SWF, then /// you should pass in a class name here. The MainTimeline class /// will be renamed in here to this new name.</param> public Sprite(Timeline srcTimeline, SWF root, string className = null) { this._root = root; /* Layers are just objects that exist purely to be arranged in some * kind of order and be pointed at by more meaningful, other things. * To clone layers, we need to simply copy the list and map old * layer refs to our new ones. */ Dictionary <Layer, Layer> newLayers = new Dictionary <Layer, Layer>(srcTimeline.LayerCount); foreach (Layer l in srcTimeline.Layers) { Layer newLayer = new Layer(this); LayerList.Add(newLayer); newLayers.Add(l, newLayer); } FrameList = new List <Frame>((int)srcTimeline.FrameCount); foreach (Frame f in srcTimeline.Frames) { Frame newFrame = new Frame(); foreach (IDisplayListItem dli in f.DisplayList) { newFrame.AddTag(dli.Clone(newLayers[dli.Layer], false)); } FrameList.Add(newFrame); } if (srcTimeline is SWF) { SWF srcSWF = (SWF)srcTimeline; if (className != null) { if (srcSWF.Class != null) { srcSWF.RenameMainTimelineClass(className); } /* Else the class will be generated later */ } RemapFonts(srcSWF, root); if (className != null) { foreach (DoABC abc in srcSWF.Scripts) { root.MergeScript(abc); } } if (className == null) { /* It's tempting to use ClassByName("flash.display.MovieClip") but * remember that that class exists in the player, not the SWF. What * we need in this case is just the name of the class, not a reference * to the class itself. Because that's complicated, we assign a * dummy class and watch for it when we write the class out. */ this.Class = AdobeClass.CreateFlashDisplayMovieClip(root.FirstScript.Code); } else { this.Class = srcSWF.Class; } } }
/// <summary> /// Initializes a new instance of a sprite by cloning another timeline. /// </summary> /// <param name="srcTimeline">The timeline to clone.</param> /// <param name="className">If the cloned timeline is a SWF, then /// you should pass in a class name here. The MainTimeline class /// will be renamed in here to this new name.</param> public Sprite(Timeline srcTimeline, SWF root, string className = null) { this._root = root; /* Layers are just objects that exist purely to be arranged in some * kind of order and be pointed at by more meaningful, other things. * To clone layers, we need to simply copy the list and map old * layer refs to our new ones. */ Dictionary<Layer, Layer> newLayers = new Dictionary<Layer, Layer>(srcTimeline.LayerCount); foreach (Layer l in srcTimeline.Layers) { Layer newLayer = new Layer(this); LayerList.Add(newLayer); newLayers.Add(l, newLayer); } FrameList = new List<Frame>((int)srcTimeline.FrameCount); foreach (Frame f in srcTimeline.Frames) { Frame newFrame = new Frame(); foreach (IDisplayListItem dli in f.DisplayList) { newFrame.AddTag(dli.Clone(newLayers[dli.Layer], false)); } FrameList.Add(newFrame); } if (srcTimeline is SWF) { SWF srcSWF = (SWF)srcTimeline; if (className != null) { if (srcSWF.Class != null) { srcSWF.RenameMainTimelineClass(className); } /* Else the class will be generated later */ } RemapFonts(srcSWF, root); if (className != null) { foreach (DoABC abc in srcSWF.Scripts) { root.MergeScript(abc); } } if (className == null) { /* It's tempting to use ClassByName("flash.display.MovieClip") but * remember that that class exists in the player, not the SWF. What * we need in this case is just the name of the class, not a reference * to the class itself. Because that's complicated, we assign a * dummy class and watch for it when we write the class out. */ this.Class = AdobeClass.CreateFlashDisplayMovieClip(root.FirstScript.Code); } else { this.Class = srcSWF.Class; } } }