1 Reply Latest reply on Jun 1, 2010 10:27 PM by Dajji

    How do I check the width of a component

    SiHoop Level 1

      I am adding several pages to a display and want to lay out the pages on screen. To do this, I use an array (sectionPages) to keep track of the number of pages that I am creating. In the example below, first I create 7 pages, then 5 pages. The idea is to create the first 7 pages, then find the width of those pages to determine where the next 5 pages should be placed.

      My problem is that I cannot find the width of the first 7 pages. I thought I could use FlexEvent.CREATION_COMPLETE to send me to a function, then use e.target.lastWidth to read the width of the last display that I track inside the component. However, what happens is that the values get calculated as 0 before they are displayed propoerly on screen. Is there a listener that I can use that will wait for the screen to be laid out properly before I calculate the page widths?


      <?xml version="1.0" encoding="utf-8"?>
      <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="init()">
      import mx.events.*;
      private    var sectionPages:Array=[7,5];//Number of pages in each group
      public function init():void{
      //First make the pages
          for(var j:int=0; j<sectionPages.length;j++){
              var section:SeveralPages=new SeveralPages;
              section.addEventListener(FlexEvent.CREATION_COMPLETE, handleSectionAdded)
      public function handleSectionAdded(e:Event):void{
          trace("Latest width="+e.target.lastWidth)