startFunction的任务是调用doFunction 3秒,然后停止。不幸的是,没有编译器错误就无法工作。只是空白输出。可能是一些容易犯的错误,但我是初学者,因为几个小时就无法找到解决方案。我已经删除了代码以使其更清晰,但可以在必要时进行粘贴。
package {
//all imports
public class MemoryPuzzles extends MovieClip{
//all variables
public function MemoryPuzzles():void {//first function
//function memory puzzles
}//first function end end
public function startFunction():void//beginning of second function in the single class
{
trace("start function works");
startTime = getTimer();
if( (getTimer() - startTime)<3000 ){
addEventListener(Event.ENTER_FRAME, doFunction);
} else {
removeEventListener(Event.ENTER_FRAME, doFunction);
}
function doFunction(e:Event):void
{
trace("do function works");
}//end of dofunction
}//end of startfunction
}//class end
}//import end
由于
答案 0 :(得分:0)
参考以下代码。我测试了。
package
{
import flash.display.MovieClip;
import flash.utils.getTimer;
public class MemoryPuzzles extends MovieClip
{
public function MemoryPuzzles():void
{
startFunction();
}
public function startFunction():void
{
trace("start function works");
var startTime = getTimer();
addEventListener(Event.ENTER_FRAME, doFunction);
function doFunction(e:Event):void
{
trace("time: " + (int)(getTimer()-startTime));
if((int)(getTimer()-startTime)>=3000)
{
removeEventListener(Event.ENTER_FRAME, doFunction);
trace("ended");
}
}
}
}
}