;

PDA

Click to See Complete Forum and Search --> : var declaration shortcuts


mlecho
06-01-2007, 12:39 AM
i take it that i can not do this:
var tgx,tgy,dx,dy,vx,vy,ease:Number;
but i have to do this:
var tgx:Number,tgy:Number,dx:Number,dy:Number,vx:Numbe r,vy:Number,ease:Number;

? || is the error i get in Flex, meaningless?

At the risk of developing bad habits, i would be curious if there is a resource out there with useful shortcuts when coding.

tonypa
06-01-2007, 04:15 AM
Well, you can do this:

var var1, var2:Number;

Which declares 2 variables, var is untyped, var2 is Number.

var var1, var2:Number;
trace(var1 is Number); //false
trace(var2 is Number);//true

However, once you assign value to the variable, untyped variable will be converted into Number anyway:

var var1, var2:Number;
var1=0;
var2=0;
trace(var1 is Number); //true
trace(var2 is Number); //true

So, basically, you can simply declare bunch of untyped variable in short:

var var1, var2;

and later, when they get Number value assigned, they will be converted into Numbers.