A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: How do you create global variables?

  1. #1
    Junior Member
    Join Date
    May 2012
    Posts
    17

    How do you create global variables?

    Figured it out.

    Delete this thread please
    Last edited by FlashAahaah; 06-02-2012 at 01:19 PM. Reason: figure it out myself

  2. #2
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    No. Describe your problem, and solution, so that others might benefit.

    Generally, you don't need global variables. They are almost always a sign of bad design and strongly coupled functionality that should be better abstracted.

    If for some reason you have a legitimate need for a variable which can be accessed literally anywhere, a static variable will do. Some people like to create a class specifically to group their static variables together. This makes the band-aid more comfortable, but it doesn't fix the boo-boo.

  3. #3
    Junior Member
    Join Date
    May 2012
    Posts
    17
    What exactly is "boo-boo"-like about grouping global variables together? Does it have any negative effect on the program?

    In this specific instance I have a global variable to remember how many times a symbol has been clicked. For instance, if the user clicks on it once, it moves the timeline to a specific place, and upon completion of this part of the scene the global variable changes (the actionscript makes the variable change at the same time it stops the scene); so when the user clicks on the symbol again after this first click animation has completed, it does something different. I can do this with a global variable, is there another way?
    Last edited by FlashAahaah; 06-02-2012 at 08:22 PM.

  4. #4
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    The boo-boo is using globals at all. I'd have the symbol be an instance of a class which has a property to keep the clicked count. Or have the counter in the class which implements the event listener (if those are different).
    The only negative effect of using variables in a larger scope than necessary is that you run the risk of creating spaghetti code by making it easier to blur the separation of concerns between classes. In this case, nothing else has any reason to know or access the clicked count, so you probably don't want anything to mess with it or depend on it.

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