SHOW:
|
|
- or go back to the newest paste.
| 1 | - | //TODO: missbehaves on rectangular images? |
| 1 | + | //Finally came around to rewrite this: http://pastebin.com/tvnz57eQ |
| 2 | - | //http://wordpress.org/support/topic/square-images-cropped-in-fullscreen?replies=7#post-2227942 |
| 2 | + | //fixing _FIT of near-rectangular pictures & _FILL-behaviour (filling on both axis) |
| 3 | function fitToScreen(mc:MovieClip) {
| |
| 4 | - | var maxHeight:Number = Stage.height-25; |
| 4 | + | mc._yscale = mc._xscale = 100; |
| 5 | - | ZigoEngine.doTween (mc,"_x",0,0,"linear",0,function () {
|
| 5 | + | var maxHeight:Number = Stage.height-25; |
| 6 | - | if(mc._height <= maxHeight && mc._width <= Stage.width){
|
| 6 | + | if(_scalingStrategy == _FIT){
|
| 7 | - | mc._yscale = mc._xscale = 100; |
| 7 | + | var getWidthRatio:Number = mc._width / mc._height; |
| 8 | var getHeightRatio:Number = mc._height / mc._width; | |
| 9 | - | if(_scalingStrategy != _NOSCALE){
|
| 9 | + | if(Stage.width > maxHeight){
|
| 10 | - | if(mc._height < mc._width) {
|
| 10 | + | |
| 11 | - | mc._width = Stage.width; |
| 11 | + | mc._width = Math.round(maxHeight*getWidthRatio); |
| 12 | - | mc._yscale = mc._xscale; |
| 12 | + | }else{
|
| 13 | - | if(_scalingStrategy == _FILL){
|
| 13 | + | mc._width = Stage.width; |
| 14 | - | if (mc._height < maxHeight) {
|
| 14 | + | mc._height = Math.round(Stage.width*getHeightRatio); |
| 15 | - | mc._height = maxHeight; |
| 15 | + | |
| 16 | - | mc._xscale = mc._yscale; |
| 16 | + | }else if(_scalingStrategy == _FILL){
|
| 17 | - | } |
| 17 | + | mc._width = Stage.width; |
| 18 | - | } |
| 18 | + | mc._yscale = mc._xscale; |
| 19 | - | }else {
|
| 19 | + | if(mc._height < maxHeight){
|
| 20 | mc._height = maxHeight; | |
| 21 | - | mc._xscale = mc._yscale; |
| 21 | + | mc._xscale = mc._yscale; |
| 22 | } | |
| 23 | } | |
| 24 | - | mc._x = Stage.width/2 - mc._width/2; |
| 24 | + | mc._x = Stage.width*0.5 - mc._width*0.5; |
| 25 | - | mc._y = maxHeight/2 - mc._height/2; |
| 25 | + | mc._y = maxHeight*0.5 - mc._height*0.5; |
| 26 | - | }); |
| 26 | + |