AddCharacter() public method

Adds a character, e.g. a shape or an image to the SWF dictionary.
public AddCharacter ( string id, ICharacter c ) : void
id string A name to refer to this character in the dictionary.
c ICharacter The character to add.
return void
示例#1
0
        /// <summary>
        /// Create a MovieClip that can later be referenced by SWFs and instantiated.
        /// </summary>
        /// <param name="movieClipTag">A pointer to the movie clip node in the job XML</param>
        /// <param name="currentSwfTag">A pointer to the currently processing SWF node</param>
        /// <param name="swf">The SWF to add the movie clip to</param>
        private void CreateMovieClip(XPathNavigator movieClipTag, XPathNavigator currentSwfTag, SWF swf)
        {
            string type = movieClipTag.GetAttribute(XMLHelper.AttrType, string.Empty);
            string src = movieClipTag.GetAttribute(XMLHelper.AttrSrc, string.Empty);
            string className = movieClipTag.GetAttribute(XMLHelper.AttrClass, string.Empty);
            string swfTag = movieClipTag.GetAttribute(XMLHelper.AttrSwf, string.Empty);

            /*
             * ISSUE 59: The examples in unit tests all put instances in the same package, e.g.
             *  <instance blahblah class="com.swiffotron.Class1" />
             *  <instance blahblah class="com.swiffotron.Class2" />
             * both put them into com.swiffotron. These are moved from the IDE generated packages
             * myswf1_fla and myswf2_fla so if you think about it, moving them both to com.swiffotron
             * makes sense because they would both have been put into the same generated package
             * if you'd done it via the IDE. The problem comes if we move them into different packages.
             * I don't know what will happen, I just haven't tried it. I have a sneaking suspicion that
             * we'll run into problems in namespace sets and the bugs will be very hard
             * to track down. Some solutions:
             * - Insist on using the same package in classes
             * - make class just be a class name, and dictate the package automatically
             * - Resolve the namespace sets to include all relevant, foreign packages (hard)
             */

            bool fromOtherSwf = swfTag != null && swfTag != string.Empty;
            if (fromOtherSwf)
            {
                /* ISSUE 60: If swf attribute is present, find the swf. It should be loaded/generated. It should not be the current swf. */
                throw new SwiffotronException(
                        SwiffotronError.UnimplementedFeature,
                        this.Context,
                        "swf attribute is not supported in movieclip tags yet.");
            }

            switch (type)
            {
                case XMLHelper.ValSwf:
                    if (fromOtherSwf)
                    {
                        throw new SwiffotronException(
                                SwiffotronError.BadInputXML,
                                this.Context,
                                "The movieclip 'swf' attribute does not make sense when the type is set to 'swf'.");
                    }

                    if (!this.processedSWFs.ContainsKey(src))
                    {
                        throw new SwiffotronException(
                                SwiffotronError.Internal,
                                this.Context,
                                "Internal error. SWF tags were processed out of order (" + currentSwfTag.GetAttribute(XMLHelper.AttrID, string.Empty) + " requres " + src + ").");
                    }

                    if (className == string.Empty)
                    {
                        throw new SwiffotronException(
                                SwiffotronError.BadInputXML,
                                this.Context,
                                "An clip created from a SWF needs a class name to be defined.");
                    }

                    SWF importSwf = this.processedSWFs[src];

                    /* ISSUE 55: There's an issue comment up there next to the declaration of processedSWFs which is intended
                     * to cache the new Sprite() bit below. */
                    swf.AddCharacter(movieClipTag.GetAttribute(XMLHelper.AttrID, string.Empty), new Sprite(importSwf, swf, className));

                    /* ISSUE 61: The above new Sprite will merge the sprite's code into the SWF regardless of whether
                     * it's instantiated. This should be done based on the exportforscript flag, or if the sprite
                     * is instantiated. Mind you, there is an argument that says if you declare a movieclip and
                     * never use it, and don't mark if for export, then you should probably remove it. Perhaps
                     * a more elegant solution would be to verify this in the XML and give a warning that you're
                     * doing redundant things. */

                    break;

                case XMLHelper.ValExtern:
                    if (fromOtherSwf)
                    {
                        throw new SwiffotronException(
                                SwiffotronError.BadInputXML,
                                this.Context,
                                "The movieclip 'swf' attribute does not make sense when the type is set to 'extern'. Try declaring the external SWF in its own tag instead, and reference it by ID.");
                    }

                    if (className == string.Empty)
                    {
                        throw new SwiffotronException(
                                SwiffotronError.BadInputXML,
                                this.Context,
                                "An clip created from a SWF needs a class name to be defined.");
                    }

                    SWF forImport = this.SwfFromStore(src);
                    try
                    {
                        swf.AddCharacter(movieClipTag.GetAttribute(XMLHelper.AttrID, string.Empty), new Sprite(forImport, swf, className));
                    }
                    catch (SWFModellerException sme)
                    {
                        if (sme.Error == SWFModellerError.CodeMerge)
                        {
                            throw new SwiffotronException(SwiffotronError.BadInputXML, this.Context.Sentinel("ClassNameCollision"), "Possible class name collision.", sme);
                        }
                        else
                        {
                            throw;
                        }
                    }

                    break;

                default:
                    /* ISSUE 73 */
                    throw new SwiffotronException(
                            SwiffotronError.UnimplementedFeature,
                            this.Context,
                            "Bad instance type: " + type);
            }
        }