5 Replies Latest reply on Jan 31, 2007 9:29 PM by kglad

    Variable Reference of Instance Name

    jahmer
      While I have had no problems with bracket evaluation of constants and number variables, I don't know the coding convention for brack evaluation of a string.

      I get an undefined for oBtnName

      oBtnName = new Object;
      oBtnName = this["mcWing" + aWingColor[nIdx] + "Btn"];

      where aWingColor is an array of strings. So I tried setting aWingColor[nIdx] to variable thinking the inside array brackets were goofing this up:

      oBtnName = new Object;
      var sWingColor:String = aWingColor[nIdx];
      oBtnName = this["mcWing" + sWingColor + "Btn"];
      trace (sWingColor + " " + oBtnName._name );

      returns Pink undefined

      and interactive debug is showing oBtnName as undefined as well.

      So, then I tried this
      oBtnName = this["mcWing" + sWingColor._value + "Btn"];

      and then this
      oBtnName = this["mcWing" + "[sWingColor]" + "Btn"];

      and so on and so on. . . .



        • 1. Re: Variable Reference of Instance Name
          kglad Adobe Community Professional & MVP
          if you want to create an object with that string name use:

          • 2. Re: Variable Reference of Instance Name
            jahmer Level 1
            Isn't

            this["mcWing" + aWingColor[nIdx] + "Btn"]=new Object()

            the same as

            var oBtnName:Object = new Object;
            oBtnName = this["mcWing" + aWingColor[nWingRollIdx] + "Btn"];

            I am doing this to shorten the reference name
            Here is the rest of the code


            mcWingPinkBtn.onRollOut = function () {
            clearInterval(nInterval);
            nWingRollIdx = 1;
            nInterval = setInterval(fFadeOutWing, 1);
            }

            function fFadeOutWing():Void {
            var oBtnName:Object = new Object;
            oBtnName = this["mcWing" + aWingColor[nWingRollIdx] + "Btn"];
            oBtnName._alpha -= nAlphaIncrement;

            ----oBtnName is undefined here so the following if doesn't work -----

            if(oBtnName._alpha <= nAlphaStart) {
            oBtnName._alpha = nAlphaStart;
            clearInterval(nInterval);
            }
            updateAfterEvent();
            }

            • 3. Re: Variable Reference of Instance Name
              kglad Adobe Community Professional & MVP
              the answer to your first question is no. they are not the same.

              your fFadeOutWind() function has some errors. first, it's an error in logic to attempt to create a new Object with the same name as an object (your button) that already exists. creating two or more objects with the same name is always a bad idea. using the code i gave and NOT creating a new object would allow you to reference your movieclip correctly.

              the other errors ("this" is undefined in that function called by setInterval) are irrelevent when you change your approach.

              you've never stated what you're trying to accomplish, but i infer you want to fade several mcWing+COLOR+btn buttons. in that situation you could use the following:

              • 4. Re: Variable Reference of Instance Name
                jahmer Level 1
                It works now. Thanks again.
                • 5. Re: Variable Reference of Instance Name
                  kglad Adobe Community Professional & MVP
                  you're welcome.