Posted By

visualadvance on 02/07/10


Tagged

object globalvars


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

tspitzr
mitien


AS3: GlobalVars Class File


 / Published in: ActionScript 3
 

A little hack to store variables in a class file that all other classes can access.

VERY IMPORTANT: I have found an issue where, even if you have all your cross-domain issues resolved, the GlobalVars will be undefined if your swfs are cross-domain.

  1. // make a class called GlobalVars.as
  2. package com
  3. {
  4. public class GlobalVars
  5. {
  6. public static var vars:Object = {};
  7. }
  8. }
  9.  
  10. // then in your other classes
  11. import com.GlobalVars;
  12. GlobalVars.vars.whatever = "something to store"
  13.  
  14. // then in any other class just do your import of com.GlobalVars, then:
  15. trace (GlobalVars.vars.whatever) // returns "something to store"

Report this snippet  

You need to login to post a comment.