A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: AS3 resize image

  1. #1
    Junior Member
    Join Date
    Mar 2011
    Posts
    15

    AS3 resize image

    Hi,
    hoping someone can help me with my code

    I want my background image to resize so that when a browser window is resized, the image scales with the width of the browser window (centre of the stage)

    here is my code so far that does the job:

    stage.scaleMode=StageScaleMode.NO_SCALE;
    stage.align=StageAlign.TOP_LEFT;
    stage.addEventListener(Event.RESIZE, onStageResize);
    addEventListener(Event.ENTER_FRAME, onFrame);

    function onStageResize(evt:Event):void {
    backgroundimg.scaleX=stage.stageWidth/1280;
    backgroundimg.y=stage.stageHeight/2-backgroundimg.height/2;
    backgroundimg.scaleY = backgroundimg.scaleX;

    }


    This is where I am stuck:

    The minimum I want the image to scale to 900px... how do I set it so that the image doesn't resize further than 900px wide?

    hope this makes sense! many thanks

  2. #2
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    Add an if statement:
    if (backgroundimg.width < 900 && backgroundimg.height < 900)
    {
    backgroundimg.scaleX=stage.stageWidth/1280;
    backgroundimg.y=stage.stageHeight/2-backgroundimg.height/2;
    backgroundimg.scaleY = backgroundimg.scaleX;
    }
    - The right of the People to create Flash movies shall not be infringed. -

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center