如何获取名称存储在变量中的实例的位置?

时间:2009-11-18 01:07:13

标签: flash

如何获取名称存储在变量中的实例的位置? 如果有一个名称我不知道的实例,但实例的名称存储在变量x中。我怎样才能获得它的位置?


我的意思是:如果我让人们在文本输入中输入实例名称,我怎样才能获得实例的位置? 例如,我有一个输入文本text1,它已经包含一个实例名称(其中一个实例已经存在)。我想获取实例的x位置并存储在变量中。怎么做?

3 个答案:

答案 0 :(得分:0)

编辑:如果您有输入文本,用户可以在其中键入实例名称。假设输入文本名为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.

答案 1 :(得分:0)

你的意思是你在舞台上有一个MovieClip的实例,它有一个名字。然后你有一个String类型的变量x存储该名称?假设您知道剪辑所在的显示容器,您可以:

编辑:

//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;

答案 2 :(得分:0)

var myMovieClip:MovieClip = MovieClip(stage.getChildByName(text1.text));

myMovieClip.x
myMovieClip.y

编辑:MovieClip(事物)是投射对象并将其转换为MC