0
import flash.events.MouseEvent;
import flash.events.Event;
import flash.utils.Timer;
import flash.events.TimerEvent;


var timer:Timer = new Timer(1000);


start_btn.buttonMode = true;
stop_btn.buttonMode = true;
start_btn.addEventListener(MouseEvent.CLICK, onStart, false, 0, true);
timer.addEventListener(TimerEvent.TIMER, onTimer, false, 0, true);
//stage.addEventListener(Event.ENTER_FRAME, onEnter, false, 0, true);
function onStart(evt:MouseEvent):void
{
    var minutes:Number = Number(min_txt.text);
    var seconds:Number = Number(sec_txt.text);
    timer.start();
}

function onTimer(evt:TimerEvent):void
{
    minutes--;
    trace("Timer Triggered!!");
}

那么我该如何做到这一点,以使“分钟-”起作用..因为变量在一个单独的函数中..

(或给我另一种方式)..

谢谢..

4

1 回答 1

1

如果在函数中声明变量,则为局部变量。您不能访问变量其他功能,其他范围。但是如果你在全局变量中声明。随处可用。

简单的方法,如果你全局声明变量。它是可用的。

import flash.events.MouseEvent;
import flash.events.Event;
import flash.utils.Timer;
import flash.events.TimerEvent;

var timer:Timer = new Timer(1000);

start_btn.buttonMode = true;
stop_btn.buttonMode = true;
start_btn.addEventListener(MouseEvent.CLICK, onStart, false, 0, true);
timer.addEventListener(TimerEvent.TIMER, onTimer, false, 0, true);
//stage.addEventListener(Event.ENTER_FRAME, onEnter, false, 0, true);
var minutes:Number;
function onStart(evt:MouseEvent):void
{
  minutes = Number(min_txt.text);
  var seconds:Number = Number(sec_txt.text);
  timer.start();
}

function onTimer(evt:TimerEvent):void
{
  minutes--;
  trace("Timer Triggered!!");
}
于 2013-02-24T15:13:32.347 回答