MovieClipUtils
| Kind of class: | class |
|---|---|
| Inherits from: | none |
| Author: | Arthur Clemens |
| Classpath: | org.asapframework.util.MovieClipUtils |
| File last modified: | Saturday, 07 October 2006, 23:53:43 |
MovieClip utility functions.
Summary
Class methods
Class methods
centerOnStage
static function centerOnStage (
inMC:MovieClip,
inOffset:Point,
inShouldCenter:Boolean) : Void
Sets a movieclip to the center of the stage.
Parameters:
inMC :
movieclip or button to set
inOffset:
(optional) movieclip offset as Point
Example:
This example centers the movieclip on the stage, with an offset of (50, 0):
MovieClipUtils.centerOnStage( my_mc, new Point(50,0) );
drawBox
static function drawBox (
inMC:MovieClip,
inLeft:Number,
inTop:Number,
inRight:Number,
inBottom:Number,
inLineProperties:Array,
inFillProperties:Array) : Void
Draws a box in a movieclip.
Parameters:
inMC :
the movieclip to draw the box into
inLeft :
the left coordinate of the box in pixels
inTop :
the top coordinate of the box in pixels
inRight :
the right coordinate of the box in pixels
inBottom :
the bottom coordinate of the box in pixels
inLineProperties:
an array of line properties: line width, line rgb color and line alpha, for example:
[0, 0xff0000,100] (see MovieClip.lineStyle)inFillProperties:
an array of fill properties: fill rgb color and fill alpha, for example:
[0x8888ff, 5]Example:
The following code draws a box of 80 pixels wide, centered, with a red hairline and a half-transparent yellow fill:
MovieClipUtils.drawBox(my_mc, -40, -40, 40, 40, [0, 0xff0000, 100], [0xffff00, 50]);To draw a box without border, pass an empty line properties array:
MovieClipUtils.drawBox(my_mc, -40, -40, 40, 40, [], [0xffff00, 50]);
getNormalizedScale
static function getNormalizedScale (
inMC:MovieClip,
inMaxSize:Point) : Number
Calculates the scale factor of a movieclip to let it fit within given boundaries: when this scale factor is applied, the MovieClip is no wider than inMaxSize.x and no higher than inMaxSize.y.
Parameters:
inMC :
the movieclip to be scaled
inMaxSize:
the maximum width and heigth of the movieclip defined as a Point object; to force height (the scale factor is related to height only), pass a Point with null as x value; to force width (the scale factor is related to width only), pass a Point with null as y value
Returns:
The factor to apply to the scale of a movieclip to let it fit within the specified boundaries. This factor uses MovieClip scaling values (meaning 100 is the unscaled default value).
Implementation note:
The calculated factor is independent of already applied MovieClip scaling.
Example:
For a picture gallery with picture frames of 150 wide and 100 high, to scale MovieClip mc to fit withing these boundaries, use:
Another example: image a Loader that loads images of unknown dimensions, while these images should fit within given picture boundaries. On the Loader's listener method ON_DONE you would call
In the image class:
var frameSize:Point = new Point(150,100); var normalScale:Number = MovieClipUtils.getNormalizedScale(mc, frameSize); mc._xscale = mc._yscale = normalScale;
Another example: image a Loader that loads images of unknown dimensions, while these images should fit within given picture boundaries. On the Loader's listener method ON_DONE you would call
getNormalizedScale to fit the image in.In the image class:
public function loadImage (inName:String, inUrl:String) : Void { loader.addEventListener(LoaderEvent.ON_DONE, this); loader.load( image_mc, inUrl, inName, true ); // sets the loaded image initially to visible:false } private function onLoadDone (e:LoaderEvent) : Void { var image:MovieClip = MovieClip(e.targetClip) var normalScale:Number = MovieClipUtils.getNormalizedScale(image, mSize); image._xscale = image._yscale = normalScale; // now show the movieclip image._visible = true; }
setActive
static function setActive (
inMC:MovieClip,
inFlag:Boolean) : Void
Inactivates the contents of a movieclip (including buttons and button clips), or activates it back again.
Parameters:
inMC :
movieclip or button whose contents should be set enabled or disabled
inFlag:
false (make inactive) or true (make active)
Example:
You can disable all menu buttons in a menu, by calling
To activate the menu items again, call
setActive(menu_mc, false).To activate the menu items again, call
setActive(menu_mc, true).Implementation note:
The movieclip is given an empty event handler (onRelease) with useHandCursor set to false.