I need to have access to the logged in user troughout a flash application. Therefor I’m concidering making the ‘user’ variable global.
I usually try to avoid global variables, but it seems quite suitable in this case and I’m not the first to concider the active user as a global. I know that systems like drupal also uses a global variable for the logged in user.
I want to know if stackoverflow thinks of this as bad practice or if there are better alternatives.
If you use a global variable, you are creating a dependency on that variable in all the modules that use it. So, for example, if you wanted to reuse any of those modules in another project, you would need to take their use of this global variable into account.
Having said that, I don’t particularly find it bad design to have a global variable for a user-id. If you wanted to reuse any of the modules that use it, you would want to deal with users anyways, and will probably have that global variable in your new application too.
There are dependency-injection frameworks that could solve this for you. Whether they will add value to your specific project or not depends on many other considerations, and it is really up to you.