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