PDA

View Full Version : Retaining original .jpg size with loadMovie()


divarch
02-05-2004, 10:23 AM
Hi guys, I have done a search throughout a forum, but was unable to find an answer (also checked out CB's useful thread but no go), so:

How can I make loaded .jpg retains it's original size, regardless of container that loads it.

So far, when I load it up, container stretches(or resamples) the loaded content to fit it's own size.

The reason I need this, is I want to container dynamically resize( scaling with ease), and without it it cannot be done.

Thanks for any help.

CyanBlue
02-05-2004, 10:39 AM
Howdy... :)

I don't get your question... :D
So, you want to load the JPEG into the Flash and you want the size of the JPEG file maintained when it is loaded into the Flash or you want to maintain the size of the movieclip that you are trying to load the JPEG file into???
(Yeah... I know... I need more coffee... :D)

divarch
02-05-2004, 12:06 PM
Hehe, coffee..

No, I want to set the size of the container based on the size of image loaded.

Thanks for trying to help

CyanBlue
02-05-2004, 12:24 PM
Um... It turns out to be that it is not the coffee problem...

You just made me to test it though... :)

The first one... The holder movieClip is 450 x 300 and I am loading 400 x 262 JPEG file and Flash is loading without stretching...

The second one... The holder is 300 x 200, and Flash is stretching the JPEG file as it should be...

The third one... The empty movieclip holder... Same thing as the second one...

Now, I AM confused... :confused:

senocular
02-05-2004, 12:40 PM
There should be no "stretching".

Loaded jpegs are not changed when they are loaded. They come in at the size they actually are. When they are placed in a movieclip, that movieclip's _width and _height may change based on this new content, but that new content (the image) has not changed in size iself.

