Global functions in AS3
Posted by
Ziwei
Posted On
Jun 23 2009 2:31 am
Add
Posted in
Actionscript, Tutorials
Setting a global function that’s visible to any classes in your project without any form of import is easy and straightforward with AS3.
First, let us create a AS file called “Global” with the following code
-
- package {
- public class Global {
- public static function performAction():void {
- trace("Called global function")
- }
- }
- }
Now save this file into the document root of your working file or the folder root of any classpath that you defined in the actionscript 3.0 setting under publish settings.
Voila, now you are able to call the function anywhere by calling Global.performAction().

Comments ( 2 )
I’m sorry but the name and content in this article are misleading.
Creating a class named ‘Global’ and accessing a static function thereof doesn’t give you a true global function.
Global functions do not have many benefits. Surely static functions are often better, but I think this article will confuse many developers. Maybe you can improve it?
Rather than creating a true global function, the aim of this article is simply to provide a way to recreate the _global object in AS2 without any importing of classes in AS3. The benefits has more got to do with the programming habits of AS2 coder who are trying to migrate to AS3 than real performance gain.
Remember! Spamming is for losers