Components are instanciated asynchronously. You may want to try this implementation.
<?xml version="1.0" encoding="utf-8"?>
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark">
<fx:Script>
<![CDATA[
private var _message:String, _messageChanged:Boolean;
public function get message():String {
return _message;
}
[Bindable("messageChanged")]
public function set message(value:String):void {
if (_message == value) {
return;
}
_message = value;
_messageChanged = true;
invalidateProperties();
dispatchEvent(new Event('messageChanged'));
}
override protected function commitProperties():void {
super.commitProperties();
if (_messageChanged) {
_messageChanged = false;
label1.text = _message;
}
}
]]>
</fx:Script>
<s:Label id="label1"/>
</s:View>
This is based on the Flex component live cycle, which lets you type a bit, but with a template it's ok if you can't/don't want to use data binding like in this example:
<?xml version="1.0" encoding="utf-8"?>
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark">
<fx:Script>
[Bindable]
private var _message:String;
public function setMsg(msg:String):void
{
_message = msg;
}
</fx:Script>
<s:Label id="label1" text="{_message}"/>
</s:View>
This example is might me a good choice as well - depending on your needs.