The following example shows how you can access the Label subcomponent in a Flex FormItem container and do fancy stuff like have form labels with hyperlinks or selectable text by using the itemLabel property.
Full code after the jump.
<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/03/21/customizing-a-formitem-containers-label-in-flex-3/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
verticalAlign="middle"
backgroundColor="white">
<mx:Script>
<![CDATA[
import mx.events.FlexEvent;
import mx.controls.Label;
import mx.controls.Alert;
import mx.containers.FormItem;
private function init2(evt:FlexEvent):void {
var lbl:Label = FormItem(evt.currentTarget).itemLabel as Label;
lbl.selectable = true;
}
private function init3(evt:FlexEvent):void {
var lbl:Label = FormItem(evt.currentTarget).itemLabel as Label;
lbl.htmlText = txt;
lbl.selectable = true;
lbl.addEventListener(TextEvent.LINK, label_link);
}
private function label_link(evt:TextEvent):void {
Alert.show("You clicked a link. Have some cake.");
}
]]>
</mx:Script>
<mx:String id="txt">
<![CDATA[<a href="event:att"><u>Hyperlink</u></a> label]]>
</mx:String>
<mx:Form maxWidth="500">
<mx:FormItem id="formItem1"
label="Default label">
<mx:Label id="label1"
text="The quick brown fox jumped over the..." />
</mx:FormItem>
<mx:FormItem id="formItem2"
label="Selectable label"
creationComplete="init2(event);">
<mx:Label id="label2"
text="The quick brown fox jumped over the..." />
</mx:FormItem>
<mx:FormItem id="formItem3"
label="Hyperlink label"
creationComplete="init3(event);">
<mx:Label id="label3"
text="The quick brown fox jumped over the..." />
</mx:FormItem>
</mx:Form>
</mx:Application>
View source is enabled in the following example.



Thanks lots of.
i am Getting an error like
1119: Access of possibly undefined property itemLabel through a reference with static type
i am using Flex Gumbo.
any suggestion?