02/08/2011

Dealing with Browser Zoom in Flash

One problem Flash ads can have is when the user zooms in using the Zoom of their browser. This can cause scaling problems with your Flash ad.

A solution for this is to add a event listener to the Resize event, this listener then tells your ads to rescale based on the size of the stage. Here's an example:

First make sure that scaleMode is not set:

   1:  //stage.scaleMode = StageScaleMode.NO_SCALE;



Here the scaleMode is commented out, then add the event listener to the stage:


   1:  stage.addEventListener(Event.RESIZE, onStageResize);



Then in the event set the stageWidth divided by the width of the ad being created. Then set this to scaleX and scaleY properties.

 

   1:  protected function onStageResize(event:Event):void
   2:   
   3:  {
   4:   
   5:  var widthScale:Number = stage.stageWidth / 728; 
   6:   
   7:  scaleX = scaleY = widthScale;
   8:   
   9:  }



I used this for some of the ads I’ve been creating at work, it does need testing on all browsers, but it might be one possible solution.

No comments: