AS3 syntax compile errors - expecting semicolon before rightparen - actionscript-3

I know this is extremely basic but the following function is generating 2 syntax errors on compile, these are shown below. I can't figure them out. Any help is much appreciated.
Game, Layer 'Actions', Frame 2, Line 5 1086: Syntax error: expecting semicolon before rightparen.
Game, Layer 'Actions', Frame 2, Line 5 1084: Syntax error: expecting rightbrace before semicolon.
function fl_TouchEndHandler_2(event:TouchEvent):void {
// Drag & drop stuff...
contained[i] = Gem1_MC.hitTestObject(Gem4_MC));
contained[i] = Gem2_MC.hitTestObject(Gem4_MC));
contained[i] = Gem3_MC.hitTestObject(Gem4_MC));
if (contained.indexOf(false) == -1) { // This returns -1 if it can't find false
gotoAndStop(1);
}
}

You have extra ')'
try:
function fl_TouchEndHandler_2(event:TouchEvent):void {
// Drag & drop stuff...
contained[i] = Gem1_MC.hitTestObject(Gem4_MC);
contained[i] = Gem2_MC.hitTestObject(Gem4_MC);
contained[i] = Gem3_MC.hitTestObject(Gem4_MC);
if (contained.indexOf(false) == -1) { // This returns -1 if it can't find false
gotoAndStop(1);
}
}

Related

Octave Function Undefined

Any idea why the following produces an error?
printf("this is my text\n");
MyFunc;
function MyFunc
printf("printing from inside function\n");
endfunction
This is the error I get (from the Command Window)
error: 'MyFunc' undefined near line 3, column 3
error: called from
function_example at line 3 column 1
Okay, I see the issue now. The function definition needs to be placed before the function call is made - as shown below.
printf("this is my text\n");
function MyFunc
printf("printing from inside function\n");
endfunction
MyFunc;

1084: Syntax error: expecting rightparen before colon?

I'm new to AS3 and I'm trying to write a basic game code. So what I'm trying to do is when the enemy is at 0 hp, the output will say "you win!"
but it says "1084: Syntax error: expecting rightparen before colon" (on line 2)
here
{
if (enemyHP:Number = 0)
trace("you win!");
}
thx
You don't need to write type of enemyHP in if statement and to do right comparison between Number variables you need to write == instead of =. So finally your code should look like:
{
if (enemyHP == 0)
trace("you win!");
}

How to use Math.LN(x) in ActionScript 3

How to use Math.LN(x) in ActionScript 3?
I have a formula to convert:
17.867 * LN(x)-29.263
How to write in ActionScript 3? I'm confused about how to write it.
What I've tried :
var Kc:Number;
var value_x:Number;
function enterFrameHandler () : void
{
value_x=80;
Kc=(17.867)*Math.LN10(value_x) - 29.263;
value_Kc.text=String(Kc);
trace(Kc);
//y = 17.867ln(x) - 29.263//
}
enterFrameHandler();
Getting error :
Error : Scene 1, Layer 'Layer 1', Frame 1, Line 7, Column 19 1195 :
Attempted access of inaccessible method LN10 through a reference with
static type Class.
thanks for your replied #Organis may be directly show problem in my code
var Kc:Number;
var value_x:Number;
function enterFrameHandler () : void
{
value_x=80;
Kc=(17.867)*Math.LN10(value_x) - 29.263;
value_Kc.text=String(Kc);
trace(Kc);
//y = 17.867ln(x) - 29.263//
}
enterFrameHandler();
///get error Scene 1, Layer 'Layer 1', Frame 1, Line 7, Column 19 1195: Attempted access of inaccessible method LN10 through a reference with static type Class.//

Syntax error: expecting semicolon before leftbracket

I have the following code at frame one of the top layer:
var level:Array = new Array();
var level[0] = new Object();
I am getting the following error:
Scene 1, Layer 'levels', Frame 1, Line 2
1086: Syntax error: expecting semicolon before leftbracket.
I've looked at many examples which seem to be doing the same thing I'm doing, and I've also tried defining the object separately and then adding it to the array, with the same error. I've also searched for the answer, but all the questions I've found are a little different than this situation.
The syntax/grammar production
var level[0] = new Object();
is invalid.
The var production expects a simple Identifier, not an expression1. The parser was roughly trying to treat the production as var level;[0] = ..; (but failed due to the missing semicolon, and would have failed anyway because [0] = ..; is an invalid production as well).
Try:
var level:Array = new Array();
level[0] = new Object(); // no "var" here so it is a valid grammar production
or, more concisely:
var level:Array = [{}]; // using Array and Object literal notations
1 See AS3.g for that ANTLR production rules. Alternatively, for ECMAScript (from which AS derives), see 12.2 Variable Statement from ES5-Annotated and note that it requires an "Identifier" followed by an optional initializer (=) or another declaration (,) or end of statement (;).
Only is
level[0] = {};
or
level.push({});

AS3 Compiler error 1083: problem with else syntax

I'm creating a simple click and scroll for a future menu for my personal site. I have a box, I called it thing_mc, and I have 3 positions for it. I have a next and prev. button that will control thing_mc position. I'm using TweenLite to animate thing_mc, if that makes a difference.
I get a 1083 error (...else is unexpected) and (...rightparen is unexpected).
Can anyone tell me why and how I can resolve this?
Thanks
import gs.TweenLite;
next_mc.addEventListener(MouseEvent.CLICK, nextListener);
prev_mc.addEventListener(MouseEvent.CLICK, prevListener);
//prev_mc.visible = false;
function nextListener(event:MouseEvent):void
{
if(thing_mc.x == 400);
{
TweenLite.to(thing_mc, .5, {x:50, y:50});
}
else if //// i get error 1083 here (...else is unexpected)
{
TweenLite.to(thing_mc, .5, {x:-100, y:50}); //// i get error 1083 here (...rightparen is unexpected)
}
}
function prevListener(event:MouseEvent):void
{
if(thing_mc.x == -100);
{
TweenLite.to(thing_mc, .5, {x:400, y:50});
}
else if //// i get error 1083 here (...else is unexpected)
{
TweenLite.to(thing_mc, .5, {x:500, y:50}); //// i get error 1083 here (...rightparen is unexpected)
}
}
next_mc.buttonMode = true;
prev_mc.buttonMode = true;
I am not AS expert, but the semicolon after if(thing_mc.x == 400); and if(thing_mc.x == -100); seems strange. Should rather read if(thing_mc.x == 400) and if(thing_mc.x == -100) I'd say.
else if //// i get error 1083 here (...else is unexpected)
You have a few options here. You can either use a second condition, if you want to use else if i.e.
else if (someCondition) { ...
or, use just else
else { ...
or use another if
if { ...
It all depends on what you want to achieve.
From what I can see, the second option (plain else) looks like what you want.
function nextListener(event:MouseEvent):void
{
if(thing_mc.x == 400);
{
Don't use ; after the if brackets
;-)
Wats going on is the parser sees
if ( cond ) ;
as
if ( cond ) /empty statement/ ; //semicolon ends empty statement
(and the else if /.../ of course lacked the parenthesized conditional expr that an if requiress).
I've seen this semicolon related error a lot.
It may be because semicolons are optional in some cases in as3.