Brett, I'm not clear on what you're trying to accomplish. You said you need to create components dynamically and set their properties. If you simply need to set the width and height of a newly created component, you can do that immediately after 'new'ing the component in the same way that you set x and y. - Gordon
________________________________ From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of Alex Harui Sent: Monday, March 26, 2007 3:22 PM To: [email protected] Subject: RE: [flexcoders] Setting properties on AS-created components You can't be as procedural as old Flash AS. If you do: b = new Button() you can't ask for the width until after your method is over because the validation mechanism normally doesn't kick in until "later". You can force validation by doing: b.validateNow(). Generally, you don't want to do that. Usually, if you create the Button in createChildren() or on an event, your updateDisplayList will get called at the appropriate time, and the child will be sized by then. So, instead of writing one long "create-and-draw" function, we recommend finding the right methods to override or events to listen to, and writing a few lines of code in the right places. -Alex ________________________________ From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of Brett Walker Sent: Monday, March 26, 2007 2:49 PM To: [email protected] Subject: Re: [flexcoders] Setting properties on AS-created components hi Alex, Thanks for the reply. I did try using getExplicitOrMeasuredWidth() before I switched to using a listener, and it returned 0. Are you suggesting that it should return the accurate value, though? Or that I should be using getExplicitOrMeasuredWidth() *anytime* I want to access a child's width property? I will try moving the event listener to something earlier than creationComplete -- I was just happy that I got it to work at all! -brett On 3/26/07, Alex Harui <[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]> > wrote: We can always use more documentation. Books are coming out left and right these days which may also help. You're right, the width/height isn't set until the updateDisplayList pass. We use a invalidate/validate model for performance reasons. Another thing is that we use a top-down layout model. The application is sized, then its children, then their children, etc... Essentially, children are sized by their parents. Parents laying out their children generally don't care about the width/height because they will dictate it. Instead they care about the child's measured or explicitly set height and try to honor that. There is a method call getExplicitOrMeasuredWidth()/Height() that we use all the time. The source code shipped with the product which is a good place to look. There is a keep-generated flag that shows you what AS the MXML compiler generates. Final note, creationComplete is very late, the equivalent of automatically hitting a button to effect change, so you'll probably be better off using getExplicitOrMeasured...() ________________________________ From: [email protected] <mailto:[email protected]> [mailto:[email protected] <mailto:[email protected]> ] On Behalf Of Brett Walker Sent: Monday, March 26, 2007 12:34 AM To: [email protected] <mailto:[email protected]> Subject: [flexcoders] Setting properties on AS-created components hi there, Long time AS developer, new Flex developer. Coming from a pure ActionScript background, I've been really banging my head against the Flex framework. I'm working on a Flex 2 project where I need to dynamically instantiate Flex components using ActionScript, and then lay them out manually. I finally got everything sorted out, but I'm wondering if there really isn't a better way to do this. Basically, I'm creating Flex components at runtime using "new ___()". In particular, I came across a problem trying to modify a Button component that I created inside a Panel. Setting the x and y immediately was no problem, however the width property kept returning 0 . I tried explicitWidth, measuredWidth, every arcane width I could find in the docs, but always 0. Then I realized that the Button probably hadn't finished its layout processes yet. Okay, after some more hand-wrenching, I decided to add a listener to the Button for the FlexEvent.CREATION_COMPLETE event, and set the props on that. Gods be praised, it worked. The width property finally had a value. But really, this seems very inelegant to me. Don't get me wrong, I love the AS3 event system (mostly), but having to create listener functions just to set visual properties of AS-created components...ugh. Is there a better way to accomplish this? Did I miss something? I think that Adobe needs to concentrate more documentation on using Flex from a non-MXML perspective. It is very frustrating trying to get up to speed with such a complicated framework, when most of the documentation uses MXML to teach concepts. thanks, -brett

