How can I obtain the position of a instance whose name is stored in an variable? If there is a instance whose name I don't know, but the instance's name is store in an variable x. How can I obtain its position?
EDIT: If you have a input text, where users would type the instance name. Let's say the input text is named text1.
targetMc = eval(text1.text);
targetMcX= targetMc._x;
targetMcY = targetMc._y;
trace(targetMcX); //would trace _x position of instance typed in your text1.
trace(targetMcY); //would trace _y position of instance typed in your text1.
You mean you have an instance of a MovieClip on stage, that has a name. You then have a variable x of type String which stores that name? Assuming you know which display container the clip is in you can go:
EDIT:
//on some trigger (either text field change, or button click)
var nameOfInstance:String = txtInput.text;
//also check that you have given the display objects on stage instance names if they
//were dynamically created
var myMovieClip:MovieClip = /*container goes here.*/getChildByName(nameOfInstance);
var xPos:Number = myMovieClip.x;
Thanks a lot, Sthg, and Allan!! What I means is that: If I let people type in an instance name in a text input, how can I obtain the position of the instance? For example, I have a input text, text1, which already contains an instance name(One of the instances which are already exist.). I want to obtain the x-position of the instance and store in a variable. How to do this?
var myMovieClip:MovieClip = MovieClip(stage.getChildByName(text1.text));
myMovieClip.x
myMovieClip.y
EDIT: The MovieClip ( thing ) is to cast the object and turn it into a MC
Thanks a lot, Sthg!!! It really work! Allan, I also appreciate your help! Have a nice day, Guys!
Sincerely, John