2009-11-18 39 views
0

如何獲取名稱存儲在變量中的實例的位置? 如果有一個實例的名稱我不知道,但實例的名稱存儲在一個變量x中。我如何獲得它的位置?如何獲取名稱存儲在變量中的實例的位置?


我的意思是說:如果我讓人們在一個實例名稱在文本輸入類型,我怎樣才能得到一個實例的位置? 例如,我有一個輸入文本text1,它已經包含一個實例名稱(其中一個已存在的實例)。我想獲取實例的x位置並存儲在一個變量中。這個怎麼做?

回答

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. 
0

你的意思是你在舞臺上有一個MovieClip實例,它有一個名稱。然後你有一個變量x的String類型存儲該名稱?假設你知道這顯示容器夾片,你可以去:

編輯:

//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; 
0
var myMovieClip:MovieClip = MovieClip(stage.getChildByName(text1.text)); 

myMovieClip.x 
myMovieClip.y 

編輯:影片剪輯(事)是投對象,並把它變成一個MC