External Preloader and Auto Center

  • brettbash
  • Novice
  • Novice
  • User avatar
  • Posts: 16

Post 3+ Months Ago

I. Auto Centering Dilemma
I'm working on a website with a width of 100%. I have entered that all into my html file with swfobject. When it loads everything is centered, but when I resize the browser window my swf shifts left - then I can't get it back to the center unless I reload the page. My flash files consist of a mainloader.swf (preloader) and main.swf (content). Both are the same size in flash. In the pre loader, I have the loader in a movie clip on the main timeline that has the registration point top left (x:0, y:0) and that is the width of the swf. Also on the main time line of the preloader swf is an action frame for centering everything (since the preloader and the main.swf are the same dimensions and have the same registration point.). This is what I have in my action frame:

Code: [ Select ]
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
function resizeHandler(e:Event):void
  atom.x = (atom.stage.stageWidth / 2) - (atom.width / 2);
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.addEventListener(Event.RESIZE, resizeHandler);
stage.dispatchEvent(new Event(Event.RESIZE));
  1. import flash.display.StageAlign;
  2. import flash.display.StageScaleMode;
  3. import flash.events.Event;
  5. function resizeHandler(e:Event):void
  6. {
  7.   atom.x = (atom.stage.stageWidth / 2) - (atom.width / 2);
  8. }
  10. stage.align = StageAlign.TOP_LEFT;
  11. stage.scaleMode = StageScaleMode.NO_SCALE;
  12. stage.addEventListener(Event.RESIZE, resizeHandler);
  14. stage.dispatchEvent(new Event(Event.RESIZE));

atom is the instance name of the pre loader movie clip.
Maybe there is something not quite right in my code, or maybe I need to do something else additional with the main.swf.

II. External Preloader
The problem with my external preloader is that it loads the main.swf, but it seems to load while main.swf plays. So once main.swf is loaded, it's on frame 180 playing already. I want it to start fresh at frame 1 on the main.swf. After the preloader loads, it plays a fade out sequence on the preloader swf - you'll see in the actionscript. The main.swf loads over that, so I have the main.swf start to animate in on it's 30th frame. So here is my loading actionscript in the preloader swf:

Code: [ Select ]
var myMovie:Sprite;
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, loadProgress);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadComplete);
loader.load(new URLRequest("main.swf"));
// Update the percentage display
function loadProgress(e:ProgressEvent):void
    var perc:Number = e.bytesLoaded / e.bytesTotal;
    percentage_mc.percentage.text = Math.ceil(perc*100).toString();
// Load complete, hide the animating graphic and text
function loadComplete(e:Event):void
myMovie = Sprite(loader.content);
loader.contentLoaderInfo.removeEventListener( ProgressEvent.PROGRESS, loadProgress);
loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, loadComplete);
  3. stop();
  5. var myMovie:Sprite;
  6. var loader:Loader = new Loader();
  8. loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, loadProgress);
  9. loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadComplete);
  10. loader.load(new URLRequest("main.swf"));
  12. // Update the percentage display
  13. function loadProgress(e:ProgressEvent):void
  15. {
  17.     var perc:Number = e.bytesLoaded / e.bytesTotal;
  18.     percentage_mc.percentage.text = Math.ceil(perc*100).toString();
  21. }
  23. // Load complete, hide the animating graphic and text
  24. function loadComplete(e:Event):void
  26. {
  29. myMovie = Sprite(loader.content);
  30. addChild(myMovie);
  34. gotoAndPlay(31);
  36. loader.contentLoaderInfo.removeEventListener( ProgressEvent.PROGRESS, loadProgress);
  37. loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, loadComplete);
  39. }

on frame 31 on the preloader where it ends I just have a stop();

Any ideas on why it's being retarded on me? Any help would be great :-)

Post Information

  • Total Posts in this topic: 1 post
  • Users browsing this forum: No registered users and 5 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum

© 1998-2017. Ozzu® is a registered trademark of Unmelted, LLC.