The Armor Games website will be down for maintenance on Monday 10/7/2024
starting at 10:00 AM Pacific time. We apologize for the inconvenience.

ForumsProgramming ForumFlash as3 Global Variable

3 6981
alsage
offline
alsage
132 posts
Nomad

Is it possible to have one variable that is accsesible through other many different . as files? if not is it possible for me to put a variable inside its own .as and have the others call it?

  • 3 Replies
WhiskeyedJack
offline
WhiskeyedJack
80 posts
Shepherd

Unfortunately the straightforward _global of AS2 is no longer. I believe your best bet is to create a new class with a static variable. That way if you import the class, you can access that variable globally.

//as3
package
{
public class Global
{
public static var vars:Object = {};
}
}


Then you could import the Global wherever you want to read or write the variables.

import Global


From there you can write your variables and access them anywhere you have imported the package.

Global.vars.myNewVar = 1


Anywhere Global is accessible, Global.vars.myNewVar can now be read and used.
driejen
offline
driejen
486 posts
Nomad

What WhiskeyesJack said. Also you don't have to import it to access variables in other classes, you can access static variables anywhere just fine using the <class>.<static_var/cons>.

alsage
offline
alsage
132 posts
Nomad

thanks guys I really appreciate it!

Showing 1-3 of 3