7 Replies Latest reply on Dec 2, 2009 6:22 AM by grenvoy

    this object

    grenvoy Level 1

      Where is the best place to get documentation on the "this" object?

       

      I'm trying to pass the name of a dynamically added canvas back to the parent, and I was tryng to use this.id.  I see that this.name works, but it postfixes an arbitrary number onto the name of the object.  Is there a better way to do what I'm trying to do?

        • 1. Re: this object
          Flex harUI Adobe Employee

          The 'this' object is whatever class who's methods you are invoking at that time.  You'll probably be ok setting id

           

          Alex Harui

          Flex SDK Developer

          Adobe Systems Inc.

          Blog: http://blogs.adobe.com/aharui

          1 person found this helpful
          • 3. Re: this object
            grenvoy Level 1

            So if it is derived from the methods class, why are the arbitrary numbers being apended to the end of the this.name?

             

            For example I have a Parent and a Child Canvas.  The parent adds the child dynamically based on a dictionary collection of canvas's to add.  Then when I callback into the parent from the child, I want to be able to tell him who is calling back.  Since I newed it up as "HeaderPanel" I get something like "HeaderPanel17" when I use this.name.  Where does the 17 come from?  Will it always be 2 characters?  I could always chop it off.

             

                            for each ( var lPanel:PanelHandler in mPanelDictionary )
                            {
                                var lPanelName:String = lPanel.GetPanelName();
                           
                                var lPanelObject:flash.display.DisplayObject   = null;
                                var lTempObject:Object                         = null;
                               
                                switch (lPanelName)
                                {
                                    case "HEADER":
                                        lPanelObject = new HeaderPanel();
                                        break;
                                    case "FOOTER":
                                        lPanelObject = new FooterPanel();
                                        break;
                                    default:
                                        Alert.show("Unknown Panel Type:" + lPanelName + " could not be added.");
                                        break;
                                }
                               
                                if (lPanelObject == null )
                                {
                                    continue;
                                }
                               
                                // We need to cast the panel object so we can call the
                                // panel and set the parent.
                                lTempObject = lPanelObject as Object;
                               
                                // Make sure we were able to case before we set the parent.
                                if ( lTempObject )
                                {                
                                    lTempObject.setParent(this);
                                }

            • 4. Re: this object
              paul.williams Level 4

              If you add a child to a component and you do not explicitly set a name for that child, Flex will generate one for you. If I recall correctly the name is composed of the class name of the child plus a number. If you don't want this to be the name of your child, then set something else.

               

              Why not just pass 'this' back to the parent, ie. pass a reference to the child itself?

              1 person found this helpful
              • 5. Re: this object
                grenvoy Level 1

                I could pass this back to the parent, but all I really need is a unique name to register in my dictionary.  I have a dictionary of elements that each child needs a subset of.  The parent communicates with DB for the children, then when the children refresh they call the parent and requst only the data associated with their name.

                 

                Even thoguh the number is appended it will probably work, since I would expect that name to stay constant for the life of the object.  It just seems odd to me.  I guess it allows for multiple instances of the same object to have unique names.

                • 6. Re: this object
                  paul.williams Level 4

                  You don't need to use Strings as keys in a Dictionary, you can use the direct references to your child objects as keys.

                  • 7. Re: this object
                    grenvoy Level 1

                    In my case I'm using a string as the key and storing an object.  I think I'll be ok with using this.name.  I'm trying to stay away from naming the object myself, and now that I have a better understanding of where the this.name comes from I feel comfortable in using that.

                     

                    Thanks for the help.