Button关于鼠标按住事件连续发生的Demo

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white" viewSourceURL="srcview/index.html">

    <mx:Script>
        <![CDATA[
            import mx.core.UIComponent;

            private function moveLeft(target:UIComponent):void {
                var t1:int = target.x - 10;
                var t2:int = 0;
                target.x = Math.max(t1, t2);
            }

            private function moveRight(target:UIComponent):void {
                var t1:int = target.x + 10;
                var t2:int = Application.application.width - target.width;
                target.x = Math.min(t1, t2);
            }
        ]]>
    </mx:Script>

    <mx:Box id="box" width="100" height="100" backgroundColor="red" />

    <mx:HBox>
        <mx:Button id="leftButton"
                label="left"
                autoRepeat="true"
                repeatDelay="{button_repeatDelay.value}"
                repeatInterval="{button_repeatInterval.value}"
                buttonDown="moveLeft(box)" />

        <mx:Button id="rightButton"
                label="right"
                autoRepeat="true"
                repeatDelay="{button_repeatDelay.value}"
                repeatInterval="{button_repeatInterval.value}"
                buttonDown="moveRight(box)" />
    </mx:HBox>

    <mx:Form>
        <mx:FormItem label="repeatDelay ({button_repeatDelay.value}):">
            <mx:HSlider id="button_repeatDelay"
                    minimum="50"
                    maximum="950"
                    value="100"
                    snapInterval="50"
                    tickInterval="100"
                    dataTipPrecision="0" />
        </mx:FormItem>
        <mx:FormItem label="repeatInterval ({button_repeatInterval.value}):">
            <mx:HSlider id="button_repeatInterval"
                    minimum="10"
                    maximum="910"
                    value="10"
                    snapInterval="10"
                    tickInterval="100"
                    dataTipPrecision="0" />
        </mx:FormItem>
    </mx:Form>

</mx:Application>

 

接下来的例子演示了Flex中通过调用autoRepeat属性和buttonDown事件,创建一个自动重复用户按下时动作按钮(Button)。比较拗口,简单的说就是用户按下鼠标,并且保持按下状态,该按钮一直执行鼠标按下时的动作,直到结束。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值