3769 posts Community Moderator
  • Helps us moderate the forums
  • Contributed a tutorial on Tuts+
  • Located in Netherlands
  • Made it to the Authors' Hall of Fame
+9 more
Joost Moderator says


Why would you want to fit outside of the stage? :o
So that images with different proportion/size than stage can fill the screen anyway.

Point taken :P

1234 posts
  • Has been part of the Envato Community for over 6 years
  • Has referred 50+ members
  • Has sold $75,000+ on Envato Market and is now an Elite Author
  • Has collected 50+ items on Envato Market
+5 more
MBMedia says

Just a generic script, but it should show you the math you need:

stage.scaleMode = 'noScale';
stage.align = "TL";

stage.addEventListener(Event.RESIZE, stageResize);
stageResize(null);

function stageResize(e:Event) : void
{
    var sW: Number = stage.stageWidth;
    var sH: Number = stage.stageHeight;
    var objW: Number = obj.width / obj.scaleX;
    var objH: Number = obj.height / obj.scaleY;

    var ratioW: Number = sW / objW;
    var ratioH: Number = sH / objH;

    obj.scaleX = obj.scaleY = ratioH < ratioW ? ratioW : ratioH; // to scale to fill
    // obj.scaleX = obj.scaleY = ratioH > ratioW ? ratioW : ratioH; // to scale to fit

    // if you want to center it
    obj.x = -(obj.width  - sW) / 2;
    obj.y = -(obj.height - sH) / 2;
}
321 posts
  • Has been part of the Envato Community for over 7 years
  • Has collected 100+ items on Envato Market
  • Located in United States
timmylogue says

Thanks for the replies everyone… Sorry I was on vacation for a few days just got back a few hours ago.

I should of mention that its for AS2 . I’m sorry guys, kinda thought maybe the code would of shown that… sorry again.

Please if anyone can help me with this I don’t see why this is so hard to accomplish. I’m going alittle :dead: over here.

Again what I’m trying to do is just resize the image being loaded from an .XML file.

I cant use:

picture_mc._width = 1280;
picture_mc._height = 720;
because if I do it just flips and doesn’t even load anything.

Here is my NEW AS2 code: http://www.pastie.org/2035553

Thanks :D
Timothy

1234 posts
  • Has been part of the Envato Community for over 6 years
  • Has referred 50+ members
  • Has sold $75,000+ on Envato Market and is now an Elite Author
  • Has collected 50+ items on Envato Market
+5 more
MBMedia says

It’s not hard to accomplish, I gave you the math that does it. Math is the same in AS2 and AS3 , just the property names you’re reading and setting are just slightly different.

You have to do the math at a point in your program where you have the image loaded and can read/set it’s dimensions, and can read the stage dimensions to know what size to make it. Where that is in your program is for you to know, we’re not going to implement it for you, but at that point this is the math:

var sW: Number = stage.stageWidth;
var sH: Number = stage.stageHeight;
var objW: Number = obj.width / obj.scaleX;
var objH: Number = obj.height / obj.scaleY;

var ratioW: Number = sW / objW;
var ratioH: Number = sH / objH;

obj.scaleX = obj.scaleY = ratioH < ratioW ? ratioW : ratioH; // to scale to fill
// obj.scaleX = obj.scaleY = ratioH > ratioW ? ratioW : ratioH; // to scale to fit

// if you want to center it
obj.x = -(obj.width  - sW) / 2;
obj.y = -(obj.height - sH) / 2;

just switch out “obj” to be whatever the name of for your bitmap is, and then read/write the AS2 values (such as _x, _y, _width, _height instead of x, y, width, height) instead of the AS3 ones.

321 posts
  • Has been part of the Envato Community for over 7 years
  • Has collected 100+ items on Envato Market
  • Located in United States
timmylogue says

Nice! I understand now. This should work!

Thanks again Tim

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