For example, an empty clip has a height and width of 0. Why? Because its empty. Loading an image into that clip will then change the content of that clip making its extents stretch beyond 0,0 out to the size of the clip (a movieclip's size is based on the content within it).

If your movieclip already has content, say, another image, then that content will be removed when a new image is loaded (changing its original height and width to 0). Then, once the loading of the new clip is complete, the size of the clip will reflect its current content... or the image within it, whatever size that image may be.

The only time a loaded image will not be its actual size is if its being effected by any scale modifiers by any of the movieclips in its _parent heiarchy (including the clip it was loaded into). So if a movieclip is loaded into _root.box.can, if box or can has any _xscale or _yscale properties other than 100, the image will not be shown at original size.

... Im not sure how this all applies to what you're working on, but maybe this will bring some things to light.

divarch
02-05-2004, 04:50 PM
First thanks guys for excellent feedback, I got answers all right.

Senocular, I am loading images in a author-made container without affecting it's x(y)scale props through AS.
I have been working on this in terms of practice, so to speak, in preparing what I will use in creating my own portfolio which will have img gallery among other things.

The problem was that, once image loads it should retain it's size, because I already resampled them in another app.

CB, your post and examples very much explain itself, and I thank you very much on that.

I will attach an example of what I did,(ignore the preloader)
So, if I change container's size manually, not through AS, image loaded is resized to fit, (enlarged or shrank). That is what bothers me.

I will try with 'empty clips', I only did it this way, to visually position my images.

Another thing is, is there a way I could refer to them after the loading part (I know container's gone after loading) so can I do some functions on it, like scaling or positioning runtime.

Thanks again on your feedback, and sorry I am late with response, I was out.

Cheers

divarch
02-05-2004, 04:51 PM
Where's the file?? A, here it is...

gaza
02-05-2004, 06:46 PM
Hi, divarch,

Looking at your file you have scaled container_mc and as senocular this is going to effect you image your loading.
So by creating a empty mc first would eliminate this problem which is what senocluar also said.
If you are wanting to set the a property based on the container_mc, setting the prop as a var before you load your image enables you to call it and set the loaded image prop to the old container_mc prop.

divarch
02-05-2004, 07:01 PM
Yes, I understood what Senocular told me, I've created a new container, without any scaling and now it works, with images untouched.

For the second part, I am not quite sure how to call some event handlers on the container, once image is finished loading.
Like an 'onEnterFrame' event for example, just to move it around a bit, for a start.

Thanks for your input

edit Yeap, the coords settings after loading wouldn't work, but since I created a new container without manual rescaling, now it does work.

I will go now experimenting with some more serious movement, in the meantime, thanks everyone again for their efforts

gaza
02-05-2004, 07:29 PM
In reply to the second part, just call the new container mc that you load you image into just as you would any other event, just make sure its 100% loaded before calling the event eg new_container._width > 0;

divarch
02-05-2004, 07:31 PM
Yes, already playing around, thanks again

JeremyToaster
03-25-2004, 08:05 PM
Ok I have read this thread and just about every other single thread on loading external jpegs into Flash.

Everyone seems to be doing WAY more complicated things than I want to do and there for have gone past the knowledge I need, or are assuming that knowledge first.

I just upgraded to Flash MX 2004 Pro, been using good all Flash 5 for a few years now and started with 4 when it first came out. I have recently in the past year started getting more into the coding end getting more interactive with my sites. But with limited time I tend to only find solutions for what I currently need help on and not learning the whole AS code overall.

So here's what I've got going on.....

A .swf that loads text (got that all figured out fine) and scrolls it (no problems there) and then loads images (album covers and inserts), just finally got that working last night. Now I am trying to scale the images (jpegs) down to proabably 50px by 50px, not sure yet need to check and see once it works. So once I can load them small then I can move onto to putting these empty MCs that load the jpegs into a small scroller to scroll through all the album artwork, then I want to allow the user to click or mouse over the individual MCs containing the jpegs and have them scale to full size, 340 x 340.


But first thing first, the size issue....

Here is the code, on the last frame this is loaded ::

stop ();
_root.text.loadVariables ("mega002text.txt","");
{
mcAlbumcover.loadMovie( "http://www.megalithrecords.com/images/brazil-mega-cover.jpg" );
mcAlbumcover2.loadMovie( "http://www.megalithrecords.com/images/brazil-mega-cover-2.jpg" );
mcAlbumcover3.loadMovie( "http://www.megalithrecords.com/images/brazil-mega-cover.jpg" );
}

The MCs contain no code and are empty of anything until the jpegs are loaded. In a post above, something was eluded to changing the MCs sizes once loaded? But needs to be done on the root level. So set the x(y)scale property in the main timeline last frame? If so, what is the most simple uncomplicated shortest code to do so :)

Thanks all...

divarch
03-25-2004, 10:19 PM
Hi Jeremy, I have no doubt you searched the forum since you found this old post. So, I will not redirect you to another thread ... ;)
If you want to change any property of loaded clip (their containers) you must wait 'till content is fully loaded. That's the trick..
mcAlbumcover.loadMovie( "http://www.megalithrecords.com/images/brazil-mega-cover.jpg" );
if(mcAlbumcover.getBytesLoaded()==mcAlbumcover.get BytesTotal()){
mcAlbumcover._width=50;
mcAlbumcober._height=50;
}

The code is very pseudo, but I hope you get the picture.
Cheers ;)

JeremyToaster
03-25-2004, 10:35 PM
Hey thanks, the width worked, but the height did not? Strange.....

BTW I very much enjoy the short and sweet code ;)

divarch
03-25-2004, 10:37 PM
If you copied and pasted what I 've written, notice the typo..

JeremyToaster
03-26-2004, 08:48 AM
Haha, yea I actually tried to respond and let you know I figured it out last night right away, but the board wasn't loading up for me :(
Thanks for the help, I was suprised I caught the type so quickly, usually I'll spend hours hunting through everything just to keep missing that period that is out of place or some crap, then right as I am giving up to do something else I figure it out and it's like "Doh!"

But thanks again, now onto to enlarging on command and placing inside scroll movie!

divarch
03-26-2004, 08:51 AM
Good luck! :)