/ Published in: ActionScript 3
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
// When you are in a for loop, create new items and and try to measure the height of an item. // And position items vertically.You need to remember the previous item, the fastest way to do this is to have a runningY var declared outside the for loop with an initial value of zero. //See comments in code for further explanation. var runningY:Number = 0; for (var index:int = 0; index < 4 ; index++) { var _textheader:TextField = new TextField( ); _textheader.text = "Text"; _textheader.autoSize = TextFieldAutoSize.LEFT; _textheader.x = _background.x - _background.width / 2 + TOP_LEVEL_OFFSET_X; // First iteration runningY = 0; // Second iteration runningY = 0 + textHeader.height +2; textHeader.height = 20 // Third iteration runningY = 22 + textHeader.height +2; textHeader.height = 40 -- mutiple lines of text // Fourth iteration runningY = 64 + textHeader.height +2; textHeader.height = 20 // Fifth iteration runningY = 86 _textheader.y = runningY; runningY += _textheader.height + 2; // textheader = 20 }