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
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?
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?
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?
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?
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
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?
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.
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?
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?)