6 Replies Latest reply on Feb 24, 2008 10:01 PM by kglad

    _name property for this keyword

    nanush
      When you are using the keyword this inside of an event handler it refers to the object that triggered the event.

      For example if OnLoadInit of a sound object is triggered you can say

      this.play();

      Is there any way of returning the instance name of this the way you can get the name of a movie clip

      ie somemovieclip_mc._name

      It is probably not that simple. If there is a solution it probably needs several lines of code.
      However, it would be worth while for a lot of debugging purposes.
      Any help would be greatly appreciated.
        • 1. Re: _name property for this keyword
          kglad Adobe Community Professional & MVP
          if the object has a _name property, you can retrieve it using this._name. but it's always more informative to use trace(this) for debugging.
          • 2. Re: _name property for this keyword
            nanush Level 1
            Thanks for the quick reply

            Here is an example of the kind of situation I am talking about

            this.createEmptyMovieClip("mcSoundHolder",this.getNextHighestDepth());
            //trace("root"+ this._proto_toString);
            var sndAudio:Sound =new Sound(mcSoundHolder);
            var oNameHolder:Object = new Object();
            oNameHolder=this;
            sndAudio.loadSound("scattershot_endings.mp3",false);
            sndAudio.onLoad =function(bSuccess:Boolean ):Void{
            if (bSuccess){
            this.start();
            oNameHolder=this;



            trace (this );
            }
            };

            trace (this );

            yields [object Object]
            I was hoping to get sndAudio

            Alfred
            • 3. Re: _name property for this keyword
              nanush Level 1
              Thanks for the quick reply

              Here is an example of the kind of situation I am talking about

              this.createEmptyMovieClip("mcSoundHolder",this.getNextHighestDepth());
              //trace("root"+ this._proto_toString);
              var sndAudio:Sound =new Sound(mcSoundHolder);
              var oNameHolder:Object = new Object();
              oNameHolder=this;
              sndAudio.loadSound("scattershot_endings.mp3",false);
              sndAudio.onLoad =function(bSuccess:Boolean ):Void{
              if (bSuccess){
              this.start();
              oNameHolder=this;



              trace (this );
              }
              };

              trace (this );

              yields [object Object]
              I was hoping to get sndAudio

              Alfred
              • 4. Re: _name property for this keyword
                kglad Adobe Community Professional & MVP
                unfortunately there's nothing in as2 that will let access the class of an object or the instance name of an object.

                the best you can do is to use the typeof() function and the instanceof operator in as2.
                • 5. Re: _name property for this keyword
                  nanush Level 1
                  That is unfortunate. I have spent a lot of time trying to find a way to do this but there doesn't seem to be any work around.

                  Thanks for your help.

                  • 6. Re: _name property for this keyword
                    kglad Adobe Community Professional & MVP
                    you're welcome.