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

by
by
by
by
by
by