A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: var declaration shortcuts

  1. #1
    will i ever get it?
    Join Date
    Feb 2004
    Posts
    707

    var declaration shortcuts

    i take it that i can not do this:
    PHP Code:
    var tgx,tgy,dx,dy,vx,vy,ease:Number
    but i have to do this:
    PHP Code:
    var tgx:Number,tgy:Number,dx:Number,dy:Number,vx:Number,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.

  2. #2
    Senior Member tonypa's Avatar
    Join Date
    Jul 2001
    Location
    Estonia
    Posts
    8,223
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center