Skip to main content
Known Participant
December 23, 2010
Question

addchild browser resize

  • December 23, 2010
  • 2 replies
  • 532 views

Hey Guys! I got my external swf to center...However, when I resize my browser the external swf dissapears off the screen (I can still hear it's music though) Anybody have any suggestions? Heres my class code:

package {
     
     import flash.display.Sprite;
     import flash.display.Loader;
     import flash.net.URLRequest;
     import flash.events.Event;
    import flash.display.StageAlign;
    import flash.display.StageScaleMode;
     
     public class Main extends Sprite{

          private var container:Sprite;
          
          public function Main(){
               
               container = new Sprite();     
               this.addChild(container);
               var url:URLRequest = new URLRequest("index2.swf");
               var loader:Loader = new Loader();
               loader.load(url);
               loader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler);
               
               this.stage.scaleMode = StageScaleMode.NO_SCALE;
            this.stage.align = StageAlign.TOP_LEFT;
          }
          
          private function completeHandler(event:Event):void{               
               this.addChildAt(bg,0)
               this.container.addChild(event.target.content);
               this.container.x = this.stage.stageWidth/2 - event.target.width /2;
               this.container.y = this.stage.stageHeight/2 - event.target.height /2;
               bg.width = stage.stageWidth;
               bg.height = stage.stageHeight;
               bg.x = 0
               bg.y = 0

               
               this.stage.addEventListener(Event.RESIZE, resizeHandler);
          }
          
          private function resizeHandler(event:Event):void{
               this.addChildAt(bg,0)
               this.container.x = this.stage.stageWidth/2 - event.target.width /2;
               this.container.y = this.stage.stageHeight/2 - event.target.height /2;
               bg.width = stage.stageWidth;
               bg.height = stage.stageHeight;
               bg.x = 0
               bg.y = 0
          }
     }
}

This topic has been closed for replies.

2 replies

Known Participant
December 26, 2010

Hey guys, can someone PLZ help me out. I have tried EVERY possible variation of as2/as3. I have an mc named bg that I would like to be the fullbrowser background image and I would like to load an external swf on top of that and center it. That's it! can someone plz tell me whats wrong inside the code above?

December 24, 2010

try:

private function resizeHandler(event:Event):void{
               this.addChildAt(bg,0)
               this.container.x = this.stage.stageWidth/2 - event.target.width /2;
               this.container.y = this.stage.stageHeight/2 - event.target.height /2;
               bg.width = stage.stageWidth;
               bg.height = stage.stageHeight;
               bg.x = 0
               bg.y = 0

               addChild(container); // <-  added
          }

Known Participant
December 24, 2010

STILL dissapears....could it be an issue that Im loading an AS2 swf inside a AS3 swf?