all groups > flash actionscript > may 2006 >
You're in the

flash actionscript

group:

String to MovieClip data type conversion


Re: String to MovieClip data type conversion David Stiller
5/8/2006 7:48:22 PM
flash actionscript:
tevadar,

[quoted text, click to view]

There is. Both the eval() function and the array access operator will
do it for you.

See details here.

http://www.quip.net/blog/2006/flash/actionscript-20/reference-objects-dynamically


David
stiller (at) quip (dot) net
Dev essays: http://www.quip.net/blog/
"Luck is the residue of good design."

String to MovieClip data type conversion tevadar
5/8/2006 11:23:27 PM
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

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 = mcpathArray;
}

var mcName:MovieClip = new MovieClip();
switch (mcpathArray.length) {
case 2 :
trace("path1");
mcName = _root;
return(mcName);
break;
case 3 :
trace("path2");
mcName = _root;
return(mcName);
break;
case 4 :
trace("path3");
mcName = _root;
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
Re: String to MovieClip data type conversion tevadar
5/9/2006 4:36:58 PM
David, thank you VERY much! I knew there had to be an easier way.

BTW I like your site... it's very informative

AddThis Social Bookmark Button