A Flash Developer Resource Site

Results 1 to 14 of 14

Thread: loading jpg and resizing

  1. #1
    OpticallyDevoted
    Join Date
    Sep 2002
    Location
    RI
    Posts
    134

    loading jpg and resizing

    How can I display an image by percent rather than a standard point value?

    Say the image is x500 by y800 and I want to display it within a 130x80 box at its proper aspect ratio, how would I go about that?

    I used to use:

    Code:
    loadMovie("directory/directory/image.jpg", "emptyclip1");
    In a blank frame, then:

    Code:
    onClipEvent (data) {
    	this._width = 130;
    	this._height = 80;
    }
    On the empty mc.

    But that's not gona work the imaghe distorts to fill the box.

    Any advice on how to load a large image and constrain it into that small space with its proper aspect ratio intact would be greatly apreciated!

  2. #2
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    If you know the size of your image resize it using _xscale or _yscale.

    this._xscale = 25;
    this._yscale = 25;

    for an image with width of 400 scaled to 100.

    Another possibility is to use the Loader component.
    - The right of the People to create Flash movies shall not be infringed. -

  3. #3
    OpticallyDevoted
    Join Date
    Sep 2002
    Location
    RI
    Posts
    134
    Thanks for the reply, cancerinform.

    The image size is a variable.

    I've been doing some searching and found lots of post of people trying to do something similar but not exactly the same.

    Is there a way to show the image based on a percentage? Like at 10% or 5%

    Example would be, say an image is 700x640 and I want to display it at 5%, it would resize to 35x32, then show but not distorting within a 130x80 emptymovieclip?

  4. #4
    Flashmatics silentweed's Avatar
    Join Date
    Mar 2005
    Location
    London, UK
    Posts
    4,875
    you may have to rethink the way u are doing it ..if an image is say 300 x 300 px i.e a ratio of 1:1 , there is no way you can show it as 130 x 80 (i.e ratio 13:8) without distortion..

    the ratio of width to height of the original image will always have to be 13:8 as well, if u want to fit it into 130 x 80 pixels without distortion...
    Flashmatics | Flashmatics Library (free downloads)
    -----------------------------------------------------
    Latest Projects:
    The Dead Room | Are You Smarter | Prison Break (Frame A Friend) | Beck's Fusions | The 24 Experience

    -----------------------------------------------------
    Flash Certified Developer

  5. #5
    OpticallyDevoted
    Join Date
    Sep 2002
    Location
    RI
    Posts
    134
    Thanks silentweed but that's not exactly what I want to do.

    I want to show it at a percentage of the original size, still at 1:1, within an emptymovieclip that has a set size.

  6. #6
    Flashmatics silentweed's Avatar
    Join Date
    Mar 2005
    Location
    London, UK
    Posts
    4,875
    so u mean you dont mind if it gets cropped?
    Flashmatics | Flashmatics Library (free downloads)
    -----------------------------------------------------
    Latest Projects:
    The Dead Room | Are You Smarter | Prison Break (Frame A Friend) | Beck's Fusions | The 24 Experience

    -----------------------------------------------------
    Flash Certified Developer

  7. #7
    OpticallyDevoted
    Join Date
    Sep 2002
    Location
    RI
    Posts
    134
    Sorry for the confusion,

    In the case of the 700x640 image, which would actually be a variable as the image size can be any size. Flash would resize that 700x640 to 12% so it can fit at 1:1 inside a 130x80 emptymovieclip, making the final image size, 88x80. Centered inside the emptymovieclip.

    If the image was 1024x768, horizontal, flash would resize it at 1:1 to 10% of it's original size to fit inside the 130x80 emptymovieclip giving the final image size of 107x80.

    A 500x800 vertical image, would be resized at 1:1 to 10% of it's orginal size to fit inside a 130x80 emptymovieclip giving it a final size of 50x80.

    And so on... So far I would think the image size is needed first, then the contraint value of 130x80 (or whatever it is) so that, somehow, flash would generate the new image size to display. This is where I'm blind.

    The image can't be cropped, or distorted. Just scaled, 1:1.

  8. #8
    Flashmatics silentweed's Avatar
    Join Date
    Mar 2005
    Location
    London, UK
    Posts
    4,875
    aaah i see what u mean ... the following script is an example which will resize any image to fit within 130 x 80 while respecting its widht/height ratio ..the following example loads an image called orange.jpg in the same directory


    Code:
    this.createEmptyMovieClip("mcImageHolder", 1);
    
    var mcl:MovieClipLoader = new MovieClipLoader();
    var mclListener:Object = {};
    mcl.addListener(mclListener);
    
    mcl.loadClip("orange.jpg", "mcImageHolder");
    
    mclListener.onLoadInit = function(mcTarget:MovieClip):Void{
    	while(mcTarget._width > 130 || mcTarget._height > 80){
    		mcTarget._xscale -= 0.1;
    		mcTarget._yscale -= 0.1;
    	}
    	
    }
    Last edited by silentweed; 02-04-2007 at 11:43 AM.
    Flashmatics | Flashmatics Library (free downloads)
    -----------------------------------------------------
    Latest Projects:
    The Dead Room | Are You Smarter | Prison Break (Frame A Friend) | Beck's Fusions | The 24 Experience

    -----------------------------------------------------
    Flash Certified Developer

  9. #9
    OpticallyDevoted
    Join Date
    Sep 2002
    Location
    RI
    Posts
    134
    Thanks for your time silentweed.

    I tried that code in a blank frame. But it threw me some errors.

    **Error** Symbol=Symbol 96, layer=Layer 15, frame=9:Line 9: '{' expected
    mclListener.onLoadInit = function(mcTarget:MovieClip):Void{

    **Error** Symbol=Symbol 96, layer=Layer 15, frame=9:Line 15: Unexpected '}' encountered
    }

    Total ActionScript Errors: 2 Reported Errors: 2


    EDIT****

    I tried it in a fresh flash file and it worked sorry bout that, maybe it was me, Ill try again in my working file.

    EDIT 2******

    I get no errors in a fresh file but when I try to implement it into my working file I get the errors above.
    Last edited by TCSP; 02-04-2007 at 12:15 PM.

  10. #10
    Flashmatics silentweed's Avatar
    Join Date
    Mar 2005
    Location
    London, UK
    Posts
    4,875
    looks like u have an extra or missing } somewhere in your code...
    Flashmatics | Flashmatics Library (free downloads)
    -----------------------------------------------------
    Latest Projects:
    The Dead Room | Are You Smarter | Prison Break (Frame A Friend) | Beck's Fusions | The 24 Experience

    -----------------------------------------------------
    Flash Certified Developer

  11. #11
    OpticallyDevoted
    Join Date
    Sep 2002
    Location
    RI
    Posts
    134
    Yeah it tells me those errors when I add your code. I dont get the error when i dont use it. And like I said, it works in a fresh file. Single frame, with the code and it works. It places the image at 0.0 though.

    I was wondering if maybe you could explain how its working so I can better understand what it's doing?

    Is there a way to get it to load into an existing emptyclip? Not make a new one?

    I think this will help me the most.

    Also it places it at x0 y0, so seting it into an existing clip should remedy this.

  12. #12
    Flashmatics silentweed's Avatar
    Join Date
    Mar 2005
    Location
    London, UK
    Posts
    4,875
    Heres an example ive attached ... on stage it has a movieclip called "frame"..the image will always load into this and be centred...

    have a look at the MovieClipLoader class in the flash docs for a better understanding of my code..

    basically after the image is loaded, flash resizes it util it is of the required dimensions...it then centers it within the frame...
    Last edited by silentweed; 02-04-2007 at 01:07 PM.
    Flashmatics | Flashmatics Library (free downloads)
    -----------------------------------------------------
    Latest Projects:
    The Dead Room | Are You Smarter | Prison Break (Frame A Friend) | Beck's Fusions | The 24 Experience

    -----------------------------------------------------
    Flash Certified Developer

  13. #13
    OpticallyDevoted
    Join Date
    Sep 2002
    Location
    RI
    Posts
    134
    Thanks again for your time silentweed.

    I still had some problems. I copied the frames from your fla to my fla but got those errors again. Which is totally weird and confuses me. So it wasn't working. Then I copied all the frames from my working fla and brought them into yours and it worked. No errors, except now, it take three times as long to compile... This confuses me more.. Oh well.. Bottom line, it works now

    Thanks again for your time!

  14. #14
    Flashmatics silentweed's Avatar
    Join Date
    Mar 2005
    Location
    London, UK
    Posts
    4,875
    np yw glad i could help
    Flashmatics | Flashmatics Library (free downloads)
    -----------------------------------------------------
    Latest Projects:
    The Dead Room | Are You Smarter | Prison Break (Frame A Friend) | Beck's Fusions | The 24 Experience

    -----------------------------------------------------
    Flash Certified Developer

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