View Full Version : syntax errors GO AWAY!
Diddan
September 6th, 2009, 05:21 PM
I need help guys! I get the errors:
1084: Syntax error: expecting leftparen before extends.
1084: Syntax error: expecting identifier before extends.
1084: Syntax error: expecting rightparen before leftbrace.
And this is my code.
package
{
import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.events.ProgressEvent;
import flash.filters.GlowFilter;
import caurina.transitions.*;
import caurina.transitions.properties.*;
FilterShortcuts.init();
ColorShortcuts.init();
public class starter {
public function starter extends MovieClip
{
//Laddning av siten, procent till preloadern
loaderInfo.addEventListener(ProgressEvent.PROGRESS , loading);
}
function loading(e:ProgressEvent):void {
//Variabler
var total:Number=e.bytesTotal;
var loaded:Number=e.bytesLoaded;
var av:Number=loaded/total;
var blurry:Number=av*5;
procent.text=Math.round(av*100)+" %";
//Animering av alpha p regnbÂgen
Tweener.removeAllTweens();
regnbage2.alpha=av;
}
}
}
What is wrong?
The comments in the code are written in swedish :P
Joony5
September 6th, 2009, 05:47 PM
The class should extend MovieClip, not the constructor (the function).
Joony5
September 6th, 2009, 05:54 PM
At least there isn't much point in the comments, and they're not that hard to understand.
Never seen Swedish comments before. The worst I've come across are German. They love to code in German. Actually, tell a lie, I was doing a job for a bank here in Denmark that involved a LOT of pension calculations. EVERYTHING was in Danish, comments, variable names, function names, everything. In Hungarian notation too, just for good measure.
IQAndreas
September 6th, 2009, 06:07 PM
Functions cannot be called unless contained inside of a function. (And in your case, they are all the way outside of the class even!
FilterShortcuts.init();
ColorShortcuts.init();
Here is the correct code:
package
{
import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.events.ProgressEvent;
import flash.filters.GlowFilter;
import caurina.transitions.*;
import caurina.transitions.properties.*;
public class starter {
public function starter extends MovieClip
{
FilterShortcuts.init();
ColorShortcuts.init();
//Laddning av siten, procent till preloadern
loaderInfo.addEventListener(ProgressEvent.PROGRESS , loading);
}
function loading(e:ProgressEvent):void {
//Variabler
var total:Number=e.bytesTotal;
var loaded:Number=e.bytesLoaded;
var av:Number=loaded/total;
var blurry:Number=av*5;
procent.text=Math.round(av*100)+" %";
//Animering av alpha p regnbÂgen
Tweener.removeAllTweens();
regnbage2.alpha=av;
}
}
}
However, the two "init()" functions will run every time you create a new "starter" class. You can fix this in the following way:
package
{
import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.events.ProgressEvent;
import flash.filters.GlowFilter;
import caurina.transitions.*;
import caurina.transitions.properties.*;
public class starter {
public function starter extends MovieClip
{
starter.initShortcuts();
//Laddning av siten, procent till preloadern
loaderInfo.addEventListener(ProgressEvent.PROGRESS , loading);
}
function loading(e:ProgressEvent):void {
//Variabler
var total:Number=e.bytesTotal;
var loaded:Number=e.bytesLoaded;
var av:Number=loaded/total;
var blurry:Number=av*5;
procent.text=Math.round(av*100)+" %";
//Animering av alpha p regnbÂgen
Tweener.removeAllTweens();
regnbage2.alpha=av;
}
// STATIC functions and properties
private static var initialized:Boolean = false;
public static function initShortcuts():void
{
if (initialized == false)
{
FilterShortcuts.init();
ColorShortcuts.init();
initialized = true;
}
}
}
}
I'm not sure if you have used the "static" keyword before. If not, I'll explain. I described it once in an MSN chat, and it's likely I still have it. Let me dig it out...
Also, I would capitalize Starter (as I did in the second example). That way you can easily see the difference between Classes and instances. It's not neccesary at all, just more of a standard. :)
Lycka till med kodandet, ;)
Andreas
IQAndreas
September 6th, 2009, 06:16 PM
[Smacks head] JoonyD is right. I'm blind. :P
Here is the correct code:
package
{
import flash.display.MovieClip; //Don't forget this one as well!
import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.events.ProgressEvent;
import flash.filters.GlowFilter;
import caurina.transitions.*;
import caurina.transitions.properties.*;
FilterShortcuts.init();
ColorShortcuts.init();
public class Starter extends MovieClip {
public function Starter():void {
//Laddning av siten, procent till preloadern
loaderInfo.addEventListener(ProgressEvent.PROGRESS , loading);
}
function loading(e:ProgressEvent):void {
//Variabler
var total:Number=e.bytesTotal;
var loaded:Number=e.bytesLoaded;
var av:Number=loaded/total;
var blurry:Number=av*5;
procent.text=Math.round(av*100)+" %";
//Animering av alpha p regnbÂgen
Tweener.removeAllTweens();
regnbage2.alpha=av;
}
}
}
On the note of coding in Swedish, I have been typing on an American keyboard for the last 6 years, and at first I assumed everything would be the same on a Swedish keyboard as on an American aside from the three extra keys... I was wrong!
I still can't type or code properly on a Swedish keyboard. Mostly, the double and single quotes and square and curly brackets are so hard to get to, and as a developer, those are the keys I use the most. :(
They should really have a "developer friendly" keyboard with all most common developer characters easily accessible, and all non-essential keys hidden away. Really, now that I think about it, the American keyboard is set up sortof like this, but perhaps it's just that I'm so used to it by now. :P
Diddan
September 7th, 2009, 11:03 AM
Thanks a lot everyone! :) I really appreciate it.
Diddan
September 7th, 2009, 11:34 AM
Hrm, maybe I shouldn't cheer until I've crossed the river, Now I get a 1084: Syntax error: expecting rightbrace before end of program.
I've tried to put a few braces hera and there but it didn't help. Where am I doing wrong?
Joony5
September 7th, 2009, 11:35 AM
On the note of coding in Swedish, I have been typing on an American keyboard for the last 6 years, and at first I assumed everything would be the same on a Swedish keyboard as on an American aside from the three extra keys... I was wrong!
I still can't type or code properly on a Swedish keyboard. Mostly, the double and single quotes and square and curly brackets are so hard to get to, and as a developer, those are the keys I use the most. :(
They should really have a "developer friendly" keyboard with all most common developer characters easily accessible, and all non-essential keys hidden away. Really, now that I think about it, the American keyboard is set up sortof like this, but perhaps it's just that I'm so used to it by now. :P
Yeah, tell me about it. When I first came to Denmark, what a shock! It took me 3 times as long to do anything. I was just typing rubbish. Then I thought I could just switch the layout back to British, but once you get a glimpse of the keyboard, you can't find anything. I just use a British keyboard now, makes much more sense to me.
Joony5
September 7th, 2009, 11:37 AM
Hrm, maybe I shouldn't cheer until I've crossed the river, Now I get a 1084: Syntax error: expecting rightbrace before end of program.
I've tried to put a few braces hera and there but it didn't help. Where am I doing wrong?
Count the braces. If they are fine, then there's something else confusing the compiler. What does the code look like?
Diddan
September 7th, 2009, 11:47 AM
I'm using the code in post #5
Joony5
September 7th, 2009, 11:52 AM
There are 2 function calls in the package (right after the imports) that shouldn't be there. I'm not sure where you want them, but I'm guessing you want them in the constructor (the Starter() function).
Diddan
September 7th, 2009, 12:32 PM
I've tried putting them inside parenthesis of Starter function but with no luck. What is wrong here people? :(
IQAndreas
September 8th, 2009, 07:21 AM
I've tried putting them inside parenthesis of Starter function but with no luck. What is wrong here people? :(
This code isn't giving me any parenthesis errors:
package
{
import flash.display.MovieClip;//Don't forget this one as well!
import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.events.ProgressEvent;
import flash.filters.GlowFilter;
import caurina.transitions.*;
import caurina.transitions.properties.*;
FilterShortcuts.init();
ColorShortcuts.init();
public class Starter extends MovieClip
{
public function Starter():void
{
//Laddning av siten, procent till preloadern
loaderInfo.addEventListener(ProgressEvent.PROGRESS , loading);
}
function loading(e:ProgressEvent):void
{
//Variabler
var total:Number = e.bytesTotal;
var loaded:Number = e.bytesLoaded;
var av:Number = loaded / total;
var blurry:Number = av * 5;
procent.text = Math.round(av * 100) + " %";
//Animering av alpha p regnbÂgen
Tweener.removeAllTweens();
regnbage2.alpha = av;
}
}
}
I ran it through Flash's auto-indent, so it looks prettier now.
This is a "rightparen" -> )
This is a "rightbrace" -> }
It get's annoying when the names are so similar. :P Usually that error means that you need to add a rightbrace to the end of the program, and everything will be alright. I usually auto-indent when I can to see that everything matches up properly.
Also, if you use a program like "FlashDevelop" or "Notepad2", it will highlight "matching" braces and parentheses, so you can see if the ones you selected really go together.
Also, check out my post earlier regarding the ".init()" functions. That could also be causing the errors.
thatsasif
September 8th, 2009, 10:35 AM
No errors to me even...You might have not copied properly....
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.