A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: [RESOLVED] Referencing Stage within custom "Global" class

Threaded View

  1. #1
    Senior Member
    Join Date
    Jan 2006
    Posts
    133

    resolved [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:MovieClipTarget_mc:MovieClip):void{
                
    // Remove the previous keyboard listener
                
    stage.removeEventListener(KeyboardEvent.KEY_DOWNPrevious_mc.fOnKeyDownfalse);
                
    // Add a keyboard listener that targets the Target_mc's fOnKeyDown function
                
    stage.addEventListener(KeyboardEvent.KEY_DOWNTarget_mc.fOnKeyDownfalse0true);        
            }
            
        }
        

    MyApplication.fla Timeline:
    PHP Code:
    MyGlobal.objVars.myVar1 "Hello World";
    trace(MyGlobal.objVars.myVar1); // output: Hello World

    MyGlobal.MyFunction(myMC1_mcmyMC2_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?
    Last edited by badaboom55; 01-25-2010 at 03:11 PM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center