Spacing items vertically (y axis)


/ Published in: ActionScript 3
Save to your folder(s)



Copy this code and paste it in your HTML
  1. // When you are in a for loop, create new items and and try to measure the height of an item.
  2. // 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.
  3. //See comments in code for further explanation.
  4.  
  5. var runningY:Number = 0;
  6.  
  7. for (var index:int = 0; index < 4 ; index++) {
  8.  
  9. var _textheader:TextField = new TextField( );
  10. _textheader.text = "Text";
  11. _textheader.autoSize = TextFieldAutoSize.LEFT;
  12. _textheader.x = _background.x - _background.width / 2 + TOP_LEVEL_OFFSET_X;
  13. // First iteration runningY = 0;
  14. // Second iteration runningY = 0 + textHeader.height +2; textHeader.height = 20
  15. // Third iteration runningY = 22 + textHeader.height +2; textHeader.height = 40 -- mutiple lines of text
  16. // Fourth iteration runningY = 64 + textHeader.height +2; textHeader.height = 20
  17. // Fifth iteration runningY = 86
  18. _textheader.y = runningY;
  19. runningY += _textheader.height + 2; // textheader = 20
  20. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.