4 Replies Latest reply on Mar 1, 2007 8:15 AM by kglad

    Convert String to an Object Instance Name

    billaddison Level 1
      Hey there,

      I'd like to append multiple strings in order to create an instance names. The code is placed below:

      // I have 3 buttons contained in a MC with the instance name "container"
      // I've created an array of the button instance names
      var myArray:Array = new Array (button1, button2, button3);
      // I'm using a "for" loop to automate the process
      for (i = 0; i < myArray.length; i++){
      // Creates a string of the path from root level to the button
      var myArray :String = "container." + myArray;
      // Trying to convert the string into an object and also abbreviate the path from "container.button1" to "button1"
      var myArray :Object = new Object();
      // Change all the buttons alphas to 100
      myArray
      ._alpha = 100;
      }

      thanks in Advance!
      Susan
        • 1. Re: Convert String to an Object Instance Name
          kglad Adobe Community Professional & MVP
          use the attach code option to display code. otherwise, you risk your code being altered by the is forum.

          your coding makes no sense even allowing for the forum's altering of your code.

          the only step that makes sense is your creation of the array myArray (assuming that code is on the movieclip's timeline. is it?

          after that you appear to be try and change myArray to a string (in a for-loop) which would destroy your array and ruin the for-loop while it's executing. after that it appears you're trying to destroy the string and create an object. and then you look like you want to use the array that's long gone.

          what is it that you're trying to accomplish?

          • 2. Re: Convert String to an Object Instance Name
            billaddison Level 1
            I have a series of buttons with instance names "button1", "button2", etc., inside a container MC with an instance name "container" sitting on the root level.

            All my code is located on a frame at the root level.

            I'd like to store my button instance names in an array, then make changes to all the buttons at once by using a "for" loop and appending the prefix "container." to the "button1", "button2", etc., instance names, so as to make it "container.button1", "container.button2", etc.

            Thanks!
            Susan
            • 3. Re: Convert String to an Object Instance Name
              billaddison Level 1
              Ok maybe that was a little confusing.

              Basically I want to join two strings and then use that to access a MC within a MC.

              "button1" is located inside "container". I want to make a string "container.button1" and somehow use that to access the button1 MC.

              Does that help?
              • 4. Re: Convert String to an Object Instance Name
                kglad Adobe Community Professional & MVP
                if you create your array no latter than the frame in which your buttons exist you can just use their instance names: