dcsimg
A Flash Developer Resource Site

Results 1 to 12 of 12

Thread: loadmovie resize swf

  1. #1
    Junior Member
    Join Date
    Aug 2005
    Posts
    8

    loadmovie resize swf

    hi there, I read through all the posting related to loadmovie resize but doesn't seem like I find the answer, so here is my question for you guys:

    I try to load an external swf in my flash program. The effect I want to accomplish is to fit the external swf into my movie clip container with auto resize. Say, my movie clip container has width=200 and height=100. Now, if the external swf has width=200 and height=200, after the loadmovie, I want to see the external swf fits into the movie clip container with width=100 and height=100 (resize with ratio preserved according to the container's max width or height).

    I can't use xscale or yscale to pre-adjust the external swf because I don't know the dimension of the swfs until load time. I tried to set _width and _height of the movie clip to my container's dimension after the movieload statement, but the swf doesn't even show up. I trace it, and those two numbers always show up zero. I am using Flash MX Professional 2004. Am I doing something wrong here? Please help

  2. #2
    Monkey Moderator Lexicon's Avatar
    Join Date
    Jul 2001
    Location
    UK
    Posts
    2,038
    You will need to have loaded the clip in it's entirety before editing the dimensions of the clip (you can detect with an onEnterFrame event or setInterval testing for bytesLoaded and bytesTotal). Simply having the code after the loadMovie command is not enough as the code will be executed before the clip has had time to load (hense the 0 width and height you currently get)!

    Try using the MovieClipLoader() class instead.
    That will enable you to easily detect when the clips has finished loading by listening for onLoadInit. You can put all your resize code in the onLoadInit function.

    e.g.

    Code:
    // container movieClip x and y positions
    var container_x = 100;
    var container_y = 100;
    // container max width and height parameters
    var max_width = 150;
    var max_height = 150;
    
    var loader_listener:Object = new Object();
    loader_listener.onLoadInit = function(target_mc:MovieClip):Void
    {
    	// resize to fit width 
    	target_mc._width = max_width;
    	target_mc._yscale = target_mc._xscale;
    	// if height is too much then resize to fit height
    	if(target_mc._height>max_height)
    	{
    		target_mc._height = max_height;
    		target_mc._xscale = target_mc._yscale;
    	}
    	// center clip (rounded to nearest pixel to keep things sharp)
    	container_mc._x = Math.round(container_x + (max_width - target_mc._width)/2);
    	container_mc._y = Math.round(container_y + (max_height - target_mc._height)/2);
    	
    };
    var loader:MovieClipLoader = new MovieClipLoader();
    loader.addListener(loader_listener);
    loader.loadClip("myswf.swf", container_mc);
    Last edited by Lexicon; 08-15-2005 at 02:08 PM.
    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?

  3. #3
    Senior Member pellepiano's Avatar
    Join Date
    Feb 2000
    Location
    Stockholm, Sweden
    Posts
    15,151
    If you load a swf into a container mc, anything previously in it will be replaced by the external swf .

    If you want all the external swf's to have a fixed size you can simply put some code ON the container clip.

    onClipEvent(load){
    this._width=100;
    this._height=100;
    }

    -Pelle Piano
    // Image Gallery
    www.studiobild.com
    // Photo Blog
    http://talesofthepixel.blogspot.com

  4. #4
    Monkey Moderator Lexicon's Avatar
    Join Date
    Jul 2001
    Location
    UK
    Posts
    2,038
    Quote Originally Posted by pellepiano
    If you load a swf into a container mc, anything previously in it will be replaced by the external swf .

    If you want all the external swf's to have a fixed size you can simply put some code ON the container clip.

    onClipEvent(load){
    this._width=100;
    this._height=100;
    }
    That will not keep the correct aspect ratio, it will resize the clip to 100*100.
    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?

  5. #5
    Junior Member
    Join Date
    Aug 2005
    Posts
    8
    Quote Originally Posted by Lexicon
    Code:
    var loader:MovieClipLoader = new MovieClipLoader();
    loader.addListener(loader_listener);
    loader.loadClip("myswf.swf", container_mc);
    Lexicon, thanks for the pointers. Your code is well written. I like your monkey as well. They are cute. Anyway, I try to put in one of my swfs, but it doesn't seem to like MovieClipLoader class. Nothing shows up. The same swf works perfectly fine with loadmovie though..

    I have attached the swf for your reference. could you help me to take a look at that?
    Attached Files Attached Files

  6. #6
    Monkey Moderator Lexicon's Avatar
    Join Date
    Jul 2001
    Location
    UK
    Posts
    2,038
    is that the right fla? There's no code in it?

    Long past bed-time for me, If you can post an fla with some code in then I'll take a look in the morning.

    nitey nite

    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?

  7. #7
    Junior Member
    Join Date
    Aug 2005
    Posts
    8
    sorry, I didn't know you were in bed already. Here is the original FLA that is calling the test.swf I posted previously.
    Attached Files Attached Files

  8. #8
    Monkey Moderator Lexicon's Avatar
    Join Date
    Jul 2001
    Location
    UK
    Posts
    2,038
    As you stated you were using MX 2004 Pro then I assumed you were publishing for Flash 7. The MovieClipLoader class only works in Flash player 7.

    Here is another method using an onEnterFrame action instead. This works for Flash Player 6.

    Enjoy
    Attached Files Attached Files
    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?

  9. #9
    Junior Member
    Join Date
    Aug 2005
    Posts
    8
    hmm, don't know why the test.swf still doesn't show up... I already set the publishing setting of the flash player to 7.0. It may be a bug in my Flash MX 2004 pro v7.2. Thanks a lot anyway, really appreciated your help.

  10. #10
    Monkey Moderator Lexicon's Avatar
    Join Date
    Jul 2001
    Location
    UK
    Posts
    2,038
    strange, it's working for me. Did you try Flash player 7 AND AS2?
    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?

  11. #11
    Junior Member
    Join Date
    Aug 2005
    Posts
    8
    I installed another version and it works. Thanks so much.

  12. #12
    Junior Member
    Join Date
    May 2007
    Location
    Maryland, US, Earth
    Posts
    1

    Similar Problem

    I just graduated from UMD, and I've been trying to do the same thing with a collection of flash games I've made for my portfolio site. I had similar resizing code to that given here, but a test .fla using that code exhibited the same errors. I've attached that test .fla file below. Here's a description of the problems:

    1) Certain of my games just stopped playing 1/2 way through. When they did stop playing, it usually coincided with a slieu of "*** Security Sandbox Violation *** ..." errors. I have the security set to "access network only," so those should go away when run from a server, right?

    2) Certain of my games don't even resize correctly. I suspect this may be a side-effect of #1?

    I don't want to release my games before my site goes up, but I found one online that seems to exhibit the same problems, which the attached .fla tries to load, but failed on my computer. Any ideas?

    (For my portfolio site, I'm using Flash 8 Pro, and publishing to Flash7/AS2. Some of my games' SWF's are published to Flash 8/AS2, which may be part of the problem?)
    Attached Files Attached Files

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