Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Resize loaded jpg in movieclip 1

Status
Not open for further replies.

D2C

Programmer
Aug 27, 2001
86
BE
Hi there,

I am loading a jpg in my movie with the following actionscript:

_root.createEmptyMovieClip("jpg", 10);
jpg.loadMovie ("test.jpg");
jpg._x = 2
jpg._y = 50

I want my loaded jpg to resize automatically according to the size of my Movieclip (should I also set the size of my MC?). Is this possible and/or how can I do it?

This is urgent, so thank you very much for your quick response!!
 
The MC will take the size of the loaded .jpg into it.

Regards,

cubalibre2.gif
 
That's the problem,
I want my mc to be a fixed size, and the image should resize according to the size of the mc.

Thanks!
 
Not a very good idea to resize your .jpg within Flash. It should be imported or loaded at the size it will be used in Flash.

Regards,

cubalibre2.gif
 
Use Xres3 to resize your pix's first.

If you can't find xres anymore, send me an email.

KiwiJor
jor.jpg
 
KiwiJor hi where can I get Xres3

W i K
 
You can easily resize the clip the jpeg is loaded into. Keep in mind, you must wait until the jpeg is finished loading before adjusting. One way to do that is to use the MovieClipLoader class which is available with Flash 2004.
Code:
var mcl:MovieClipLoader = new MovieClipLoader();
var listener:Object = new Object();
listener.onLoadInit = function(target_mc:MovieClip) {
    target_mc._width = 400;
    target_mc._height = 200;
}
mcl.addListener(listener);

mcl.loadClip(picUrl, myClip);

If you're using an earlier version of Flash, I'm not quite certain how you would determine when the image has finished loading other than perhaps using a setInterval method to frequently test for a non-zero width of the initially empty target clip.

Good luck.

Mike
 
for mx you have to use an onload command to resize once the jpeg has fully loaded

i have a script if you need it
 
thanks this is great I am using flash mx 2004 I will try the method that msteggo brought to my attention and I will get back to you guys on it.Once again many thanks



W i K
 
hey thanks msteggo, one more thing though how can I make it keep its apect ratio just in case I have pics of differet sizes????

thanks again

W i K
 
I do certainly agree with you on the jpeg scaling for the most part.

That said, I also believe that too many situations exist where the conveniences far outweigh the quality-loss, to fully trash the idea.

As a matter of fact, I just finished a medium-scale project where scaling not only helped, but was actually required for some of more integral functionality.

Being somewhat of a theoretical purist in this area, I'll admit that I was quite reluctant at first. Only after seeing the results with the first-level testing was I convinced of it's application in this context.

Wikfx, to maintain the original aspect ratio is to calculate it just after loading and before you change the dimensions.

Then go ahead and change the limiting dimension, then making the same proportionate change to the other dimension.

For example, adjusting the code posted above,
Code:
listener.onLoadInit = function(target_mc:MovieClip):Void {
    var aspectRatio = target_mc._width / target_mc._height;
 // Say i need the width to be 75, and height to match ratio
    target_mc._width = 75;
    target_mc._height = target_mc._width / aspectRatio;
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top