15 posts
  • Exclusive Author
  • Has been a member for 2-3 years
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
  • Bought between 10 and 49 items
  • Exclusive Author
  • Has been a member for 6-7 years
  • Netherlands
  • Referred between 10 and 49 users
  • Sold between 5 000 and 10 000 dollars
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
  • Exclusive Author
  • Has been a member for 2-3 years
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