A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: Challenge to Center Working Preloader

Threaded View

  1. #1
    Member
    Join Date
    Apr 2006
    Posts
    49

    Challenge to Center Working Preloader

    I'm in a bit of a pickle and can't sort my way out.

    I'm loading an external swf that has a preloader on Scene 1, and the main content on Scene2. While the content on Scene 2 centers nicely, the preloader content refuses to do so, lol.

    Here's what I've got on my main project timeline:

    Code:
    mcHMI.onRollOver = function() {
    	this.gotoAndPlay("over");
    	}
    
    	mcHMI.onRollOut = function() {
    	this.gotoAndPlay("off");
    	}
    	
    	mcHMI.onRelease = function() {
    	getURL("http://www.hermanmiller.com", "_blank");
    	}
    	
    	mcCOI.onRollOver = function() {
    	this.gotoAndPlay("over");
    	}
    
    	mcCOI.onRollOut = function() {
    	this.gotoAndPlay("off");
    	}
    	
    	mcCOI.onRelease = function() {
    	getURL("http://www.contemporary.ab.ca/", "_blank");
    	}
    	
    
    
    
    
    
    // No scaling and align to top left
    Stage.scaleMode = "noScale";
    Stage.align = "TL";
     
    // Create listener object for when the stage is resized
    var stageListener:Object = new Object();
    Stage.addListener(stageListener);
    
    setBackground();
    
    // Call function when the stage is resized
    stageListener.onResize = function() {
    setBackground();
    }
    
    function setBackground() {
    
    // Position background to middle
    bg._x = Stage.width/2;
    bg._y = Stage.height/2;
    
    mcMenuBarTop._x = Stage.width/2;
    
    
    
    
    
    
    // Scale background to fit width and height
    bg._width = Stage.width;
    bg._height = Stage.height;
    
    // Check if background grew bigger on x or y and
    // adjust other to match to maintain aspect ratio
    bg._xscale = bg._yscale = Math.max(bg._xscale, bg._yscale);
    
    }
    
    // Content floating in middle
    container._x = Stage.width/2;
    container._y = Stage.height/2;
    
    
    sizeListener = new Object();
    sizeListener.onResize = function() {
    	container._x = Stage.width/2;
    	container._y = Stage.height/2;
    
    
    };
    Stage.addListener(sizeListener);
    
    
    
    
    
    
    //start Stage re-size code
    Stage.align = "TL"; 
    Stage.scaleMode = "noScale";
    // ---> Create a new listener object
    var stageListener:Object = new Object(); 
    // ---> Define the resize function...
    stageListener.onResize = function() { 
          // ---> first, get the new dimensions of the stage....
          var stageWidth:Number = Math.round(Stage.width);
          var stageHeight:Number = Math.round(Stage.height);
    	  trace("Stage size is now " + Stage.width + " by " + Stage.height);
          
    	  mcTitleMCmain._x = stageWidth1;
    	  //mcTitleMCmain._y = (stageHeight/1.35) - (mcTitleMCmain._width/1) ;
    	  
    	  btn1._x = stageWidth1;
    	  btn1._y = stageHeight-50;
    	  
    	  
    	  
    	  btna._x = stageWidth-53;
    	  btna._y = stageHeight100;
    	  
    	  btng._x = stageWidth-114;
    	  btng._y = stageHeight80;
    	  
    	  btne._x = stageWidth-166;
    	  btne._y = stageHeight80;
    	  
    	  btnb._x = stageWidth-219;
    	  btnb._y = stageHeight80;
    	  
    	  btnc._x = stageWidth-269;
    	  btnc._y = stageHeight80;
    	  
    	  btnd._x = stageWidth-185;
    	  btnd._y = stageHeight80;
    	  
    	  btnf._x = stageWidth-268;
    	  btnf._y = stageHeight80;
    	
    	    
    	  mcButton1a._x = stageWidth-220;
    	  mcButton1a._y = stageHeight80;
    	  
    	  btnHermanMillerMC._x = stageWidth-113;
    	  btnHermanMillerMC._y = stageHeight-50;
    	  
    	  btnMCDesigner._x = stageWidth-40;
    	  //btnMCDesigner._y = stageHeight200;
    	  
    	  btnMCSustain._x = stageWidth-100;
    	  //btnMCSustain._y = stageHeight200;
    	  
    	  container6._x = stageWidth-560;
    	  container6._y = stageHeight-350;
    	  
    
    	  
    
    	  btnR1._x = stageWidth1;
    	  btnR1._y = stageHeight-320;
    	  
    	  	  
    	  mcMenuBarBottom._x = Stage.width/2;
    	  mcMenuBarBottom._y = stageHeight-61;
    	  
    
    Stage.align = "LT";
    Stage.scaleMode = "noScale";
    //
    myListener = new Object();
    myListener.onResize = centercontent;
    Stage.addListener(myListener);
    //
    function centercontent() {
    wallPaper_mc._x = Math.ceil(Stage.width/2-wallPaper_mc._width/2);
    wallPaper_mc._y = Math.ceil(Stage.height/2-wallPaper_mc._height/2);
    
    container1._x = Math.ceil(Stage.width/2-container1._width/2);
    container1._y = Math.ceil(Stage.height/2-container1._height/2); 
    	
    		
        mcContactNames._x = Math.ceil(Stage.width/2-mcContactNames._width/2);
        mcContactNames._y = Math.ceil(Stage.height/2-mcContactNames._height/2);
    	
    	mcAboutUs._x = Math.ceil(Stage.width/2-mcAboutUs._width/2);
        mcAboutUs._y = Math.ceil(Stage.height/2-mcAboutUs._height/2);
    	
    }
    //
    centercontent();
    
    
    
    	  
    
    };
    // --->  Apply the listener...
    Stage.addListener(stageListener); 
    // ---> Run the function...
    stageListener.onResize(); 
    
    //--------------------//

    container1 listed above is what I'm dumping my swf into...




    A button brings you to the actionscript on the main timeline that calls the swf file:



    Code:
    this.createEmptyMovieClip("container1", 15); 
    var mclListener:Object = new Object(); 
    mclListener.onLoadInit = function(mc:MovieClip) {//is now loaded and initialized in flash,- ready to center 
        mc._x = Stage.width/2 - mc._width/2; 
        mc._y = Stage.height/2 - mc._height/2; 
    } 
    var image_mcl:MovieClipLoader = new MovieClipLoader(); 
    image_mcl.addListener(mclListener); 
    image_mcl.loadClip("ASK-Bimages.swf", container1); 
    centercontent();
    	  
    
    };
    // --->  Apply the listener...
    Stage.addListener(stageListener); 
    // ---> Run the function...
    stageListener.onResize(); 
    
    //--------------------//


    ASK-Bimages.swf has the preloader on Scene 1. Pretty basic stuff. Here's the actionscript:

    Code:
    totalBytes = this.getBytesTotal();
    loadedBytes = this.getBytesLoaded();
    remainingBytes = totalBytes-loadedBytes;
    percentDone = int((loadedBytes/totalBytes)*100);
    totalBytes = this.getBytesTotal();
    loadedBytes = this.getBytesLoaded();
    remainingBytes = totalBytes-loadedBytes;
    percentBar = int((loadedBytes/totalBytes)*100);
    percent = int((loadedBytes/totalBytes)*100);
    percentDone = percent+"%";
    bar.gotoAndStop(percentBar);
    if (_framesloaded == _totalframes) {
    	gotoAndPlay(3);
    }

    As mentioned, the swf loads just fine and stays centered at any resize. The preloader will jump to another position when you resize.

    Any help would be greatly appreciated.
    Tnx
    Last edited by landrvr1; 05-19-2010 at 04:21 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