A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: center loaded swf in container

  1. #1
    Member
    Join Date
    Nov 2005
    Posts
    87

    center loaded swf in container

    starting on AS3 and liking some of it but going out of my mind with trying to center a loaded swf.

    here is my code:
    PHP Code:
    // SETUP CONTAINER
    var container:MovieClip = new MovieClip();
    this.addChild(container);
    container.= ((stage.stageWidth/2) - (container.width/2));
    container.= ((stage.stageHeight/2) - (container.height/2));

    // CENTER CONTAINER
    function centreContainer(evt:Event):void {
        
    container.= ((stage.stageWidth/2) - (container.width /2));
        
    container.= ((stage.stageHeight/2) - (container.height /2));
        
    trace("c.w = " container.width);
        
    trace("c.x = " container.x);
    }

    function 
    loadComplete(evt:Event) {
        
    stage.addEventListener(Event.RESIZEcentreContainer);
    }

    // CREATE LOADER
    var loader:Loader = new Loader();
    var 
    loadProgress:Number;
    var 
    sectionToLoad:String;

    // LOADER FUNCTION
    function loadSection(sectionPath:String):void {
        var 
    loaderURLReq:URLRequest = new URLRequest(sectionPath);
        
    loader.load(loaderURLReq);
        
    loader.contentLoaderInfo.addEventListener(Event.OPENloadBegin);
        
    loader.contentLoaderInfo.addEventListener(Event.COMPLETEloadComplete);
        
    loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESSloadDuring);
        
    container.addChild(loader);
        
    //trace("clicked");

    a similar resize function for a movieclip on the stage works perfectly, it only seems to have trouble with loaded swfs. it seems that it isn't subtracting the proper width.

    any help is greatly greatly greatly appreciated!
    Last edited by davidhunter; 02-03-2009 at 07:05 PM.

  2. #2
    Ө_ө sleepy mod
    Join Date
    Mar 2003
    Location
    Oregon, USA
    Posts
    2,441
    The width is the size of the bounding box - not the size of the stage the swf was compiled at.

  3. #3
    Member
    Join Date
    Nov 2005
    Posts
    87
    so you're saying that if i specify the width of the swf then it should work ok?

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