Синтаксическая ошибка rightparen перед colon

why do I get the error: syntax error: expecting rightparen before colon on line 7???

var myXML:XML=new XML();
myXML.ignoreWhite = true;
myXML.onLoad = function(succes:Boolean):void{
    var colors:XML = this.firstChild;
    for (x=0;x<colors.childNodes.length;x++){
        var node:XMLNode = colors.childNodes[x];
        colors_cb.addItem{(label:node.attributes.label,data:node.attributes.data)};

    }
}
myXML.load("colors.xml");

asked Nov 15, 2013 at 12:50

user2852398's user avatar

you inverted { and ( in your function call addItem
try:

colors_cb.addItem({label:node.attributes.label,data:node.attributes.data});

it seems you are using ActionScript2 methods for XML class. Try this:

// create a loader for your XML
var xmlLoader:URLLoader = new URLLoader();
// Lister for complete event
xmlLoader.addEventListener( Event.COMPLETE, _onLoadComplete );
// start loading
xmlLoader.load( 'colors.xml' );

// handle complete loading
function _onLoadComplete( e:Event ):void
{
    // remove event listener
    xmlLoader.removeEventListener( Event.COMPLETE, _onLoadComplete );
    // set XML to ignore white spaces
    XML.ignoreWhitespace = true;
    // create XML with the loaded data
    var colors:XML = new XML( e.target.data );

    // add your items to your color_cb
    for (var x:int=0; x<colors.childNodes.length; x++ )
    {
        var node:XMLNode = colors.childNodes[x];
        color_cb.addItem({label:node.attributes.label,data:node.attributes.data});
    }
}

answered Nov 15, 2013 at 13:01

Benjamin BOUFFIER's user avatar

2

Thanks, I tried, but then I got error 1180 and 1120. I’m actually using the tutorial from Scores, HUDs, and User Interface | Flash Game Development Tutorials — As Gamer to create my own version of shooting game (there is a download link for the whole game, including a few more as files). The tutorial comes with 1 enemy (Stinger) and 1 level, it also comes with a score system, so I’m trying to create more enemies (Stinger 2 and 3) and levels. I’m able to add more enemies to the array, and want to make them only spawn between specific scores. Here’s the original game engine.as coding:

  1. package com.asgamer.basics1
  2. {
  3.   import flash.display.MovieClip;
  4.   import flash.display.Stage;
  5.   import flash.events.Event;
  6.   public class Engine extends MovieClip
  7.   {
  8.   private var numStars:int = 80;
  9.   public static var enemyList:Array = new Array();
  10.   private var ourShip:Ship;
  11.   private var scoreHUD:ScoreHUD;
  12.   public function Engine() : void
  13.   {
  14.   ourShip = new Ship(stage);
  15.   ourShip.x = stage.stageWidth / 2;
  16.   ourShip.y = stage.stageHeight / 2;
  17.   ourShip.addEventListener(«hit», shipHit, false, 0, true);
  18.   stage.addChild(ourShip);
  19.   scoreHUD = new ScoreHUD(stage);
  20.   stage.addChild(scoreHUD);
  21.   for (var i:int = 0; i < numStars; i++)
  22.   {
  23.   stage.addChildAt(new Star(stage), stage.getChildIndex(ourShip));
  24.   }
  25.   addEventListener(Event.ENTER_FRAME, loop, false, 0, true);
  26.   }
  27.   private function loop(e:Event) : void
  28.   {
  29.   if (Math.floor(Math.random() * 90) == 5)
  30.   {
  31.   var enemy:Stinger = new Stinger(stage, ourShip);
  32.   enemy.addEventListener(Event.REMOVED_FROM_STAGE, removeEnemy, false, 0, true);
  33.   enemy.addEventListener(«killed», enemyKilled, false, 0, true);
  34.   enemyList.push(enemy);
  35.   stage.addChild(enemy);
  36.   }
  37.   }
  38.   private function enemyKilled(e:Event)
  39.   {
  40.   scoreHUD.updateKills(1);
  41.   scoreHUD.updateScore(e.currentTarget.points);
  42.   }
  43.   private function removeEnemy(e:Event)
  44.   {
  45.   enemyList.splice(enemyList.indexOf(e.currentTarget), 1);
  46.   }
  47.   private function shipHit(e:Event)
  48.   {
  49.   scoreHUD.updateHits(1);
  50.   }
  51.   }
  52. }

And here’s the original scoreHUD.as coding:

  1. package com.asgamer.basics1
  2. {
  3.   import flash.display.MovieClip;
  4.   import flash.display.Stage;
  5.   import flash.text.TextField;
  6.   import flash.events.Event;
  7.   public class ScoreHUD extends MovieClip
  8.   {
  9.   private var stageRef:Stage;
  10.   public var s_score:Number = 0;
  11.   public var s_hits:Number = 0;
  12.   public var s_kills:Number = 0;
  13.   public function ScoreHUD(stageRef:Stage)
  14.   {
  15.   this.stageRef = stageRef;
  16.   kills.text = «0»;
  17.   hits.text = «0»;
  18.   score.text = «0»;
  19.   x = 10;
  20.   y = stageRef.stageHeight — height — 10;
  21.   }
  22.   public function updateKills(value:Number) : void
  23.   {
  24.   s_kills += value;
  25.   kills.text = String(s_kills);
  26.   }
  27.   public function updateHits(value:Number) : void
  28.   {
  29.   s_hits += value;
  30.   hits.text = String(s_hits);
  31.   }
  32.   public function updateScore(value:Number) : void
  33.   {
  34.   s_score += value;
  35.   score.text = String(s_score);
  36.   }
  37.   }
  38. }

I’ve made changes to the game engine.as but not the scoreHUD.as, here’s my version:

  1. package objects
  2. {
  3.   import flash.display.MovieClip;
  4.   import flash.display.Stage;
  5.   import flash.events.Event;
  6.   public class Engine extends MovieClip
  7.   {
  8.   private var numStars:int = 80;
  9.   public static var enemyList:Array = new Array();
  10.   private var ourShip:Ship;
  11.   private var scoreHUD:ScoreHUD;
  12.   public function Engine() : void
  13.   {
  14.   ourShip = new Ship(stage);
  15.   ourShip.x = stage.stageWidth / 2;
  16.   ourShip.y = stage.stageHeight / 2;
  17.   ourShip.addEventListener(«hit», shipHit, false, 0, true);
  18.   stage.addChild(ourShip);
  19.   scoreHUD = new ScoreHUD(stage);
  20.   stage.addChild(scoreHUD);
  21.   for (var i:int = 0; i < numStars; i++)
  22.   {
  23.   stage.addChildAt(new Star(stage), stage.getChildIndex(ourShip));
  24.   }
  25.   addEventListener(Event.ENTER_FRAME, loop, false, 0, true);
  26.   }
  27.   private function loop(e:Event) : void
  28.   {
  29.   if (s_score(value) < 10000)
  30.   {
  31.   if (Math.floor(Math.random() * 60) == 5)
  32.   {
  33.   var enemy:Stinger = new Stinger(stage, ourShip);
  34.   enemy.addEventListener(Event.REMOVED_FROM_STAGE, removeEnemy, false, 0, true);
  35.   enemy.addEventListener(«killed», enemyKilled, false, 0, true);
  36.   enemyList.push(enemy);
  37.   stage.addChild(enemy);
  38.   var enemy2:Stinger2 = new Stinger2(stage, ourShip);
  39.   enemy2.addEventListener(Event.REMOVED_FROM_STAGE, removeEnemy, false, 0, true);
  40.   enemy2.addEventListener(«killed», enemyKilled, false, 0, true);
  41.   enemyList.push(enemy2);
  42.   stage.addChild(enemy2);
  43.   var enemy3:Stinger3 = new Stinger3(stage, ourShip);
  44.   enemy3.addEventListener(Event.REMOVED_FROM_STAGE, removeEnemy, false, 0, true);
  45.   enemy3.addEventListener(«killed», enemyKilled, false, 0, true);
  46.   enemyList.push(enemy3);
  47.   stage.addChild(enemy3);
  48.   }
  49.   }
  50.   }
  51.   private function enemyKilled(e:Event)
  52.   {
  53.   scoreHUD.updateKills(1);
  54.   scoreHUD.updateScore(e.currentTarget.points);
  55.   }
  56.   private function removeEnemy(e:Event)
  57.   {
  58.   enemyList.splice(enemyList.indexOf(e.currentTarget), 1);
  59.   }
  60.   private function shipHit(e:Event)
  61.   {
  62.   scoreHUD.updateHits(1);
  63.   }
  64.   }
  65. }

In my version, line 44 — 63 is the enemies spawn control, I added line 40, 41, 64 so these enemies only spawn when player’s score is below 10000, I was going to set another wave of enemies for 10001 — 20000 to increase the difficulty, but obviously I have to fix these errors first.

I’m working with ActionScript3.0 on a basic movement engine. When I try to test my code, I get this error:

MovementClass.as, Line 44, Column 22    1084: Syntax error: expecting rightparen before colon.

I get this for lines 44, 52, 60, and 68 of the following code; these are the lines reading heroGoing<direction>(e:TimerEvent);

package  {
import flash.display.*;
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.events.TimerEvent;


public class MovementClass extends MovieClip {
    var reference:Reference = new Reference();
    var hero:Hero = new Hero();
    var enemy:Enemy = new Enemy();
    var wall:Wall = new Wall();

    //Timer
    var moveTimer:Timer = new Timer(25, 10)

    //Booleans
    var movingHeroRight:Boolean = false;
    var movingHeroLeft:Boolean = false;
    var movingHeroUp:Boolean = false;
    var movingHeroDown:Boolean = false;

    public function MovementClass() {
        hero.x = stage.stageWidth * .5;
        hero.y = stage.stageHeight * .5;
        addChild(hero);
        startEngine();
    }

    public function startEngine():void {
        stage.addEventListener(KeyboardEvent.KEY_DOWN, movementHandler);
        stage.addEventListener(KeyboardEvent.KEY_UP, stopHandler);
    }

    public function movementHandler(keyDown:KeyboardEvent):void {
        if (keyDown.keyCode == 39) {
            if (movingHeroLeft == true, movingHeroUp == true, movingHeroDown == true) {
                return;
            } else {
                heroGoingRight(e:TimerEvent);
                movingHeroRight = true;
                moveTimer.start;
            }
        } else if (keyDown.keyCode == 37) {
            if (movingHeroRight == true, movingHeroUp == true, movingHeroDown == true) {
                return;
            } else {
                heroGoingLeft(e:TimerEvent);
                movingHeroLeft = true;
                moveTimer.start;
            }
        } else if (keyDown.keyCode == 38) {
            if (movingHeroLeft == true, movingHeroRight == true, movingHeroDown == true) {
                return;
            } else {
                heroGoingUp(e:TimerEvent);
                movingHeroUp = true;
                moveTimer.start;
            }
        } else if (keyDown.keyCode == 40) {
            if (movingHeroLeft == true, movingHeroUp == true, movingHeroRight == true) {
                return;
            } else {
                heroGoingDown(e:TimerEvent);
                movingHeroDown = true;
                moveTimer.start;
            }
        }
        //moveTimer.start();
    }

    function heroGoingUp(eUp:TimerEvent):void {
        if (movingHeroUp == true) {
            reference.y += 5;
        }
    }

    function heroGoingDown(eDown:TimerEvent):void {
        if (movingHeroDown == true) {
            reference.y -= 5;
        }
    }

    function heroGoingLeft(eLeft:TimerEvent):void {
        if (movingHeroLeft == true) {
            reference.x += 5;
        }
    }

    function heroGoingRight(eRight:TimerEvent):void {
        if (movingHeroRight == true) {
            reference.x -= 5;
        }
    }

    public function stopHandler(keyUp:KeyboardEvent):void {
        if (movingHeroRight == true) {
            movingHeroRight = false;
        } else if (movingHeroLeft == true) {
            movingHeroLeft = false;
        } else if (movingHeroUp == true) {
            movingHeroUp = false;
        } else if (movingHeroDown == true) {
            movingHeroDown = false;
        }
    }
}
}

What am I doing wrong?

baseURL=baseURl.replace(http:,»http ://»);

What I have tried:

var TotLength: Number= URL.length;
var LastSlashIndex :Number= URL.lastIndexOf(«/»);
var arr:Array =URL.split(«/»);
var baseURL:String;
var i:int;
for(i=0 ;i<3;i++){
baseURL+= arr[i];
baseURL= baseURL.replace(null,»»);
}

baseURL=baseURl.replace(http:,»http ://»);

} var TotLength: Number= URL.length;
var LastSlashIndex :Number= URL.lastIndexOf(«/»);
var arr:Array =URL.split(«/»);
var baseURL:String;
var i:int;
for(i=0 ;i<3;i++){
baseURL+= arr[i];
baseURL= baseURL.replace(null,»»);
}

baseURL=baseURl.replace(http:,»http ://»);

}

Updated 23-Jun-16 20:51pm


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject,
20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8
+1 (416) 849-8900

ActionScript Error #1084: Syntax error: expecting rightbrace before end of program.

Error 1084 is the general error number for syntax errors. ActionScript Error #1084 can be any number of errors. I will keep this one up to date with all the variations I find and how to fix them.

AS3 Error 1084: Syntax error: expecting rightbrace before end of program

This is a very easy one. This error just means that you are most likely missing a right brace. Or you have nested code improperly.

Bad Code:
[as]
package com.cjm
{
class CoolClass {
function CoolClass () {
trace(“Something cool”)
}
}
[/as]
Good Code:
[as]
package com.cjm
{
class CoolClass {
function CoolClass () {
trace(“Something cool”)
}
}
}
[/as]
Please make note of the third bracket at the end of the good code.

ActionScript Error #1084: Syntax error: expecting colon before semicolon.

You will most likely get this error if you are using a ternary statement and you forget to use a colon, forgot the last part of your ternary, or you replace the colon with a semicolon. This is illustrated in the following example:

Bad Code:
[as]
me.myType == “keys” ? trace(keys);
[/as]
or
[as]
me.myType == “keys” ? trace(keys) ; trace(defs);
[/as]
Good Code:
[as]
me.myType == “keys” ? trace(keys) : trace(defs);
[/as]
Flash/Flex Error #1084: Syntax error: expecting identifier before leftbrace.

Description:
This Flash/Flex Error is reported when you left out the name of your class. The ‘identifier’ that it is looking for is the name of your class.

Fix:
You will see in the code below that you just need to add in the name of your class and the error will go away.

Bad Code:
[as]
package com.cjm.somepackage {
public class {
}
}
[/as]
Good Code:
[as]
package com.cjm.somepackage {
public class MyClass {
}
}
[/as]
Flex/Flash Error #1084: Syntax error: expecting leftparen before colon.
or
Flex/Flash Error #1084: Syntax error: expecting rightparen before colon.

Description:
These AS3 Errors are reported when you the order of the parenthesis and colon are not in the proper place or the parenthesis is missing.

Fix:
The AS3 code below demonstrates the placement error. Properly order the items and the error will disappear. Also, make sure that a parenthesis is not missing. The ‘Bad Code’ gives an example of leftParen and then right paren in the order.

Bad Code:
[as]
public function ScrambleSpelling:void (s:String)
or
public function ScrambleSpelling(s:String:void
[/as]
Good Code:
[as]
public function ScrambleSpelling (s:String):void
[/as]
Flex/Flash Error #1084: Syntax error: expecting rightparen before semicolon.

Description:
This AS3 Error is reported most often when the parenthesis is missing.

Fix:
Make sure that a parenthesis is not missing. The ‘Bad Code’ gives an example of leftParen and then right paren in the order.

Bad Code:
[as]
tempArray.push((middle.splice(middle.length-1) * Math.random());
or
tempArray.push(middle.splice(middle.length-1) * Math.random();
[/as]
Good Code:
[as]
tempArray.push(middle.splice(middle.length-1) * Math.random());
[/as]
Flex/Flash Error #1084: Syntax error: expecting identifier before 1084.

Description:
This AS3 Error is reported when you have begun a package, class, function/method or variable with a numeric character rather than an Alpha character, _(underscore), or $(dollar sign). In the Flash Authoring environment it won’t allow you to add numerics as the first character in an instance name or in the linkage but with code it just gives this crazy error.

Fix:
Make sure to name your package, class, function/method or variable with a Alpha character, _(underscore), or $(dollar sign).

Bad Code:
[as]
package 1084_error
{
class 1084_error {
function 1084_error () {
var 1084_error:int = 123;
}
}
}
[/as]
Good Code:
[as]
package error_1084
{
class error_1084 {
function error_1084 () {
var error_1084:int = 123;
}
}
}
[/as]
P.S. It is probably not a good idea to give everything the same name as in the examples above.

1084: Syntax error: expecting rightparen before tripledot

Description:
This AS3 Error is reported when you add the ellipsis after the arguments parameter

Fix:
Make sure to add the ellipsis before the arguments parameter.

Incorrect:
[as]
public static function checkInheritance(propertyName:String, objects…) { }
[/as]
Correct:
[as]
public static function checkInheritance(propertyName:String, …objects) { }
[/as]

AS3 Error #1084 will rear it’s many heads according to the particular syntax error at the moment. I will post every variation of this error that I can find.

Понравилась статья? Поделить с друзьями:
  • Синоптическая ошибка на андроиде что делать
  • Синтаксическая ошибка как исправить на компьютере
  • Синтаксическая ошибка информатика
  • Синонимы к слову фатальная ошибка
  • Синтаксическая ошибка mapinfo