2 Replies Latest reply on May 9, 2006 9:36 AM by tevadar

    String to MovieClip data type conversion

    tevadar
      Is there an easy way to convert a string into a movieClip reference?

      I’m populating an array with movie clip references and other properties and then saving them to the sharedObject(). The problem is that many of the movieClips are nested within others and so the target path is not so simple. The only way I know of is with the _root[] method.

      So...

      _level0.instance1.instance2.instance3

      Becomes...

      _level0[instance1][instance2][instance3]

      So in order to convert a sting generated by movieClip._target back into a movieClip reference all I can think of is to split it into an array and then reconstruct it like...


      function stringToClip(clipString:String) {

      mcpathArray = clipString.split("/");

      for(var i:Number = 1; i<mcpathArray.length; ++i){
      var tVar:String = "path"+i;
      this[tVar] = mcpathArray ;
      }

      var mcName:MovieClip = new MovieClip();
      switch (mcpathArray.length) {
      case 2 :
      trace("path1");
      mcName = _root[path1];
      return(mcName);
      break;
      case 3 :
      trace("path2");
      mcName = _root[path1][path2];
      return(mcName);
      break;
      case 4 :
      trace("path3");
      mcName = _root[path1][path2][path3];
      return(mcName);
      break;
      }

      };


      I know the last part could be delt with more elegantly, but the whole thing seams to way to much work to do such a simple task.

      Thanks for any help with this,
      Joe