A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: [AS2/3] Duplicate variable definition in for-loop?

  1. #1
    SaphuA SaphuA's Avatar
    Join Date
    Oct 2002
    Location
    The Netherlands
    Posts
    2,180

    [AS2/3] Duplicate variable definition in for-loop?

    Hi there,

    I'm currently learning AS3 (and 2 aswell I guess). Now i'm having a little 'problem' with duplicated variables.

    I'm having a function with two for-loops:
    code:
    for(var i:int=0; i<10; i++) {
    var m:Boolean = false;
    }

    for(var i:int=0; i<10; i++) {
    var m:Boolean = false;
    }


    Why do i get the warning of duplicated variables? I always thought that both variables 'i' and 'm' would get removed at the end of the loop. Doesn't this happen anymore since AS2/3 ?

    Thanks,
    ~Sph

  2. #2
    Senior Member UnknownGuy's Avatar
    Join Date
    Jul 2003
    Location
    Canada
    Posts
    1,361
    No, they don't get removed if declared in a loop, its when they are declared in a function.

    (Eg, at the end of the function all local variables declared are erased)

  3. #3
    Senior Member tonypa's Avatar
    Join Date
    Jul 2001
    Location
    Estonia
    Posts
    8,223
    Moved to AS3 forum.

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