MXML components do not have constructor parameters. You set properties
after calling 'new'. If you write
 
    <mx:Button id="b" label="OK" labelPlacement="right"/>
 
the compiler generates code similar to
 
    var b:Button;
    ...
    b = new Button();
    b.label = "OK";
    b.labelPlacement = "right";
 
It doesn't know what MXML attributes correspond to what constructor
parameters.
 
If setting a property needs to affect children, you use
invaldiateProperties() and commitProperties() to accomplish this,
because the children do not get created during 'new'. (This is so that
which children it creates can be determined by the properties you set!)
Take a look at how Button code implements its label property.
 
- Gordon

________________________________

From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of tddclare
Sent: Friday, March 23, 2007 11:59 AM
To: [email protected]
Subject: [flexcoders] "constructor" like arguments in MXML components?



I'm working on an app that has the need for several popup "item
editor" kind of windows. 

Example: there are people in a list, and when you double click one of
them, you get a popup (TitleWindow) with a form with fields for (and
populated with the selected person's) FirstName, LastName, ... and
save and cancel buttons.

I'm also trying to use the same popup for entering a NEW person, so
that the popup comes up with blank form items.

My first approach was to make an MXML component based off of
TitleWindow, since I have a lot of form elements and layout to add.

But then I ran into the problem. I want to pass in a Person instance
to populate the form (if I'm in edit mode) or else not pass in
anything (null) if I'm in create-new mode. In AS, I'd have the
contructor accept a p:Person = null parameter and that would be that.

So.. my question finally. Is there a way / technoque to pass in
"contructor" types of parameters to an MXML component, or do I need to
suck it up and write the class in AS and deal with all the "addChild's
necessary to create the layout (oh, and it has states)?

Thanks!

-- TC



 

Reply via email to