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]> 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] *On
Behalf Of *Brett Walker
*Sent:* Monday, March 26, 2007 12:34 AM
*To:* [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


Reply via email to