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!!");
}
那么我该怎么做才能让“分钟 - ”工作..变量是单独的功能..
(或给我另一种方式)..
谢谢..
答案 0 :(得分: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!!");
}