Hi,

Not to step on toes here but...

The reason is not that a 'width' is not getting set but explicitWidth has not been set by YOU.

If you call text.getExplicitOrMeasuredWidth(), this will return the correct measurement.

Now, if you set text.width OR text.explicitWidth, you will get text.width. ;-) This locks the component in a flow layout though.

Imagine;

- explicit (set by the client) [width] [explicitWidth]
- measure (measured by the component) :: [measuredWidth]
min & max

width also then gets set by calling setActualSize() which a container such as the Application does(Box).

There is nothing wrong here and everything is completly the way it is supposed to be.

This shows what is going on when MXML is involved.

text.setActualSize(text.getExplicitOrMeasuredWidth(), text.getExplicitOrMeasuredHeight())

Anyway, width does not mean  _width anymore. Everything is based on real things now, no boundingBoxes, (and thankgoodness for that).

Peace, Mike


On 9/1/06, Muzak <[EMAIL PROTECTED]> wrote:

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: <flexcoders@yahoogroups.com>
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>




--
What goes up, does come down. __._,_.___

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





SPONSORED LINKS
Software development tool Software development Software development services
Home design software Software development company


YAHOO! GROUPS LINKS




__,_._,___

Reply via email to