Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flash Flex定时器示例_Flash_Actionscript 3_Apache Flex_Timer_Flex3 - Fatal编程技术网

Flash Flex定时器示例

Flash Flex定时器示例,flash,actionscript-3,apache-flex,timer,flex3,Flash,Actionscript 3,Apache Flex,Timer,Flex3,我试图在flex中使用计时器。我提到了这个例子: 以下是我想要实现的目标: 我想启动计时器,显示从计时器开始经过的分钟数 起动。它应该独立于您所在的区域( 无论你在哪个区域,定时器都应该工作正常 每个区域) 计时器应该继续,除非我想点击某个按钮 在警报框中以分钟为单位显示经过的时间,然后计时器应从0开始重新启动 我试过我的例子,但效果不好 <?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http:

我试图在flex中使用计时器。我提到了这个例子:

以下是我想要实现的目标:

我想启动计时器,显示从计时器开始经过的分钟数 起动。它应该独立于您所在的区域( 无论你在哪个区域,定时器都应该工作正常 每个区域)

计时器应该继续,除非我想点击某个按钮 在警报框中以分钟为单位显示经过的时间,然后计时器应从0开始重新启动

我试过我的例子,但效果不好

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
                layout="vertical"
                verticalAlign="middle"
                backgroundColor="white"
                creationComplete="init()">

    <mx:Script>
        <![CDATA[
            import flash.events.TimerEvent;
            import flash.utils.Timer;

            import mx.controls.Alert;
            private const TIMER_INTERVAL:Number = 10;

            private var baseTimer:int;

            private var t:Timer;

            private function init():void {
                t = new Timer(TIMER_INTERVAL);
                t.addEventListener(TimerEvent.TIMER, updateTimer);
            }

            private function updateTimer(evt:TimerEvent):void {
                var d:Date = new Date(getTimer()-baseTimer);
                var min:String = (d.minutes).toString();
                var sec:String = (d.seconds).toString();

                counter.text = String(min+"."+sec);
            }

            private function startTimer():void {

                baseTimer = getTimer();
                t.start();
            }

            private function stopTimer():void {
                t.stop();
            }
        ]]>
    </mx:Script>

    <mx:ApplicationControlBar dock="true">
        <mx:Button label="Start timer" click="startTimer()" />
        <mx:Button label="Stop timer" click="stopTimer()" />
    </mx:ApplicationControlBar>

    <mx:Label id="counter" fontSize="96" />
</mx:Application>


有人能告诉我是什么问题吗?如何解决

编辑:
如果我在我的电脑上运行这个例子,计时器从30.0开始,直到达到59.59,然后它返回到0.0,然后再次开始……现在我想要的是从0.0开始,继续计数分钟,直到单击某个按钮。。。这应该适用于任何时区

您所指的示例是,对于您的特定问题,使事情变得有点复杂。下面是一个小示例,说明如何使用简单的
计时器显示分钟数:

private const TIMER_INTERVAL:Number = 1000*60;
private var t:Timer;

private function init():void {
    t = new Timer(TIMER_INTERVAL);
    t.addEventListener(TimerEvent.TIMER, updateTimer);
    counter.text = "0";
}

private function updateTimer(evt:TimerEvent):void {

    counter.text = String(t.currentCount);
}

private function startTimer():void {

    t.start();
}

private function stopTimer():void {

    t.stop();

    // if you want the timer to reset make sure to reset your text also
    /*
    t.reset();
    counter.text = "0";
    */
}

你所指的例子是,针对你的特殊问题使事情变得有点复杂。下面是一个小示例,说明如何使用简单的
计时器显示分钟数:

private const TIMER_INTERVAL:Number = 1000*60;
private var t:Timer;

private function init():void {
    t = new Timer(TIMER_INTERVAL);
    t.addEventListener(TimerEvent.TIMER, updateTimer);
    counter.text = "0";
}

private function updateTimer(evt:TimerEvent):void {

    counter.text = String(t.currentCount);
}

private function startTimer():void {

    t.start();
}

private function stopTimer():void {

    t.stop();

    // if you want the timer to reset make sure to reset your text also
    /*
    t.reset();
    counter.text = "0";
    */
}

您的用例不需要使用Date()和/或时区。您所需要做的就是计算经过的秒数,计时器为您提供了一种简单的方法:将间隔设置为1000(每秒一次计数),然后使用
Timer.currentCount
。然后,您所需要做的就是计算显示的分和秒。下面是一个可以合并到现有mxml中的实现:

private function init():void {
    t = new Timer(1000);
    t.addEventListener(TimerEvent.TIMER, updateTimer);
}

// it's good practice to separate event handler from functional method
private function updateTimer(evt:TimerEvent):void {
    display (t.currentCount);
}

