Stick Page Forums Archive

Problems with actionscript

Started by: spaceflip | Replies: 1 | Views: 415

spaceflip

Posts: 0
Joined: Jul 2025
Nov 4, 2008 7:04 PM #286747
I'm trying to create a cannon firing game in which you shoot down planes. I found an error that I cant fix.
1084: Syntax error: expecting rightbrace before not.

Here is my script.

import fl.controls.Button;
//this listens for a key press and executes the function "pivot"
stage.addEventListener(KeyboardEvent.KEY_DOWN, pivot);


//this defines the function "pivot"
function pivot(event:KeyboardEvent):void
{
//test to see what key is pressed AND whether cannon is upright
if (event.keyCode==39 && cannonbarrel_mc.rotation<90){
//rotate cannon 1 degree right
cannonbarrel_mc.rotation +=1;

}
else if (event.keyCode==37 && cannonbarrel_mc.rotation> -90){
//rotate cannon 1 degree left
cannonbarrel_mc.rotation -=1;

}



var cannonballSpeed=9;
var cannonballReady=true;
var cannonballDelay=150;
var cannonballArray=[];
var cannonballCount=0;


function createcannonballs():void{
var ball= this.attachMovie("cannonball"+cannonballCount, 1000+cannonballCount);
cannonballCount++;
ball.DisplayObject.x=cannonbarrel_mc.DisplayObject.x+(cannonbarrel_mc.DisplayObject.width/2);
ball.DisplayObject.y=cannonbarrel_mc.DisplayObject.y+ball._height;
cannonballArray.push(ball);


}
fire!.addEventListener(MouseEvent.CLICK, createcannonballs);
}



PLZ help me THX
darkcampainger
2

Posts: 159
Joined: Aug 2006
Rep: 10

View Profile
Nov 4, 2008 7:54 PM #286773
Quote from spaceflip
function pivot(event:KeyboardEvent):void
{
//test to see what key is pressed AND whether cannon is upright
if (event.keyCode==39 && cannonbarrel_mc.rotation<90){
//rotate cannon 1 degree right
cannonbarrel_mc.rotation +=1;

}
else if (event.keyCode==37 && cannonbarrel_mc.rotation> -90){
//rotate cannon 1 degree left
cannonbarrel_mc.rotation -=1;

}

} // <-- You forgot the closing brace for the pivot() function

var cannonballSpeed=9;


Add a rightbrace as bolded above. That should fix the problem.

In the future, surround your ActionScript in [noparse]
 
tags, like this:

function lawls():void {
if (monies>9000) {
explode();
}
}
[/noparse]

That will also ensure that tabbing is maintained:


function lawls():void {
if (monies>9000) {
explode();
}
}
Website Version: 1.0.4
© 2025 Max Games. All rights reserved.