/// <summary> /// Read in the definitions for the code block. /// </summary> private void ReadScriptDefs() { uint scriptCount = this.abcdtr.ReadU30(); for (int i = 0; i < scriptCount; i++) { uint idx = this.abcdtr.ReadU30(); Method m = this.code.GetMethod((int)idx); Script s = new Script() { Method = m }; uint traitCount = this.abcdtr.ReadU30(); while (traitCount --> 0) { s.AddTrait(this.ReadTrait()); } this.code.AddScript(s); } }
/// <summary> /// Generates a main timeline script for a new SWF /// </summary> /// <param name="qClassName">Qualified class name for the MainTimeline class, /// e.g. mygeneratedswf_fla.MainTimeline</param> /// <returns>A DoABC tag that can be inserted into a new SWF, which may be the one /// from the timeline (And so may already be in the SWF).</returns> public static DoABC GenerateDefaultScript(string qClassName, Timeline timeline) { DoABC abc = timeline.Root.FirstScript; if (abc == null) { abc = new DoABC(true, string.Empty, null, null); abc.code = new AbcCode(); } AS3ClassDef classDef = GenerateTimelineClass(abc.code, qClassName, timeline.Root.Context); timeline.Class = classDef; Script s = new Script() { Method = GenerateTimelineScript(abc.code, classDef) }; abc.code.AddScript(s); s.AddTrait(new ClassTrait() { As3class = classDef, Kind = TraitKind.Class, Name = timeline.Class.Name }); return abc; }
/// <summary> /// Generates a script that binds a class to a clip. /// </summary> /// <param name="spr">The sprite to create the class for.</param> public void GenerateClipClassBindingScript(Sprite spr) { Namespace nsEmptyPackage = this.CreateNamespace(Namespace.NamespaceKind.Package, string.Empty); Namespace nsFlashEvents = this.CreateNamespace(Namespace.NamespaceKind.Package, "flash.events"); Namespace nsFlashDisplay = this.CreateNamespace(Namespace.NamespaceKind.Package, "flash.display"); Multiname mnObject = this.CreateMultiname(Multiname.MultinameKind.QName, "Object", nsEmptyPackage, null); Multiname mnEventDispatcher = this.CreateMultiname(Multiname.MultinameKind.QName, "EventDispatcher", nsFlashEvents, null); Multiname mnDisplayObject = this.CreateMultiname(Multiname.MultinameKind.QName, "DisplayObject", nsFlashDisplay, null); Multiname mnInteractiveObject = this.CreateMultiname(Multiname.MultinameKind.QName, "InteractiveObject", nsFlashDisplay, null); Multiname mnDisplayObjectContainer = this.CreateMultiname(Multiname.MultinameKind.QName, "DisplayObjectContainer", nsFlashDisplay, null); Multiname mnSprite = this.CreateMultiname(Multiname.MultinameKind.QName, "Sprite", nsFlashDisplay, null); Multiname mnMovieClip = this.CreateMultiname(Multiname.MultinameKind.QName, "MovieClip", nsFlashDisplay, null); Multiname sprQName = null; Multiname sprMultiname = null; if (spr.Class.Name.Kind == Multiname.MultinameKind.Multiname) { sprMultiname = spr.Class.Name; /* ISSUE 5: Convert a multiname to a QName of the form: * mn QName "MyClassName"; ns Package "com.mypackage"; set * */ throw new SWFModellerException( SWFModellerError.UnimplementedFeature, "Unsupported sprite class name kind in class binding script generation: " + spr.Class.Name.Kind.ToString()); } else if (spr.Class.Name.Kind == Multiname.MultinameKind.QName) { sprQName = spr.Class.Name; /* Convert to form: * mn Multiname "MyClassName"; ns *; set {ns Package "com.mypackage"} */ sprMultiname = this.CreateMultiname( Multiname.MultinameKind.Multiname, sprQName.Name, nsEmptyPackage, this.CreateNamespaceSet(new Namespace[] { sprQName.NS })); } else { /* ISSUE 73 */ throw new SWFModellerException( SWFModellerError.UnimplementedFeature, "Unsupported sprite class name kind in class binding script generation: " + spr.Class.Name.Kind.ToString()); } Method bindingMethod = this.CreateMethod(spr.Class.Name.Name + "BindingScript.abc", 2, 1, 1, 9, /* The above magic numbers come from the numbers generated by IDE versions of this function. * I have no real ideal about how I'd work them out for myself, which would obviously be * more ideal. */ /* Line */ /* 1 */ this.Op(Opcode.Mnemonics.GetLocal0), /* 2 */ this.Op(Opcode.Mnemonics.PushScope), /* 3 */ this.Op(Opcode.Mnemonics.FindPropStrict, sprMultiname), /* 4 */ this.Op(Opcode.Mnemonics.GetLex, mnObject), /* 5 */ this.Op(Opcode.Mnemonics.PushScope), /* 6 */ this.Op(Opcode.Mnemonics.GetLex, mnEventDispatcher), /* 7 */ this.Op(Opcode.Mnemonics.PushScope), /* 8 */ this.Op(Opcode.Mnemonics.GetLex, mnDisplayObject), /* 9 */ this.Op(Opcode.Mnemonics.PushScope), /* 10 */ this.Op(Opcode.Mnemonics.GetLex, mnInteractiveObject), /* 11 */ this.Op(Opcode.Mnemonics.PushScope), /* 12 */ this.Op(Opcode.Mnemonics.GetLex, mnDisplayObjectContainer), /* 13 */ this.Op(Opcode.Mnemonics.PushScope), /* 14 */ this.Op(Opcode.Mnemonics.GetLex, mnSprite), /* 15 */ this.Op(Opcode.Mnemonics.PushScope), /* 16 */ this.Op(Opcode.Mnemonics.GetLex, mnMovieClip), /* 17 */ this.Op(Opcode.Mnemonics.PushScope), /* 18 */ this.Op(Opcode.Mnemonics.GetLex, mnMovieClip), /* 19 */ this.Op(Opcode.Mnemonics.NewClass, spr.Class), /* 20 */ this.Op(Opcode.Mnemonics.PopScope), /* 21 */ this.Op(Opcode.Mnemonics.PopScope), /* 22 */ this.Op(Opcode.Mnemonics.PopScope), /* 23 */ this.Op(Opcode.Mnemonics.PopScope), /* 24 */ this.Op(Opcode.Mnemonics.PopScope), /* 25 */ this.Op(Opcode.Mnemonics.PopScope), /* 26 */ this.Op(Opcode.Mnemonics.PopScope), /* 27 */ this.Op(Opcode.Mnemonics.InitProperty, sprQName), /* 28 */ this.Op(Opcode.Mnemonics.ReturnVoid)); Trait classTrait = new ClassTrait() { As3class = (AS3ClassDef)spr.Class, Kind = TraitKind.Class, Name = sprQName }; bindingMethod.AddTrait(classTrait); Script bindScript = new Script() { Method = bindingMethod, }; bindScript.AddTrait(classTrait); this.scripts.Insert(0, bindScript); /* Insert at the start to make sure any timeline script is last. */ }