Skip to main content
Participating Frequently
April 2, 2008
Question

global variable in as3.0

  • April 2, 2008
  • 2 replies
  • 692 views
I am doing something with flash cs3,I need to use global variable in it ,but there is not global variable in as3.0,can anyone help me ,thanks forever!
This topic has been closed for replies.

2 replies

Participating Frequently
April 3, 2008
thanks you are welcome
Inspiring
April 2, 2008
There is no global in AS3. But you can make values globally accessible by
using static fields in classes. e.g.

// MyClass.as
package
{
public class MyClass
{
public static var globals = new Object();
}

}

MyClass.globals["hello"] = "world"
trace(MyClass.globals.hello);


// and if you want to simulate something a little
// closer to the AS2 _global object you can drop
// this into a top level in your class path

// global.as
package
{
public const global:Object = new Object();
}

global["hello"] = "world";
trace(global.world)