`

继承FormItem实例

    博客分类:
  • Flex
阅读更多

/*******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类
}

分享到:
评论

相关推荐

    JAVA期末作业打飞机游戏设计(程序+论文).zip

    首先显示的是游戏的背景介绍(图4-1),为此,在类lzhhdm定义Form类对象a,在startApp()函数中判断isSplash是否为真,如果为真的话,将创建Form类的实例a,并且调用append()方法在表单上放置StringItem类的实例以...

    从实例谈面向对象编程、工厂模式和重构

    cbbMediaType.Item.Add(key); } cbbMediaType.SelectedIndex = 0; } 最后,更改主程序的 Play 按钮单击事件: 程序代码 Public void BtnPlay_Click(object sender,EventArgs e) { string mediaType = ...

    python入门到高级全栈工程师培训 第3期 附课件代码

    05 item系列 06 str与repr 07 自定制format 08 slots属性 09 doc属性 10 module和class 11 析构方法 12 call方法 13 迭代器协议 14 迭代器协议实现斐波那契数列 16 描述符答疑 17 描述符优先级 18 软件开发规范 19 ...

    Ext Js权威指南(.zip.001

    4.4.3 所有继承类的基类:ext.base / 151 4.4.4 实现动态加载:ext.loader / 151 4.4.5 管理类的类:ext.classmanager / 159 4.4.6 类创建的总结 / 161 4.5 动态加载的路径设置 / 163 4.6 综合实例:页面...

    Visual C++实践与提高-COM和COM+篇『PDF』

    9.4.2 添加MFC ActiveX Form ClassWizard AppWizard 9.4.3 创建timesheet控件并添加MSFlexGird控件 9.4.4 编辑timesheet控件的单元格 9.4.5 创建并测试timesheet控件 9.5 用ATL开发ActiveX控件——例程AtlTickerCtrl...

    ZendFramework中文文档

    7.7.7. 继承(Subclassing)动作控制器 7.8. 动作助手 7.8.1. 介绍 7.8.2. 初始化助手 7.8.3. 助手经纪人 7.8.4. 内建的动作助手 7.8.4.1. 动作堆栈(助手) 7.8.4.2. AutoComplete 7.8.4.2.1. ...

    ssh(structs,spring,hibernate)框架中的上传下载

    Struts+Spring+Hibernate实现上传下载    本文将围绕SSH文件上传下载的主题,向您详细讲述如何开发基于SSH的Web程序。SSH各框架的均为当前最新版本:  •Struts 1.2  •Spring 1.2.5  •Hibernate 3.0 ...

    ExtAspNet_v2.3.2_dll

    -修正Form不能自适应浏览器大小的改变(feedback:kaywood)(WorkItem#6309)。 -增加重载方法Alert.Show(message, title, icon)(feedback:TheBox)(WorkItem#6353)。 -为容器控件(比如Panel,Region,Tab等)增加AJAX...

    ExtAspNet v2.2.1 (2009-4-1) 值得一看

    -修正Form不能自适应浏览器大小的改变(feedback:kaywood)(WorkItem#6309)。 -增加重载方法Alert.Show(message, title, icon)(feedback:TheBox)(WorkItem#6353)。 -为容器控件(比如Panel,Region,Tab等)增加AJAX...

Global site tag (gtag.js) - Google Analytics