Thread: Scope in ActionScript

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912

    Scope in ActionScript

    For the record - I'm working on massive source code that was written by people who were incompetent at the time, and are no longer working here. So if it makes no sense to you why I'm having this problem and why I can't just rename the variable - trust me, it makes sense! So...

    There's a variable declared in the global scope - outside of any classes. It's used in a function.

    There's another function that declares a variable with the same name and uses that.

    The code seems to compile with no problems - I can't actually test the functionality of it right now.

    But to save me a couple of hours of testing once I can try running some examples - does anybody know if this causes undefined behavior, or if AS just uses the most local variable by default, or what?

    I read in Adobe's documentation that a variable defined in a function is actually useable before the declaration and outside the function. WEIRD! So I'm a little lost about scope...

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    From reading http://livedocs.adobe.com/flash/mx20...=00000785.html
    I'm pretty convinced that unless you specify _global, it is the local variant that you get.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  4. #4
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    ActionScript should follow ECMAScript scoping rules. Thus you get the most local variable the interpreter can find.

    There's no such thing as undefined behaviour in ActionScript.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  5. #5
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    Aww... I miss undefined behavior!

    Well thanks for the answers! The links posted by dwks are exactly the ones confusing me - because they almost seem to conflict with a book I have published by Adobe...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. how do you resolve this error?
    By -EquinoX- in forum C Programming
    Replies: 32
    Last Post: 11-05-2008, 04:35 PM
  3. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM
  4. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  5. Nested loop frustration
    By caroundw5h in forum C Programming
    Replies: 14
    Last Post: 03-15-2004, 09:45 PM