LookupInstance() public method

Finds a placed character on the stage by its instance name.
public LookupInstance ( string qname ) : PlaceObject
qname string The qualified name, which is a dotted path through /// nested instances to the instance you want, starting from the root /// timeline.
return PlaceObject
示例#1
0
        /// <summary>
        /// Executes a modify tag on a SWF
        /// </summary>
        /// <param name="modify">A navigator pointing to the modify element in the XML</param>
        /// <param name="swf">The SWF to modify</param>
        private void ModifyInstance(XPathNavigator modify, SWF swf)
        {
            string qname = modify.GetAttribute(XMLHelper.AttrQName, string.Empty);

            PlaceObject po = swf.LookupInstance(qname);

            /* ISSUE 63: There is a question of whether to error if the instance is not found. Some are
             * found with a pattern rather than a path, and you may not expect it to always find something. 
             * At the moment, we shall throw an exception, because it suits our development, unit testing
             * fail-fast strictness. */
            if (po == null)
            {
                throw new SwiffotronException(
                        SwiffotronError.BadPathOrID,
                        this.Context.Sentinel("ModifyInstance"),
                        @"Instance not found: " + qname);
            }

            Xml.MoveToFirstChildElement(modify);

            do
            {
                if (modify.NodeType == XPathNodeType.Element)
                {
                    switch (modify.LocalName)
                    {
                        case XMLHelper.TagMoveRel:
                            Matrix rel = Xml.TransformTagToMatrix(modify);
                            po.Matrix.Apply(rel);
                            break;

                        case XMLHelper.TagMoveAbs:
                            Matrix abs = Xml.TransformTagToMatrix(modify);
                            po.Matrix = abs;
                            break;

                        default:
                            /* ISSUE 73 */
                            throw new SwiffotronException(
                                    SwiffotronError.UnimplementedFeature,
                                    this.Context,
                                    @"Unsupported modification tag: " + modify.LocalName);
                    }
                }
            }
            while (modify.MoveToNext(XPathNodeType.Element));

            modify.MoveToParent();
        }
示例#2
0
        /// <summary>
        /// Finds a timeline from a qualified instance name.
        /// </summary>
        /// <param name="qname">The dotted qname path to the instance.</param>
        /// <param name="swf">The SWF to search.</param>
        /// <param name="uname">The unqualified name of the found instance is returned here.</param>
        /// <returns>The found timeline</returns>
        private Timeline QNameToTimeline(string qname, SWF swf, out string uname)
        {
            int lpos = qname == null ? -1 : qname.LastIndexOf('.');
            uname = qname;
            if (lpos == -1)
            {
                /* If this is just a simple instance name, return the stage. */
                return swf;
            }
            else
            {
                uname = qname.Substring(lpos + 1);
                string parentQname = qname.Substring(0, lpos);
                PlaceObject parentIns = swf.LookupInstance(parentQname);
                if (parentIns == null)
                {
                    throw new SwiffotronException(
                            SwiffotronError.BadPathOrID,
                            this.Context,
                            "Ancestor of '" + uname + "', i.e. '" + parentQname + "' does not exist.");
                }

                ICharacter parentChar = parentIns.Character;

                if (!(parentChar is Timeline))
                {
                    throw new SwiffotronException(
                            SwiffotronError.BadPathOrID,
                            this.Context,
                            "QName '" + parentQname + "' does not refer to a timeline.");
                }

                return (Timeline)parentChar;
            }
        }