繁体   English   中英

Flash AS3,设置子动画片段的位置时很奇怪

[英]Flash AS3, strangeness when setting position of child movieclip

我正在将movieclip对象动态添加到父容器,然后将每个新添加的剪辑的y位置设置为容器的高度加上一定数量的垂直填充像素。 所需的效果是将新的动画片段附加到动画片段的垂直列(文本消息线程)的底部。 奇怪的是,无论我为垂直填充指定什么值,新剪辑始终始终与先前添加的剪辑的底部完全显示,就像填充始终为0。

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的位置不能反映这一点。

有什么想法吗? 请告诉我,我缺少一些荒谬的东西。 提前致谢。

我的问题是,正如@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;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM