2010-10-14 62 views
0

我已經創建了下面的腳本,但座標不能正常工作。請看我的腳本,並讓我知道我的腳本有什麼問題。 感謝ActionScript 3.0將邊框添加到電影剪輯

/*mcc is the Instance name*/ 

var myMovieClip:Sprite = new Sprite(); 
trace("x" + mcc.x + "y" + mcc.y + "width" + mcc.width); 
myMovieClip.graphics.lineStyle(1, 0xFF0000); 
myMovieClip.graphics.drawRect(0, 0, mcc.width+1, mcc.height+1); 
myMovieClip.graphics.endFill(); 
myMovieClip.x = -(mcc.x/2); 
myMovieClip.y = -(mcc.y/2); 
mcc.addChild(myMovieClip); 
+0

座標究竟不能正確地工作?你從這個腳本中看到了什麼結果? – ktdrv 2010-10-14 23:07:21

回答

1

將需要更多地瞭解mcc看起來像我們假定中冶爲中心的,而不是MCC的右上角是在[0,0]

內容嘗試使用改爲getBounds method

這樣的事情...雖然我沒有測試它

var bounds:Rectangle = mcc.getBounds(this) 
myMovieClip.graphics.drawRect(
    bounds.left-border/2, bounds.top-border/2, 
    bounds.width+border, bounds.height+border 
); 
myMovieClip.x = (mcc.x); 
myMovieClip.y = (mcc.y); 
mcc.addChild(myMovieClip); 
0

謝謝你,這是工作,現在,我用的getBounds並設置myMovieClip.x =(0); 。這沒有意義,但現在它運作良好。

無論如何,mcc可以是任何事物,也可以是事件旋轉角度。

var border=1; 
var myMovieClip:Sprite = new Sprite(); 
myMovieClip.graphics.lineStyle(border, 0xFF0000); 
trace("getbound on mcc" + mcc.getBounds(mcc)); 
trace("parser" + mcc.getBounds(mcc).y) 
    trace("getbound on this" + mcc.getBounds(this)); 
    trace("Other x " + mcc.x + " y " + mcc.y + " width " + mcc.width+ " height " + mcc.height); 
var bounds =mcc.getBounds(mcc) 
myMovieClip.graphics.drawRect(bounds.left-border/2, bounds.top/2,bounds.width+border, bounds.height+border); 

myMovieClip.graphics.endFill(); 
myMovieClip.x = (0); 
myMovieClip.y = (bounds.y)/2; 
mcc.addChild(myMovieClip); 
trace("New bound" + mcc.getBounds(mcc)); 
相關問題