A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: positioning a mc with onLoadComplete

  1. #1
    Angkor-What? Gekke_Hollander's Avatar
    Join Date
    Jun 2000
    Location
    Netherlands
    Posts
    234

    positioning a mc with onLoadComplete

    Hi,

    I'm loading a swf into an mc on the stage. After it's loaded I want to center it on stage. I'm doing something like this:

    Code:
    maintimeline = this;
    mainMC.onResize = function() {
    	this._x = (Stage.width+this._width)/4;
    	this._y = (Stage.height+this._height)/4;
    };
    Stage.addListener(mainMC);
    maintimeline.mainMC.onResize();
    //
    var mainMCloader = new MovieClipLoader();
    mainMClistener = new Object();
    mainMClistener.onLoadComplete = function() {
    	updateAfterEvent;
    	maintimeline.mainMC.onResize();
    };
    mainMCloader.addListener(mainMClistener);
    mainMCloader.loadClip("main.swf", maintimeline.mainMC);
    The problem is that, even while I'm using onLoadComplete, Flash thinks that the mainMC._width = 0. It is only, when I make the timeline play a couple of frames that mainMC._width finally results in the real size (the one of the loaded swf).

    What I'm I doing wrong???

    Cheers
    MX 2004 Pro - Oops I did it again!!!
    SWF, it's a journey... not a destination

  2. #2
    Angkor-What? Gekke_Hollander's Avatar
    Join Date
    Jun 2000
    Location
    Netherlands
    Posts
    234
    anyone?
    MX 2004 Pro - Oops I did it again!!!
    SWF, it's a journey... not a destination

  3. #3
    Monkey Moderator Lexicon's Avatar
    Join Date
    Jul 2001
    Location
    UK
    Posts
    2,038
    try using onLoadInit instead of onLoadComplete.

    onLoadComplete executes before the loaded movieClip is initialised and so you do not have access to its methods and properties etc. onLoadInit executes when the movie has finished loading and has initialised.
    www.lexicon-design.co.uk
    If we aren't supposed to eat animals, then why are they made of meat?
    If Vegetarians like animals so much, why do they eat all their food?

  4. #4
    Angkor-What? Gekke_Hollander's Avatar
    Join Date
    Jun 2000
    Location
    Netherlands
    Posts
    234
    That helped, thanx! Somehow I though that onLoadComplete was trggered when the load was completed and onLoadInit was triggered when the load initiated...

    One more question though. I want to position the mc onLoadInit but I can't seem to call the function correctly...

    Code:
    maintimeline = this;
    maintimeline.mainMC.onResize = function() {
    	trace(this._width);
    };
    //
    var mainMCloader = new MovieClipLoader();
    mainMClistener = new Object();
    mainMClistener.onLoadInit = function() {
    // going wrong here I think...
    	maintimeline.mainMC.onResize();
    };
    mainMCloader.addListener(mainMClistener);
    mainMCloader.loadClip("ain.swf", maintimeline.mainMC);
    Any clues on this?

    Cheers
    MX 2004 Pro - Oops I did it again!!!
    SWF, it's a journey... not a destination

  5. #5
    Angkor-What? Gekke_Hollander's Avatar
    Join Date
    Jun 2000
    Location
    Netherlands
    Posts
    234
    Found it thanx anyway

    Code:
    var mainMCloader = new MovieClipLoader();
    mainMClistener = new Object();
    mainMClistener.onLoadInit = function() {
    	mainMC.onResize = function() {
    		this._x = (Stage.width-this._width)/2;
    		this._y = (Stage.height-this._height)/2;
    	};
    	Stage.addListener(mainMC);
    	maintimeline.mainMC.onResize();
    };
    mainMCloader.addListener(mainMClistener);
    mainMCloader.loadClip("main.swf", maintimeline.mainMC);
    MX 2004 Pro - Oops I did it again!!!
    SWF, it's a journey... not a destination

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