简体   繁体   中英

Flash AS3, strangeness when setting position of child movieclip

I'm dynamically adding movieclip objects to a parent container and then setting each newly added clip's y position to the height of the container plus some number of vertical padding pixels. The desired effect is to append the new movieclip to the bottom of a vertical column of movieclips (a text message thread). What's strange is that no matter what value I specify for vertical padding, the new clip is always displayed abutted exactly against the bottom of the previously added clip, as though the padding were always 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;

If I set the value of newSMS.y explicitly to a number newSMS.y = 600 it works as expected. However, if I set yPos by explicitly adding the padding pixels bounds.height + 10 the result is strange again.

trace(newSMS.y) yields the expected value, but the movielip's position does not reflect this.

Any thoughts? Please tell me I'm missing something ridiculous. Thanks in advance.

My problem was, as @BoleslawChrobry pointed out, the 10 pixels of padding added to the first mc were in effect "trimmed" from the height of the containing mc next time it was calculated. Easy fix:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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