I want to scale swf up to 100%, but at any percent down. Any ideas how to do that?
I want to allow the swf to scale when the browser window is resized, but I don't want it to increase over 100% (so it should only scale down).
This is an ex开发者_Go百科ample of the kind of scaling the client wants: http://www.voosfurniture.com/
But again, it should stop at 100% going up.
you can do it but you need to put your content in a container (variable "_container" below) :
package
{
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.geom.Point;
import flash.geom.Rectangle;
public class Test extends Sprite
{
private var _initialeStageBounds : Point = new Point;
private var _container : Sprite = new Sprite;
public function Test()
{
_container.graphics.beginFill(0x556699);
_container.graphics.drawRect(0,0,100,100);
addChild(_container);
_initialeStageBounds.x = stage.stageWidth;
_initialeStageBounds.y = stage.stageHeight;
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
stage.addEventListener(Event.RESIZE, onStageResize);
}
private function onStageResize(e:Event) : void
{
var ratio : Number = Math.min(1,
stage.stageWidth / _initialeStageBounds.x,
stage.stageHeight / _initialeStageBounds.y);
_container.x = (stage.stageWidth - _container.width) / 2;
_container.y = (stage.stageHeight - _container.height) / 2;
_container.scaleX = ratio;
_container.scaleY = ratio;
}
}
}
精彩评论