A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Stage Resizing Class

  1. #1
    Senior Member
    Join Date
    Oct 2000
    Posts
    123

    Stage Resizing Class

    Hey all,

    So I'm finally taking the AS3 plunge. Put it off as long as I can. So I'm rebuilding my portfolio site in AS3, and already need to hit the books (unfortunately don't have any yet).

    So I want to create an external class for resizing the stage. If I have any sites where I want them to act as full screen flash sites, I just want to import this class. Although, I want a generic function to be called onResize so I can adapt it to any future project, and not have specific functions within the resize.

    Here's my StageFullScale class:
    Code:
    package {
    	import flash.display.Stage;
    	import flash.display.StageAlign;
    	import flash.display.StageScaleMode;
    	import flash.events.Event;
    	public class StageFullScale {
    		private var myStage:Stage;
    		public function StageFullScale():void {
    			myStage.scaleMode = StageScaleMode.NO_SCALE;
    			myStage.align = StageAlign.TOP_LEFT;
    			myStage.addEventListener(Event.RESIZE, resizeStage);
    		}
    		private function resizeStage(event:Event):void {
    			trace("RESIZE");
    		}
    	}
    }
    Now I want to create a class for my site which will import this Stage class. Here's that one:
    Code:
    package {
    	import flash.display.MovieClip;
    	import StageFullScale;
    	public class TetDesign extends MovieClip {
    		var myStage:StageFullScale = new StageFullScale();
    	}
    }
    So the class above I'm going to build out the be the main Class for my site, and I want to import my stage class. Any suggestions (I'm sure this is pretty basic AS3).

    Thanks in Advance.

  2. #2
    Flash Your Flex
    Join Date
    Apr 2007
    Location
    Provo, Utah
    Posts
    45
    I just built a stage scaler class, and both of ours look really similar (must be that great minds think alike )

  3. #3
    Senior Member
    Join Date
    Oct 2000
    Posts
    123
    Hey malihk,

    How did you extend your stage class to your document? Basically, I am writing one master class that will run my portfolio site. The stage resizing class will be one component of that, but I can't seem to bring it in for some reason (you can see by my codes above). I also want the resizeStage function to be pretty generic, so I can call it from my master class and do any specific resizing behaviors in that document. Any ideas?

    Thanks!

  4. #4
    Flash Your Flex
    Join Date
    Apr 2007
    Location
    Provo, Utah
    Posts
    45
    Tetuan -

    I really like the use of a master global class (I have loved it since as1) to manage method calls to functions across all scopes. In AS3 it is a little bit more difficult to create a global class, but still very easy. This way you can access your stage and any other properties throughout all your classes. You can read up more on it, but it is basically the idea that a class can be accessed from anywhere (not having to give scope to trace it out). I shorted this up pretty fast so I hope that it works for you.

    This is the main doc class:

    PHP Code:
    package {
        
    import flash.display.*;
        
    import com.agilix.StageScale;
            
    //http://www.uza.lt/blog/2007/04/as3-global-object/
        
    import lt.uza.utils.*
        public class 
    Example extends Sprite{
            
    //Private 
            
    private var global = Global.getInstance();
            public function 
    Tester(){
                global.
    stage this.stage;
                global.
    top this;
                var 
    stageScale = new StageScale();
            }        
        }
        

    and here is the StageScale class

    PHP Code:
    /**
     * @author Chase Brammer
     */
    package com.agilix{

        
    import flash.display.StageAlign;
        
    import flash.display.StageScaleMode;
        
    import flash.events.Event;
        
    import flash.utils.*;
        
        
    //http://www.uza.lt/blog/2007/04/as3-global-object/
        
    import lt.uza.utils.*;
        
        public class 
    StageScale {

            
    //Public
            
    public var onStageScale:Function;
            
            
    //Private
            
    private var _interval;
            
            
    //I really like this global object, so we can reference the stage with
            //out having to pass in any param's in our class creation
            //http://www.uza.lt/blog/2007/04/as3-global-object/
            
    private var global = Global.getInstance();
            
            public function 
    StageScale(){
                
    init();
            }
            
    //Use this to assign an external function on stage scaling
            
    public function set onStageScale(f_function:Function){
                
    onStageScale f_function;    
            }
            private function 
    init(){
                
    //this makes sure that the interval (used to handle processor) 
                //is not called while it is in limbo
                
    _readyToGo true;
                
    //listeners
                
    global.stage.scaleMode StageScaleMode.NO_SCALE;
                global.
    stage.align StageAlign.TOP_LEFT;
                global.
    stage.addEventListener(Event.RESIZEresizeHandler);
                
    //run the scale function on init
                
    setPostions();
            }
            private function 
    resizeHandler(event:Event){
                if(
    _readyToGo) {
                    
    //I use an interval so I can change how much processor
                    //it will use.  Depending on other processor requirements
                    //I like to keep it at 1 (instant) or if I have lots of load
                    //then I can take it to 1000 (1 sec)
                    
    _interval setInterval(stageResized1);
                    
    _readyToGo false;
                }
            };
            private function 
    stageResized(){
                
    //clear out interval and say that we are good to go again on the next resize
                
    clearInterval(_interval);
                
    _readyToGo true;
                
    //run our functions
                
    setPostions();
                
    onStageScale();
            }
            private function 
    setPostions(){
                
    //do calculations off these for scaling etc...
                
    var stageWidth:Number = global.stage.stageWidth;
                var 
    stageHeight:Number = global.stage.stageHeight;
            }
        }

    Last edited by malihk; 05-07-2007 at 03:10 PM.

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