2015-05-25 92 views
0

我將動畫片段對象動態添加到父容器,然後將每個新添加的片段的y位置設置爲容器的高度加上一些垂直填充像素的數量。期望的效果是將新的動畫片段追加到垂直動畫片段列(文本消息線索)的底部。什麼奇怪的是,無論什麼價值我的垂直填充指定,新片段始終顯示正好緊靠在先前添加的剪輯的底部,彷彿填充總是0Flash AS3,設置兒童動畫片段位置時的奇怪

var smsVPadding:Number = 10; 

// Get current bounds of sms_history_mc 
var bounds = sms_history_mc.getBounds(sms_history_mc.parent); 
var yPos:Number = bounds.height + smsVPadding; 

// Add the new SMS to sms_history_mc 
sms_history_mc.addChild(newSMS); 

newSMS.y = yPos; 

如果我設置newSMS.y的值明確地指向newSMS.y = 600,它按預期工作。但是,如果我通過明確添加填充像素bounds.height + 10來設置yPos,結果會再次變得很奇怪。

trace(newSMS.y)產生期望值,但是movielip的位置不反映這一點。

有什麼想法?請告訴我我錯過了一些荒謬的事情。提前致謝。

+0

您確定您的sms對象/ MovieClip內容正確定位嗎?聽起來像你可能在該剪輯的頂部有一些空的空間。此外,沒有理由使用邊界,只是執行'sms_history_mc.height' – BadFeelingAboutThis

+2

也許是因爲你已經將第一個影片剪輯的'y'設置爲填充值,所以所有剪輯僅向下移動10個像素。 –

+0

@BolesławChrobry釘了它。在'sms_history_mc'的頂部有10個像素的空白空間是什麼東西在扔掉。對象的高度/寬度不反映剪輯頂部/底部/左側/右側的任何空白空間 – BadFeelingAboutThis

回答

0

我的問題是,正如@BoleslawChrobry指出的那樣,添加到第一個mc中的10個填充像素實際上是在下次計算時從包含mc的高度「修剪」的。輕鬆修復:

// Get current bounds of sms_history_mc 
var bounds = sms_history_mc.getBounds(sms_history_mc.parent); 
var yPos:Number = sms_history_mc.height; 
if(yPos > 0) // At least one sms has already been added 
    yPos += smsVPadding; 

// Add the new SMS to sms_history_mc 
sms_history_mc.addChild(newSMS); 

newSMS.y = yPos;