Hi Lachlan,
You can solve this through binding. Create a variable for "a value"
and set it ant initialization:
[Bindable]
private var aValue:String;
//init code
aValue = "a Value";
Then bind the variable to the component property:
<local:MyComponent myProperty="{aValue}"/>
By doing it this way, the property will be set when the component is
created.
-TH
--- In [email protected], Lachlan Cotter
<[EMAIL PROTECTED]> wrote:
>
> Hi List,
>
> I have a question about the initialisation rules for MXML
components.
> My situation is as follows:
>
> I have defined a custom MXML component that extends the Canvas
class
> (myComponent).
>
> MXML root node of the file, I put a Text element, assigning it an
ID
> (myText).
>
> I define a setter method on this class (myProperty) that takes a
> String argument and passes it to myText.text.
>
> I use the custom component in the application, with a tag like
this:
>
> <local:MyComponent myProperty="a value" />
>
> Sure enough the instance is created and the setter method is
called.
> However, an error results when I try to access the property of
the
> child Text object. Apparently it has not been initialised when
the
> method is called. This results in an error (setting a property on
a
> null object).
>
> My question is if this is the expected behaviour and if there is
a
> way to achieve this with MXML (setting properties of child
objects
> from a setter method called at init time).
>
> Thanks for any insights.
>
> Cheers,
> Lach
>
--
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/