1084:语法错误:在冒号之前需要右括号

问题描述

我是 ActionScript 的新手,我对这两个错误感到困惑。我之前已经有一些其他语言的编码经验。

Scene 1,Layer 'Actions',Frame 1,Line 78,Column 20 1084: Syntax error: expecting rightparen before colon.

Scene 1,Line 85,Column 20 1084: Syntax error: expecting rightparen before colon.

这是我的代码

function moveCharacter(evt:KeyboardEvent):void
{
    if (evt.keyCode == Keyboard.RIGHT)
    {
        eggHead.scaleX = 1; //flip right
        eggHead.x += 10;
        
        //cycle through frames
        if (eggHead.currentFrame == 9)
        {
             eggHead.gotoAndStop(2);
        }
        else
        {
            eggHead.gotoAndStop(eggHead.currentFrame+1);
        }
    }
        
    if (evt.keyCode == Keyboard.LEFT)
    {
        eggHead.scaleX = -1; //flip left
        eggHead.x -= 10;
        
        //cycle through frames
        if (eggHead.currentFrame == 9)
        {
            eggHead.gotoAndStop(2);
        }
        else
        {
            eggHead.gotoAndStop(eggHead.currentFrame+1);
        }
    }
}

function timing(evt:TimerEvent):void
{
    timestep += 1; //increment counter
    if (run)
    { //only if run = true is shift key has been pressed
        moveCharacter(evt:KeyboardEvent)
        {
            timestep = 0; //reset the counter
        }
    }
    else if (timestep == 2)
    {
        moveCharacter(evt:KeyboardEvent)
        {
            timestep = 0; //reset the counter
        }
    }
}

第 78 行和第 85 行是 moveCharacter(evt:KeyboardEvent) 函数

我不确定问题出在哪里,我看不到一个,除非我是瞎子。

解决方法

: 字符在 AS3 中的用途有限(大多数是各种类型声明):

// Variable declaration.
var a:int;

// Variable declaration within a loop statement.
for (var i:int = 0; i < 10; i++)
{
    // ...
}

// Ternary operator.
a = (Math.random() > 0.5)? 1: 0;

// Function declaration (both arguments and return type).
function convert(j:int,k:Number):String
{
    return j + "_" + k;
}

// XML NameSpaces.
var x:XML = <soap:Envelope xmlns:soap="http://.../envelope/" />;

这两者都不是,因此出现了语法错误。

if (run)
{
    moveCharacter(evt:KeyboardEvent)
    {
        timeStep = 0; //reset the counter
    }
}

您可能应该解释一下您想编写什么样的逻辑,因为不清楚您在这里要做什么。