Extend a Flex component in AS3 or MXML
You'll extend a VBOX class to create a new "labeled VBOX component" passing the title as new parameter.
<ui:VBoxLabeled labelVBox="MXML VBoxLabeled" width="200" height="200" />
Following two examples: in MXML and AS3
<ui:VBoxLabeled labelVBox="MXML VBoxLabeled" width="200" height="200" />
Following two examples: in MXML and AS3
// AS3 Version
package com.domain.ui
{
import mx.containers.VBox;
public class VBoxLabeledAS extends VBox
{
import mx.controls.HRule;
import mx.controls.Label;
[Bindable]
private var _label:String;
public function VBoxLabeledAS()
{
super();
this.setStyle('backgroundColor', 0x999999)
}
public function set labelVBox(val:String):void {
// Create Title Label
var label:Label = new Label();
addChild(label)
label.text = val;
// Create HRule
var hr:HRule = new HRule();
addChild(hr)
hr.percentWidth = 100;
}
}
}
//MXML Version
<?xml version="1.0" encoding="utf-8"?>
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml"
width="100%" height="100%"
backgroundColor="#999999"
>
<mx:Script>
<![CDATA[
import mx.controls.HRule;
import mx.controls.Label;
[Bindable]
private var _label:String;
public function set labelVBox(val:String):void {
// Create Title Label
var label:Label = new Label();
addChild(label)
label.text = val;
// Create HRule
var hr:HRule = new HRule();
addChild(hr)
hr.percentWidth = 100;
}
]]>
</mx:Script>
</mx:VBox>




