倒计时的确认窗体(Flex组件)

it2024-11-06  11

Flex组件-倒计时的确认窗体的代码

Confirm.as package {    import flash.events.Event;    import flash.events.MouseEvent;    import flash.events.TimerEvent;    import flash.utils.Timer;        import mx.containers.Canvas;    import mx.containers.ControlBar;    import mx.containers.Panel;    import mx.controls.Button;    import mx.controls.Text;    [Event(name="confirm", type="flash.events.Event")]    [Event(name="cancel", type="flash.events.Event")]    public class Confirm extends Canvas {        public var panel:Panel;        public var controlBar:ControlBar        public var okButton:Button;        public var cancelButton:Button;        [Bindable] public var panelWidth:int;        [Bindable] public var panelHeight:int;        [Bindable] public var title:String;        [Bindable] public var text:String;        [Bindable] public var okButtonLabel:String = "OK";        [Bindable] public var cancelButtonLabel:String = "OK";        public var timerCount:int;        private var timer:Timer;        /**         * A pop up window that acts as a confirmation window with a coutdown timer before          * the user is allowed to click OK. The idea behind this was to help force a user          * to read the notice being displayed.         *          * @title String    The title of the pop-up panel             * @text String        The text in the body of the pop-up         * @timeout int        Number of seconds before the user can click OK         * @width int        width of the pop-up panel         * @height int        height of the pop-up panel         *          * @event confirm    This event is thrown when the user clicks OK         * @event cancel    This event is thrown when the user clicks Cancel         */        public function Confirm(title:String="Confirmation", text:String="Are You Sure?", timeout:int=5, width:int=355, height:int=165) {            super();            this.percentWidth = 100;            this.percentHeight = 100;            this.timerCount = timeout;            this.panelWidth = width;            this.panelHeight = height;            this.title = title;            this.text = text;            this.setStyle("backgroundColor", "#FFFFFF");            this.setStyle("backgroundAlpha", ".75");            panel = new Panel();            panel.title = this.title;            panel.width = this.panelWidth;            panel.height = this.panelHeight;            panel.layout = "vertical";            panel.setStyle("borderAlpha", 1);            panel.setStyle("horizontalCenter", 0);            panel.setStyle("verticalCenter", 0);            panel.setStyle("verticalScrollPolicy", "off");            panel.setStyle("horizontalScrollPolicy", "off");            panel.setStyle("paddingTop", 5);            panel.setStyle("paddingLeft", 5);            panel.setStyle("paddingBottom", 5);            panel.setStyle("paddingRight", 5);            panel.setStyle("verticalAlign", "middle");            panel.setStyle("horizontalAlign", "left");            var dsp_text:Text = new Text();            dsp_text.percentWidth = 100;            dsp_text.percentHeight = 100;            dsp_text.setStyle("fontSize", "11");            dsp_text.text = this.text;            controlBar = new ControlBar();            controlBar.setStyle("horizontalAlign", "center");            cancelButton = new Button();            cancelButton.label = "Cancel";            cancelButton.addEventListener(MouseEvent.CLICK, clickCancel);            okButton = new Button();            okButton.width = 136;            okButton.label = "OK";            okButton.enabled = false;            okButton.setStyle("disabledColor", "#888888")            okButton.addEventListener(Event.ADDED_TO_STAGE, startTimer);            okButton.addEventListener(MouseEvent.CLICK, clickOK);            controlBar.addChild(cancelButton);            controlBar.addChild(okButton);            panel.addChild(dsp_text);            panel.addChild(controlBar);            this.addChild(panel);        }        private function startTimer(event:Event):void {            this.okButton.enabled = false;                if (this.timer == null) {                this.timer = new Timer(1000, timerCount);                this.timer.addEventListener(TimerEvent.TIMER, timeoutCounter);            } else {                this.timer.reset()            }                this.okButton.label = "OK (please wait " + timerCount + ")";                this.timer.start();        }            private function timeoutCounter(event:TimerEvent):void {            var timeLeft:int = timer.repeatCount - timer.currentCount;                if (timeLeft) {                this.okButton.label = "OK (please wait " + timeLeft + ")";            } else {                this.okButton.enabled = true;                this.okButton.label = "OK";            }        }            private function clickOK(event:MouseEvent):void {            this.dispatchEvent(new Event("confirm"));        }            private function clickCancel(event:MouseEvent):void {            this.dispatchEvent(new Event("cancel"));        }    }}

 

 

示例源文件:下载

转自:

http://blog.empiregpservices.com/FlexSource/CookBook-CountDownOKButton/index.html

推荐博客:http://blog.empiregpservices.com/

转载于:https://www.cnblogs.com/wuhenke/archive/2009/10/31/1593580.html

相关资源:asp.net知识库
最新回复(0)