How to get scene sizes using StageScaleMode.SHOW_ALL?

If you set stage.scaleMode to StageScaleMode.SHOW_ALL, your swf can be increased or decreased and can be supplemented by top / bottom or left / right. However, stage.width + height always returns the width and height as defined by your swf, and stage.scaleX + Y always returns 1. As I understand it, resizing is not thrown. So, how do I get the real scale and size?

I want them to be for two problems:

  • I want to fill this registration form up / down or left / right with something only if the user can see it.

  • I draw vectors into bitmaps and want to scale it correctly so that it doesn't look jagged (or fuzzy with bitmap.smoothing). Flash seems to do the scaling correctly when cacheEBitmap = true, so how can I recreate it?

+4
source share
2 answers

In your case, it will probably be easier to use StageScaleMode.NO_SCALE and program the resizing yourself:

stage.addEventListener(Event.RESIZE, onStageResize); private function onStageResize(event : Event) : void { var stageW : int = stage.stageWidth; var stageH : int = stage.stageHeight; var contentW : int = yourVisibleContent.width; var contentH : int = yourVisibleContent.height; // resize it to fit var canvasAspectRatio : Number = stageW / stageH; var contentAspectRatio : Number = contentW / contentH; if(canvasAspectRatio > contentAspectRatio) { yourVisibleContent.height = stageH; yourVisibleContent.width = yourVisibleContent.height * contentAspectRatio; } else { yourVisibleContent.width = stageW; yourVisibleContent.height = yourVisibleContent.width / contentAspectRatio; } // center it: yourVisibleContent.x = (stageW - yourVisibleContent.width) / 2; yourVisibleContent.y = (stageH - yourVisibleContent.height) / 2; // fill remaining space with black: graphics.beginFill(0x000000); if(canvasAspectRatio > contentAspectRatio) { var horizontalEmptySpace : Number = stageW - yourVisibleContent.width; graphics.drawRect(0, 0, horizontalEmptySpace / 2, stageH); graphics.drawRect(stageW - horizontalEmptySpace / 2, 0, horizontalEmptySpace / 2, stageH); }else{ var verticalEmptySpace : Number = stageH - yourVisibleContent.height; graphics.drawRect(0, 0, stageW, verticalEmptySpace / 2); graphics.drawRect(0, stageH - verticalEmptySpace / 2, stageW, verticalEmptySpace / 2); } // now you can also redraw your bitmaps with higher resolutions // it is easy to read the scale of your content with: yourVisibleContent.scaleX and yourVisibleContent.scaleY } 
+3
source

This is the code I used to retrieve measurements during swf loading and use them to scale bitmaps later, based on bjornson's answer above.

 var actualScale :Number; var actualStageWidth :Number; var actualStageHeight :Number; private function collectDimensions () :void { stage.scaleMode = StageScaleMode.NO_SCALE; actualStageWidth = stage.stageWidth; actualStageHeight = stage.stageHeight; var contentWidth :Number = yourVisibleContent.width; var contentHeight :Number = yourVisibleContent.height; var canvasAspectRatio :Number = actualStageWidth / actualStageHeight; var contentAspectRatio :Number = contentWidth / contentHeight; if (canvasAspectRatio > contentAspectRatio) { actualScale = actualStageHeight / contentHeight; } else { actualScale = actualStageWidth / contentWidth; } stage.scaleMode = StageScaleMode.SHOW_ALL; } public function createBitmap (clip :MovieClip) :Bitmap { var bitmapData :BitmapData = new BitmapData(clip.width, clip.height); var matrix :Matrix = new Matrix(); matrix.scale(actualScale, actualScale); bitmapData.draw(clip, matrix); var bitmap :Bitmap = new Bitmap(bitmapData); bitmap.scaleX = bitmap.scaleY = 1/actualScale; bitmap.smoothing = true; return bitmap; } 
+1
source

Source: https://habr.com/ru/post/1345631/


All Articles