ActionScript Guru - Porting _global from AS2 to AS3

Global variables

The _global variable has been removed in ActionScript 3.0, it is suggested that you use specific objects that are created in the global scope to store your data instead of globing unrelated bits and pieces under one global object. However if you absolutely need a general global object here is how you would do it. Create a file in the root of your class directory called _global.as and drop the following code into it.//declaration

Code:

package {

// this reinstates the _global object that was removed from from AS3

// however one thing has changed the global object must have a

// category for storing data dynamicaly

//ex: _global.ply.name

//this is the name of the player stored in the global object

public class _global {

public static var ply:Object = new Object();

public static var gen:Object = new Object();

public static var glob:Object = new Object();

}

}

/*definitions here are automatically accessible to all code in the file where

this is being declared. Aka this is a security risk. Allowing a hacker to insert

code into the global object at run time and then they can try and run it from

anywhere in your program. */

 

Comments (0)add comment

Write comment
quote
bold
italicize
underline
strike
url
image
quote
quote
smile
wink
laugh
grin
angry
sad
shocked
cool
tongue
kiss
cry
smaller | bigger

security image
Write the displayed characters


busy