Sounds like you're running into the 'one-frame-delay-thing' that is known to 
most Flash users.

Try using callLater() and see if that fixes it, or use one of the events, such 
as 'add', 'added', 'creationComplete', 
'updateComplete', 'resize'..
Not sure which one will be triggered at the right moment, so you'll have to 
test it.

regards,
Muzak


----- Original Message ----- 
From: "munkydung" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Saturday, September 02, 2006 1:08 AM
Subject: [flexcoders] UIComponent.width is always 0


Well, not always... When I instantiate a control with an MXML tag, the
width property returns the correct number. When I instantiate a
control via ActionScript, the width property always returns 0. What am
I doing wrong?

Here's the code
<?xml version="1.0" encoding="utf-8"?>
<mx:Application layout="absolute" width="100%" height="100%"
frameRate="12" pageTitle="Text Control width test"
xmlns:mx="http://www.adobe.com/2006/mxml"; creationComplete="init()">
  <mx:Script>
    <![CDATA[
    import mx.controls.Text;
    [Bindable]
    internal var debugMsg:String; // used for displaying text our
textArea at the bottom of the application
    internal function init():void {
      // output widths of text control created via MXML
      debugMsg += "textViaMXML.width = " + textViaMXML.width + "\n";
      debugMsg += "textViaMXML.measuredWidth = " +
textViaMXML.measuredWidth + "\n";
      debugMsg += "textViaMXML.textWidth = " + textViaMXML.textWidth +
"\n";

      // now we create a Text via actionscript
      var textViaAS:Text = new Text();
      textViaAS.text = "Text Control created via ActionScript";
      textViaAS.y = 40;
      textViaAS.setStyle('horizontalCenter',0);
      application.addChild(textViaAS);
      textViaAS.validateNow(); // really just for kicks, it doesn't
seem to fix the problem...

      // output widths of text element created via ActionScript
      debugMsg += "textViaAS.width = " + textViaAS.width + "\n";
      debugMsg += "textViaAS.measuredWidth = " +
textViaAS.measuredWidth + "\n";
      debugMsg += "textViaAS.textWidth = " + textViaAS.textWidth + "\n";
    }
    ]]>
  </mx:Script>
  <mx:Style>
    Text { fontFamily: Verdana;  fontSize: 16pt;  }
    TextArea.debugTextArea { fontFamily: Courier; fontSize: 12pt; }
  </mx:Style>
  <mx:Text id="textViaMXML" text="Text Control created via MXML"
horizontalCenter="0"/>

  <!-- a textArea for display messages from AS -->
  <mx:ApplicationControlBar id="debugControlBar" dock="false"
width="100%" bottom="0">
    <mx:TextArea id="debugTextArea" styleName="debugTextArea"
width="100%" height="120" editable="false" text="{debugMsg}" />
  </mx:ApplicationControlBar>
</mx:Application>







--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/flexcoders/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 


Reply via email to