Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 06-10-2003, 08:39 AM   #1
Andy_R
Registered User
 
Join Date: Jun 2003
Posts: 5
Default ;

At the moment, I've been sprinkling my code with semicolons pretty much at random.

I know they are required between statements, but are they actually needed at the end of a script, or at the end of a list of statements?

Do I need to write

if (condition) then {statement;statement;};

or can I just have

if (condition) then {statement;statement}

if nothing else follows after?
Andy_R is offline   Reply With Quote
Old 06-10-2003, 08:47 AM   #2
farafiro
Addicted To FLASH
 
farafiro's Avatar
 
Join Date: Dec 2001
Location: Egyptian in UAE
Posts: 12,436
Send a message via MSN to farafiro Send a message via Yahoo to farafiro
Default

no, not required at the lines ends unless u don't want to make a new line by pressing ENTER

also, they required within the for loop only, not the if statment
__________________
‚€* GOD Is Near ‚€*
Questions Don't PM for Questions . Thanks
An eye for an eye, make the whole world blind
_____________________________________________GHANDI
farafiro is offline   Reply With Quote
Old 06-10-2003, 10:52 AM   #3
Mortimer Jazz
Thing
 
Mortimer Jazz's Avatar
 
Join Date: Jun 2001
Location: UK
Posts: 2,418
Default

Flash is pretty lax about requiring semi-colons, so you can omit them completely as long as your statements are separated by carriage returns (ie on separate lines in the actionscript window) , however I certainly wouldn't advise leaving them out.

With the exception if conditionals (if/else etc) and functions you should put a semicolon at the end of each statement to signify the end of that statement. This also allows you to put several statements/declarations on a single line should you wish to do so:

x=1;y=10;name="bob";age="152";

Obviously this ruins the clarity of your code, so it's not advised.
The closing "}" bracket on an if-statement or function is a way of denoting the end of that function, so the semi-colon isn't really needed there.

However, it is convension that if you write a "function literal" you put a semi-colon at the end. I have no idea why and it isn't necessary. Below is a fucntion literal and below that is a normal function, just to demonstrate
ActionScript Code:
//function literal (some people put semi-colons after the closing bracket, but not essential) doSomething = function(){  //code here }; //standard function (don't put a semi-colon afetr the closing bracket) function doSomething(){  //code here }
As faffy says, they are only required to separate statements within a for loop.
Mortimer Jazz is offline   Reply With Quote
Old 06-10-2003, 01:35 PM   #4
bluegel
Im watching in my absence
 
bluegel's Avatar
 
Join Date: Feb 2003
Location: wherever the mood takes me
Posts: 2,114
Default

at the end of the day, you will probably always check your syntax anyway and that will tell you if you are missing semicolons or not.
__________________
Im a girl

Watching in my absence - courtesy of CyanBlue
bluegel is offline   Reply With Quote
Old 06-10-2003, 11:29 PM   #5
sneeuwitje
...
 
sneeuwitje's Avatar
 
Join Date: May 2003
Location: rotterdam, NL
Posts: 676
Default

Quote:
Mortimer Jazz
I have no idea why ...
Isn't that just because your first example is not really a function, but a statement (doSomething = ...)?
__________________
Little bit off-Flash lately ... back soon hopefully
sneeuwitje is offline   Reply With Quote
Old 06-11-2003, 12:09 AM   #6
Mortimer Jazz
Thing
 
Mortimer Jazz's Avatar
 
Join Date: Jun 2001
Location: UK
Posts: 2,418
Default

Well, good point, but it's not so straight forward.
Just as "instance" and "object" can be used interchangably so can "statement" and "function".

Strictly speaking it's a function (a function-literal to be precise), but a function declaration is also a statment (and this goes for both normal functions and function literals). This is why I thought it better to say I don't know the reasoning behind including the semi-colon. I can hazzard a guess, but I don't actually know for sure:

If I remember correctly, both types are functions are nothing more than variable assignments (funtions are just datatype, and so can be treated as such), but the difference is that normal functions are available to all scripts in your movie, regardless of where the function is declared (because they are the first things to get processed by the flash player), whilst function literals are only available to code written after their declaration, and so act more like a standard variable assignment.

In other words function literals are sort of proceedural in nature, and so the semi-colon indicates the end of that statement, and that we're ready for the next. This doesn't really apply to normal functions due to the fact that they always get processed before everything else.

I hope this helps
Mortimer Jazz is offline   Reply With Quote
Old 06-11-2003, 12:24 AM   #7
sneeuwitje
...
 
sneeuwitje's Avatar
 
Join Date: May 2003
Location: rotterdam, NL
Posts: 676
Default thanx

This is not my thread, but it's always a pleasure to stumble across one of your in-deep explanations of AS
sneeuwitje is offline   Reply With Quote
Old 06-11-2003, 12:37 AM   #8
Mortimer Jazz
Thing
 
Mortimer Jazz's Avatar
 
Join Date: Jun 2001
Location: UK
Posts: 2,418
Default

Not a problem
Like I said, I'm not 100%, but it sounds like the most logical explanation to me.

[edit: I should just clarify (for the purpose of anyone searching threads, and so I don't get shouted at) that when I say "normal functions are available to all scripts in your movie, regardless of where the function is declared", it is standard proceedure to declare all 'normal' functions on the first frame of your movie. If you declare a function on a frame that the playhead hasn't reached yet, and then try and call that function it will not be called because it doesn't exist ]

Andy, I know this is a post to the newbie forum, so i'll just state, obviously this isn't essential stuff to know.

Just remember that you only need semi-colons at the end of variable assignments (anywhere where a value is assigned to a variable name)
ActionScript Code:
myVariable = "my value";

That's about it really.
Hope this helps

Last edited by Mortimer Jazz; 06-11-2003 at 12:45 AM.
Mortimer Jazz is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT. The time now is 11:45 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.