tags:

views:

57

answers:

5

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?

A: 

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.
sthg
A: 

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;
Allan
A: 

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?

john
i've updated the answer, take a look.
sthg
You should edit your question rather than post updates as an answer. Answers on Stack Overflow do not retain there order. This is not a forum.
TandemAdam
A: 
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

Hock
A: 

Thanks a lot, Sthg!!! It really work! Allan, I also appreciate your help! Have a nice day, Guys!

Sincerely, John

john