3650 posts Community Moderator
  • Has been a member for 5-6 years
  • Contributed a Tutorial to a Tuts+ Site
  • Netherlands
  • Community Moderator
  • Microlancer Beta Tester
  • Sold between 10 000 and 50 000 dollars
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Exclusive Author
+4 more
Joost Volunteer 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
  • Bought between 50 and 99 items
  • Elite Author
  • Exclusive Author
  • Has been a member for 5-6 years
  • Referred between 50 and 99 users
  • Sold between 50 000 and 100 000 dollars
  • United States
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;
}
315 posts
  • Bought between 100 and 499 items
  • Has been a member for 7-8 years
  • 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
  • Bought between 50 and 99 items
  • Elite Author
  • Exclusive Author
  • Has been a member for 5-6 years
  • Referred between 50 and 99 users
  • Sold between 50 000 and 100 000 dollars
  • United States
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.

315 posts
  • Bought between 100 and 499 items
  • Has been a member for 7-8 years
  • United States
timmylogue says

Nice! I understand now. This should work!

Thanks again Tim

by
by
by
by
by
by