5 Replies Latest reply on Sep 8, 2007 8:06 PM by kglad

    string conversion

      i have an as2 2-d array in which i am storing the instance name of a mc in the [0] slot and the path to another mc in the [1] slot. the problem is that the [1] slot ( pathName.instanceName ) is tracing out as an 'undefined' value. i know the paths are valid because i have passed them to a function using a switch statement and they work. is there a way i can store the data in the [1] slot as a string and then convert it back to an instance name when i call it.
        • 1. Re: string conversion

          //the first line creates an empty movie clip called xx
          var xx:MovieClip = _root.createEmptyMovieClip("container", 1);

          //a new array initiated
          arr = new Array();

          for (var i = 0; i<10; i++) {
          //in this loop "mc"+i movie clips are created inside xx
          // so the path of each "mc"+i is _root.xx["mc"+i]

          xx.createEmptyMovieClip("mc"+i, i);

          //cc strores the names of each movie clip
          cc = ["mc"+i];

          // the arr array now stores two values
          // first value stores the path (i.e. xx which is _root.container) and
          //the 2nd value stores movieclip's name
          arr = [xx, cc];
          [0]+"."+arr [1]); // _level0.container.mc0....9
          // say suppose i want 5th item in that 2d array called arr and store the value in ff
          ff = arr[4][0]+"."+arr[4][1]; // but its actually a string u can verify that by the following command
          trace(typeof(ff)); //String

          //conversion to movie clip
          trace(typeof (eval(ff))); //movieclip

          i hope this ll solve ur problem
          • 2. Re: string conversion
            _name Level 1
            thanks tegnegi, but that is not what i am trying to do. i want to pass the name of an array that is stored in an array to a function, but because the array name includes a path it is tracing out as 'undefined.' i can pass the instance names like this:

            myFunction( pathName.arrayName );

            however, if i store the array names in an array and trace them out, flash does not recognize them as valid data.

            • 3. Re: string conversion
              kglad Adobe Community Professional & MVP
              you can use the eval() function to convert your string to a path/object.
              • 4. Re: string conversion
                _name Level 1
                thanks, kglad, that's a nice little function.
                • 5. Re: string conversion
                  kglad Adobe Community Professional & MVP
                  you're welcome.