Actionscript 3 闪现错误-1013:私有属性只能用于类属性定义
我正试图做一个计时器倒计时,我相信我有所有的部件在那里,它只是不断给我这个错误,每当我测试它 知道发生了什么吗Actionscript 3 闪现错误-1013:私有属性只能用于类属性定义,actionscript-3,animate-cc,Actionscript 3,Animate Cc,我正试图做一个计时器倒计时,我相信我有所有的部件在那里,它只是不断给我这个错误,每当我测试它 知道发生了什么吗 package { import flash.display.MovieClip; import flash.events.TimerEvent; import flash.utils.Timer; public class MainTimer extends MovieClip { private var currentMin:i
package
{
import flash.display.MovieClip;
import flash.events.TimerEvent;
import flash.utils.Timer;
public class MainTimer extends MovieClip {
private var currentMin:int;
private var currentSec:int;
private var oneSecondTimer:Timer = new Timer (1000,1);
public var timeHasStopped:Boolean=false;
public function MainTimer() {
// constructor code
trace("the main timer is here");
currentMin = 2;
currentSec = 5;
minBox.text = String(currentMin);
if(currentSec < 10)
{
secBox.text = "0" + String(currentSec);
}
else {
secBox.text = String(currentSec);
}
oneSecondTimer.addEventListener(TimerEvent.TIMER_COMPLETE, onTimerComplete);
oneSecondTimer.start();
private function onTimerComplete(event:TimerEvent):void {
currentSec = currentSec -1;
if(currentSec <0)
{
currentSec =59;
currentMin -=1;
} //end if
if(currentMin < 0) {
currentMin =0;
currentSec =0;
timerHasStopped = true;
}
else
{
oneSecondTimer.start();
}
minBox.text =String(currentMin);
secBox.text =String(currentSec);
if(currentSec <10)
{
secBox.text = "0" + String(currentSec);
}
}
} // Ends Function
} // Ends Class
} // Ends Package
包
{
导入flash.display.MovieClip;
导入flash.events.TimerEvent;
导入flash.utils.Timer;
公共类MainTimer扩展了MovieClip{
私有变量currentMin:int;
私有var-currentSec:int;
私有变量oneSecondTimer:Timer=新定时器(1000,1);
公共var:Boolean=false;
公共函数MainTimer(){
//构造代码
跟踪(“主计时器在此”);
currentMin=2;
currentSec=5;
minBox.text=字符串(currentMin);
如果(当前秒<10)
{
secBox.text=“0”+字符串(当前秒);
}
否则{
secBox.text=字符串(当前秒);
}
oneSecondTimer.addEventListener(TimerEvent.TIMER\u COMPLETE,onTimerComplete);
oneSecondTimer.start();
私有函数onTimerComplete(事件:TimerEvent):无效{
currentSec=currentSec-1;
如果(currentSec函数onTimerComplete
位于函数MainTimer
内;它不是类成员,因此private
关键字不适用。函数onTimerComplete
位于函数MainTimer
内;它不是类成员,因此private
关键字不适用。)可折叠。在创建另一个新函数之前,函数必须有大括号,并且必须用大括号关闭。您的//Ends函数应该放在第行的后面
从那时起,您可以定义其他第二个函数函数onTimerComplete
如果您缩进代码,这样您就可以很容易地看到事情的开始和结束(使用TAB
key)
缩进代码的示例如下(文本已删除),请查看此结构如何使大括号更容易查看,从而发现任何缺少或多余的大括号
public function MainTimer()
{
// constructor code
.......
if(currentSec < 10)
{
.......
}
else
{
.......
}
.......
} //Ends function called MainTimer
private function onTimerComplete(event:TimerEvent):void
{
.......
if(currentSec <0)
{
.......
} //end if
if(currentMin < 0)
{
.......
}
else
{
.......
}
.......
if(currentSec <10)
{
.......
}
} //Ends function called onTimerComplete
公共函数MainTimer()
{
//构造代码
.......
如果(当前秒<10)
{
.......
}
其他的
{
.......
}
.......
}//结束名为MainTimer的函数
私有函数onTimerComplete(事件:TimerEvent):无效
{
.......
if(currentSec在创建另一个新函数之前,一个函数必须有一个大括号,并且必须用}
关闭。您的}//Ends函数应该放在oneSecondTimer.start()行之后
从那时起,您可以定义其他第二个函数函数onTimerComplete
如果您缩进代码,这样您就可以很容易地看到事情的开始和结束(使用TAB
key)
缩进代码的示例如下(文本已删除),请查看此结构如何使大括号更容易查看,从而发现任何缺少或多余的大括号
public function MainTimer()
{
// constructor code
.......
if(currentSec < 10)
{
.......
}
else
{
.......
}
.......
} //Ends function called MainTimer
private function onTimerComplete(event:TimerEvent):void
{
.......
if(currentSec <0)
{
.......
} //end if
if(currentMin < 0)
{
.......
}
else
{
.......
}
.......
if(currentSec <10)
{
.......
}
} //Ends function called onTimerComplete
公共函数MainTimer()
{
//构造代码
.......
如果(当前秒<10)
{
.......
}
其他的
{
.......
}
.......
}//结束名为MainTimer的函数
私有函数onTimerComplete(事件:TimerEvent):无效
{
.......
如果(当前秒)