继承FormItem实例

/*******FromItemWithButton 类*******/

//自定义事件
[Event(name="doSomething", type="flash.events.Event")]

//定义样式,将css文件中的newButtonSkin样式应用到此自定义组件中
[Style(name="newButtonSkin", type="Class")]
public class FromItemWithButton extends FormItem{
    private var newButtonSkin:Class;
    private var newButton:Button;
    private var _newButtonLabel:String;
    private var _newButtonWidth:int = 40;
    private var _newButtonHeight:int = 25;
    private var _newButtonSpace:int = 10;
    public function FromItemWithButton(){
        super();
    }

    public function set newButtonLabel(value:String):void{
        _newButtonLabel = value;
    }

    public function set newButtonWidth(value:String):void{
        _newButtonWidth = value;
    }

    public function set newButtonHeight(value:String):void{
        _newButtonHeight = value;
    }

    //设置按钮与formitem内的控件(如textInput)之间的间距
    public function set newButtonSpace(value:String):void{
        _newButtonSpace = value;
    }

    private function doDispatch(event:Event):void{
        this.dispatchEvent(new Event("doSomething"));
    }

    override protected function createChildren():void{
        super.createChildren();
        newButton = new Button();

        //skin类定义在css文件中。
        newButtonSkin = getStyle("newButtonSkin");
        newButton.setstyle("upSkin",newButtonSkin);
        newButton.setstyle("downSkin",newButtonSkin);
        newButton.setstyle("overSkin",newButtonSkin);

        newButton.width = _newButtonWidth;
        newButton.height=_newButtonHeight;
        newButton.label = _newButtonLabel;

        newButton.addEventListener(MouseEvent.Click, doDispatch);

        rawChildren.addChild(newButton);     //作为一个非内容子项添加
    }

    //调整按钮的位置,显示在formItem的最右边
    override protected function updateDisplayList(unscaleWidth:Number,unscaleHeight:Nuber):void{
        //计算加上新加的按钮的formItem宽度,并列新父的宽
        var containerWidth:int = _newButtonWidth + unscaleWidth + _newButtonSpace;
        super.updateDisplayList(containerWidth,unscaleHeight);
       
        //取得应放置按钮的xy座标
        var xPos:int = containerWidth = _newButtonWidth;
        var yPos:int = 0;

        //此时不能用xPos、yPos赋值给newButton的xy座标,应该用newButton的move方法
        newButton.move(xPos,yPos);
    }
}

 


/****在MXML中调用FormItemWithButton ****/
<comp:FormItemWithButton label="username"
    newButtonLabel="help"
    newButtonHeight="50"
    newButtonWidth="70"
    styleName="formItemButton"
    doSomething="doSomeHandler()">
</comp:FormItemWithButton>

 

 

/*****css定义******/
.formItemButton:{
    newButtonSkin: ClassRefrence("skins.RoundedButtonSkin"); //ActionScript类
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值