15 posts
  • Has been part of the Envato Community for over 3 years
  • Sells items exclusively on Envato Market
MaximusCript says

I have this small problem. I have mysite, where i have 5 oferts, with 5 huge images, that fits to width and height of browser. Now to do that i use z attribute in as3.

My code looks like this: var hei:int = stage.stageHeight; while(pi1c.width > wid){ pic1.z++; } while(pi1c.height > hei){ pic1.z++; } while(pic1.width < wid){ pic1.z—; } while(pic1.height < hei){ pic1.z—; } while(pi2c.width > wid){ pic2.z++; } while(pi2c.height > hei){ pic2.z++; } while(pic2.width < wid){ pic2.z—; } while(pic2.height < hei){ pic2.z—; }[/code]

wid:int = stage.stageWidth;

This works perfect, but all these pic have diffrent sizes, and it makes a nice pile of code, and lots more work for cpu. All this pictures are displayed at once, and code is run at resize event. Now, does anybody know,s how to calculate how much width/height increase and decrease while playing with z attribute?

Please, any tips.

PS: Also, could someone tell me how i make my code, look like a code i mean how i put it in a border.

1955 posts
  • Has been part of the Envato Community for over 6 years
  • Has referred 10+ members
  • Has sold $5,000+ on Envato Market
  • Has collected 10+ items on Envato Market
+3 more
Emroni says
Not the best way to handle image resizing. Try this instead:
function resizePic(pic){
     pic.width = stage.stageWidth; // Set to stage width
     pic.scaleY = pic.scaleX; // Resizes height and keeps the ratio

     if(pic.height > stage.stageHeight){ // Still larger than stage height?
          pic.height = stage.stageHeight; // Set to stage height
          pic.scaleX = pic.scaleY; // Resizes widthand keeps the ratio
     }
}

resizePic(pi1c);
resizePic(pi2c);

And you can use the < pre > tag to display code

15 posts
  • Has been part of the Envato Community for over 3 years
  • Sells items exclusively on Envato Market
MaximusCript says

I couldn’t get better idea, but your way is is so simple, and so genius.

Thanks alot! Max

Helpful Information

  • Please read our community guidelines. Self promotion and discussion of piracy is not allowed.
  • Open a support ticket if you would like specific help with your account, deposits or purchases.
  • Item Support by authors is optional and may vary. Please see the Support tab on each item page.

Most of all, enjoy your time here. Thank you for being a valued Envato community member.

Post Reply

Format your entry with some basic HTML. Read the Full Details, or here is a refresher:

<strong></strong> to make things bold
<em></em> to emphasize
<ul><li> or <ol><li> to make lists
<h3> or <h4> to make headings
<pre></pre> for code blocks
<code></code> for a few words of code
<a></a> for links
<img> to paste in an image (it'll need to be hosted somewhere else though)
<blockquote></blockquote> to quote somebody

:grin: :shocked: :cry: Complete List of Smiley Codes

by
by
by
by
by
by