[RESOLVED] Referencing Stage within custom "Global" class
Hello All,
I'm new to OOP and I still haven't gotten a handle on coding classes and the appropriate syntax with all the "public" "private" "static" keywords, etc.
Anyway, one thing I miss in AS3.0 is having "out-of-the-box" global variables and functions.
I've read a lot of forums and articles about making a simple "MyGlobal" class that could hold variables and functions which could be called from the timeline as "MyGlobal.doSomething()"
However, I seem to be running into a problem trying to reference "stage" from within one of the global functions... I imagine this is because "stage" is an instance property.
I'm basically trying to add/remove an event listener to the stage whenever the global function "MyFunction" is called.
MyGlobal.as:
PHP Code:
package{
import flash.display.*;
import flash.events.KeyboardEvent;
public class MyGlobal{
public static var objVars:Object = new Object();
public static function MyFunction(Previous_mc:MovieClip, Target_mc:MovieClip):void{
// Remove the previous keyboard listener
stage.removeEventListener(KeyboardEvent.KEY_DOWN, Previous_mc.fOnKeyDown, false);
// Add a keyboard listener that targets the Target_mc's fOnKeyDown function
stage.addEventListener(KeyboardEvent.KEY_DOWN, Target_mc.fOnKeyDown, false, 0, true);
}
}
}
MyApplication.fla Timeline:
PHP Code:
MyGlobal.objVars.myVar1 = "Hello World";
trace(MyGlobal.objVars.myVar1); // output: Hello World
MyGlobal.MyFunction(myMC1_mc, myMC2_mc);
Compiler Error:
Code:
1120: Access of undefined property stage.
Am I missing an import statment, or is there someway I need to declare stage as this.stage?