AS3 - 错误1106,无法使用Timer

时间:2018-01-18 00:02:45

标签: actionscript-3 flash

我的计时器出了问题。计时器结束后,我想让一些实例消失。但是,我收到错误1106.错误表明if语句是空的,应该有代码。但是,有代码(quickTimerBegin函数。)

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

var F20quickTimer:Timer = new Timer(5000,1); 
F20quickTimer.addEventListener(TimerEvent.TIMER, quickTimerBegin); 

//checkmarks invisible at start 
F20next_btn.visible=false; 
F20chloroplastCheck_mc.visible=false; 
F20cytoplasmCheck_mc.visible=false; 
F20mitochondriaCheck_mc.visible=false; 
F20golgiCheck_mc.visible=false; 

//allows an instance to be dragged 
//allows an instance to be dropped 
F20chloroplasts_mc.addEventListener(MouseEvent.MOUSE_DOWN, drag); 
F20chloroplasts_mc.addEventListener(MouseEvent.MOUSE_UP, dropChloroplast); 
F20cytoplasm_mc.addEventListener(MouseEvent.MOUSE_DOWN, drag); 
F20cytoplasm_mc.addEventListener(MouseEvent.CLICK, dropCytoplasm); 
F20mitochondria_mc.addEventListener(MouseEvent.MOUSE_DOWN, drag); 
F20mitochondria_mc.addEventListener(MouseEvent.MOUSE_UP, dropMitochondria); 
F20golgi_mc.addEventListener(MouseEvent.MOUSE_DOWN, drag); 
F20golgi_mc.addEventListener(MouseEvent.MOUSE_UP, dropGolgi);  

错误就在这里

**if((F20chloroplasts_mc.visible==true)&&(F20cytoplasmCheck_mc.visible==true)&&(F20mitochondriaCheck_mc.visible==true)&&(F20golgiCheck_mc.visible==true))
{
    function quickTimerBegin(event:TimerEvent):void{
        F20next_btn.visible=true; 
    }
}**

其余代码

//when an instance is clicked on, it will be dragged 
function drag(event:MouseEvent):void 
{
    event.target.startDrag(); 
    F20output_txt.text = ""; 
}

//when baseball_mc hits baseballPlayer_mc, a checkmark will appear 
function dropChloroplast(event:MouseEvent):void 
{
    F20chloroplasts_mc.stopDrag(); 

    if(F20chloroplasts_mc.hitTestObject(F20chloroplastBox))
    {
        F20chloroplastCheck_mc.visible = true; 
        F20chloroplasts_mc.x=356; 
        F20chloroplasts_mc.y=539.45; 
        F20chloroplasts_mc.removeEventListener(MouseEvent.MOUSE_DOWN, drag); 
    }
    //will return baseball_mc to original position if it does not hit baseballPlayer_mc 
    else 
    {
        F20chloroplasts_mc.x = 618.70; 
        F20chloroplasts_mc.y= 167.75; 
    }
}

//when tennisbal_mc hits tennisPlayer_mc, a checkmark will appear 
function dropCytoplasm(event:MouseEvent):void 
{
    F20cytoplasm_mc.stopDrag(); 

    if(F20cytoplasm_mc.hitTestObject(F20cytoplasmBox))
    {
        F20cytoplasmCheck_mc.visible = true; 
        F20cytoplasm_mc.x=354.25; 
        F20cytoplasm_mc.y=403.20; 
        F20cytoplasm_mc.removeEventListener(MouseEvent.MOUSE_DOWN, drag); 
    }
    //will return tennisball_mc to original position if it does not hit tennisPlayer_mc 
    else 
    {
        F20cytoplasm_mc.x = 623.65; 
        F20cytoplasm_mc.y= 272.60; 
    }
}

//when soccerball_mc hits soccerPlayer_mc, a checkmark will appear 
function dropMitochondria(event:MouseEvent):void 
{
    F20mitochondria_mc.stopDrag(); 

    if(F20mitochondria_mc.hitTestObject(F20mitochondriaBox))
    {
        F20mitochondriaCheck_mc.visible = true; 
        F20mitochondria_mc.x=357.15; 
        F20mitochondria_mc.y=292.45; 
        F20mitochondria_mc.removeEventListener(MouseEvent.MOUSE_DOWN, drag); 
    }
    //returns soccerball_mc to original position if it does not hit soccerPlayer_mc 
    else 
    {
        F20mitochondria_mc.x = 621.60; 
        F20mitochondria_mc.y= 394.50; 
    }
}

//when footbal_mc hits footballPlayer_mc, a checkamrk will appear 
function dropGolgi(event:MouseEvent):void 
{
    F20golgi_mc.stopDrag(); 

    if(F20golgi_mc.hitTestObject(F20golgiBox))
    {
        F20golgiCheck_mc.visible = true; 
        F20golgi_mc.x=353.50; 
        F20golgi_mc.y=150; 
        F20golgi_mc.removeEventListener(MouseEvent.MOUSE_DOWN, drag); 
    }
    //returns footbal_mc to original position if it does not hit footballPlayer_mc 
    else 
    {
        F20golgi_mc.x = 622.85; 
        F20golgi_mc.y= 535.15; 
    } 
}

我感谢所有的帮助!

1 个答案:

答案 0 :(得分:1)

我认为你是以错误的方式实施这项功能。
它应该是这样的

function quickTimerBegin(event:TimerEvent):void{
    if((F20chloroplasts_mc.visible==true)&&(F20cytoplasmCheck_mc.visible==true)&&(F20mitochondriaCheck_mc.visible==true)&&(F20golgiCheck_mc.visible==true))
    {
        F20next_btn.visible=true; 
    }
}

您可以控制计时器何时以F20quickTimer.start()开始。
如果F20quickTimer.reset()未满足条件,您可能需要重新启动计时器然后重新启动..或者增加 repeatCount ..
如果您知道documentation

,这将很容易