Home > Back-end >  1084: Syntax error: expecting rightparen before colon
1084: Syntax error: expecting rightparen before colon

Time:04-26

I'm new to ActionScript and I'm confused about these two errors. I already have some prior coding experience from other languages.

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

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

This is my code.

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
        }
    }
}

Lines 78 and 85 are the moveCharacter(evt:KeyboardEvent) function.

I'm not sure where the problem is, I can't see one, unless I'm blind.

CodePudding user response:

The : character has a limited amount of uses in AS3 (most of them are various type declarations):

// 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/" />;

This is neither of them, hence the syntax error.

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

You should probably explain what kind of logic you wanted to code, because it is not clear what are you trying to do here.

CodePudding user response:

The function moveCharacter was being called but you were typing a parameter declaration where the argument goes.

moveCharacter(evt:KeyboardEvent)

Your code doesn't have a keyboard event to pass at this spot. moveCharacter should be refactored to accept either "left" or "right" as arguments so that it doesnt require a keyboard event.

It's inherently unclear which direction the character should be moved from the time function. I assume the moveCharacter function is incomplete and missing forward and backward movement.

function moveCharacter(direction:String):void
{
    direction = direction.toLowerCase();
    
    if (direction == "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 (direction == "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);
        }
    }
    // TODO: Implement forward and backwards

}

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