00:00
00:00

AS: Sweet Debugging syntax

3,158 Views | 1 Reply
New Topic Respond to this Topic

AS: Sweet Debugging syntax 2005-06-28 14:18:36


AS: Main

This thread is about the correct syntax, it mostly applies to mx 2004

Remmember people, correct syntax does several things:

1)Make your code more readable
2)Makes errors easier to find for the debugger

Variables

Partial decleration:
Whenever you use a variable, declare it first, you declare a variable with the "var" command
for example:

var i;

declares a variable named I

var arr=new Array();
declares a new variable names it arr and creates a new array for it to point at

Full decleration:

Whenever you make full decleration (which is importent for the compiler to identify your errors) you also specify the return type, for example

var i:Number;

declares a number variable called i

var arr:Array=new Array();

declares a new array.

var s:String="lololololol";

creates a new string variable, names it s, and puts 'lolololol' in it

Functions

Always specify the return type, if there isn't any, the function returns "Void";

for example

function lolk():Void{
trace("lolk");
}

another example

function lolno():Number{
return 1337;
}

this way the compiler warns you if you have the wrong return type, it helps alot with errors.

remmember, params also have types, for example

function sum(num1:Number,num2:Number):Number{
return num1+num2;
}

Response to AS: Sweet Debugging syntax 2005-07-20 16:33:52


Yeah!!!!