Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / Flash / General Flash Topics / February 2006



Tip: Looking for answers? Try searching our database.

Using Global Variables?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
boxdoctor - 28 Feb 2006 16:03 GMT
Hi all.  Since most of us have basically started developing everything in .as
files, and classing things to be used over and over again, the question entered
my mind about using global variables and if people are still using them...and
if so....where, when and how.  So I figured I'd post this and see what all of
you think.

My past, and probably stupid approach, in the past was to have lots of global
variables that would contain all of the information I could ever want from
within my application.  This affords a developer a lot of help in those sticky
situations where it's so nice and easy to just stick the result in a global
variable and be done with it.   I would gather all of the user's information
from a single db call and stick all the information into a dozen or more global
variables.  I haven't found anything specific...so I'm guessing here but it
appears as though this contributes to problems in 3 major areas in Flash
application development:

1.  Increased memory usage of the app
2.  Really easy to break if you add/modify the app and forget about updating
the globals
3.  Probably not looked on kindly in the OOP world

My own new approach over the past year has been to write classes for obtaining
that information and calling it whenever you need it.  So for example if you
need a user's SSN part way through an app, you can just have a class called
"getSSN" in your security.as file and call it when you need it.

Now, I even question myself with this type of approach because the first
method seems so much simpler.  Call a single "info gather" db call right during
login and store everything you need...why complicate things with a class
instead of using a global variable to store the SSN?

Maybe someone can tell me what they have done with using global
variables...now don't get me wrong...I still have globals and use them in
situations where warranted, but certainly not as much as in the past.  I'm
wondering also if someone has any concrete stats or info that proves that the
use of a lot of globals does in fact increase the memory usage of the app and
slows down your app.  Am I off my rocker?
albee - 28 Feb 2006 16:24 GMT
Unless you're using thousands and thousands of variables, I can't see how this
would noticeably increase memory usage. I have read that Flash MX 2004 and
Flash 8 work more efficiently if values are stored in variables (more efficient
recall from memory registers and so forth), so using variables, whether
declared in a class or in the global object, are defintely the way to go. Are
you concerned about this because you potentially need to deal with many
thousands of variables?

I still use global variables all the time, especially if I need to generate
unique variables dynamically that need to transcend local function scope.

Albee
boxdoctor - 28 Feb 2006 16:59 GMT
To be honest with you, I've thought the same thing about the globals and their
use within a fairly large application.  I have an "older" app that is a mess,
but the globals which are far and wide (about 100 or so) seem to work just fine
within the app.  

I guess my concern has basically been what is the wave of the future in
regards to using globals.  I've seen some blogs out there where people are
basically trashing developers who use a lot of globals.  Me personally I march
to the beat of the voices in my head, but it does matter to me to see what
others in the world are doing.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.