-
Notifications
You must be signed in to change notification settings - Fork 1
/
Previewer.as
35 lines (26 loc) · 840 Bytes
/
Previewer.as
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package {
import flash.display.DisplayObject;
import flash.display.MovieClip;
import flash.geom.Rectangle;
public class Previewer extends MovieClip {
private var _child:DisplayObject;
public function preview(dsp:DisplayObject):void {
clear();
_child = dsp;
var scale:Number = 1;
if (_child.width > 185) scale = 185 / _child.width;
if (_child.height * scale > 185) scale = 185 / _child.height;
if (scale != 1) {
_child.scaleX = _child.scaleY = scale;
}
var bounds:Rectangle = _child.getBounds(_child);
_child.x = -bounds.x * scale + (185 - _child.width) / 2;
_child.y = -bounds.y * scale + (185 - _child.height) / 2;
addChild(_child);
}
public function clear():void {
if (_child != null && contains(_child)) removeChild(_child);
_child = null;
}
}
}