private function display ( count : int ) : void {
    var minutes : int = count / 60; // divide by 60 to get the minutes
    var seconds : int = count % 60; // use modulo operator to get the "rest"
    var min : String = minutes < 10 ? "0" + minutes : "" + minutes; // add leading zero if necessary
    var sec : String = seconds < 10 ? "0" + seconds : "" + seconds;

    counter.text = min+":"+sec; // no need to cast to String if you use "" + something
}

private function startTimer():void {
    t.start();
}

private function stopTimer():void {
    t.stop();
    t.reset();
    display (0); // reset the display
}
private function init():void{
t=新定时器(1000);
t、 addEventListener(TimerEvent.TIMER、updateTimer);
}
//将事件处理程序与函数方法分离是一种很好的做法
私有函数updateTimer(evt:TimerEvent):void{
显示(t.currentCount);
}
专用函数显示(计数:int):无效{
var minutes:int=count/60;//除以60得到分钟数
var seconds:int=count%60;//使用模运算符获取“rest”
var min:String=minutes<10?“0”+minutes:“+minutes;//必要时添加前导零
变量秒:字符串=秒<10?“0”+秒:“+秒;
counter.text=min+“:”+sec;//如果您使用“+某物”,则无需强制转换为字符串
}
私有函数startTimer():void{
t、 start();
}
私有函数stopTimer():void{
t、 停止();
t、 重置();
显示(0);//重置显示
}

您的用例不需要使用Date()和/或时区。您所需要做的就是计算经过的秒数,计时器为您提供了一种简单的方法:将间隔设置为1000(每秒一次计数),然后使用
Timer.currentCount
。然后,您所需要做的就是计算显示的分和秒。下面是一个可以合并到现有mxml中的实现:

private function init():void {
    t = new Timer(1000);
    t.addEventListener(TimerEvent.TIMER, updateTimer);
}

// it's good practice to separate event handler from functional method
private function updateTimer(evt:TimerEvent):void {
    display (t.currentCount);
}

private function display ( count : int ) : void {
    var minutes : int = count / 60; // divide by 60 to get the minutes
    var seconds : int = count % 60; // use modulo operator to get the "rest"
    var min : String = minutes < 10 ? "0" + minutes : "" + minutes; // add leading zero if necessary
    var sec : String = seconds < 10 ? "0" + seconds : "" + seconds;

    counter.text = min+":"+sec; // no need to cast to String if you use "" + something
}

private function startTimer():void {
    t.start();
}

private function stopTimer():void {
    t.stop();
    t.reset();
    display (0); // reset the display
}
private function init():void{
t=新定时器(1000);
t、 addEventListener(TimerEvent.TIMER、updateTimer);
}
//将事件处理程序与函数方法分离是一种很好的做法
私有函数updateTimer(evt:TimerEvent):void{
显示(t.currentCount);
}
专用函数显示(计数:int):无效{
var minutes:int=count/60;//除以60得到分钟数
var seconds:int=count%60;//使用模运算符获取“rest”
var min:String=minutes<10?“0”+minutes:“+minutes;//必要时添加前导零
变量秒:字符串=秒<10?“0”+秒:“+秒;
counter.text=min+“:”+sec;//如果您使用“+某物”,则无需强制转换为字符串
}
私有函数startTimer():void{
t、 start();
}
私有函数stopTimer():void{
t、 停止();
t、 重置();
显示(0);//重置显示
}

你应该知道问题出在哪里!怎么了?我们能帮忙吗?“它不工作”真的没有任何线索。如果我在我的电脑上运行这个例子,计时器从30.0开始,直到达到59.59,然后返回到0.0,然后再次开始……我想要的是从0.0开始,继续计数分钟,直到点击某个按钮。。。这应该适用于任何时区。你应该是那个知道问题所在的人!怎么了?我们能帮忙吗?“它不工作”真的没有任何线索。如果我在我的电脑上运行这个例子,计时器从30.0开始,直到达到59.59,然后返回到0.0,然后再次开始……我想要的是从0.0开始,继续计数分钟,直到点击某个按钮。。。这应该适用于任何时区。这是否适用于任何时区?我的意思是UTC没有问题?当它超过60分钟标记时,我希望它继续以分钟为单位显示时间。。像这样<代码>61:15
。。61分钟,15秒。对于本例,这两种情况都是正确的:当您仅计算计时器被调用的次数时,就没有UTC。由于没有“小时”,分钟数将不断增加。谢谢你的回答:)。。。我正在运行你的代码。。一旦没有问题,我会接受你的回答。。不管怎样,这个答案已经从我这里得到+1了。不管时区如何,这个方法都有效吗?我的意思是UTC没有问题?当它超过60分钟标记时,我希望它继续以分钟为单位显示时间。。像这样<代码>61:15
。。61分钟,15秒。对于本例,这两种情况都是正确的:当您仅计算计时器被调用的次数时,就没有UTC。由于没有“小时”,分钟数将不断增加。谢谢你的回答:)。。。我正在运行你的代码。。一旦没有问题,我会接受你的回答。。无论如何,这个答案已经得到我的+1了..我运行了你的代码。。但是,还是在船尾