Controlling MovieClips (Methods and Properties)
//Controling MovieClips
//Buttons, Event Listeners, Event Handlers and Functions to Control MovieClip Properties and Methods
man_mc.addEventListener(Event.ENTER_FRAME, whatFrame);
function whatFrame(e:Event) {
frame_txt.text = man_mc.currentFrame;
}
//Play and Stop
play_btn.addEventListener(MouseEvent.CLICK, onPlay);
function onPlay(e:MouseEvent) {
man_mc.play();
}
//stop with a dynamic instance name
var targetClip:String = "man_mc";
stop_btn.addEventListener(MouseEvent.CLICK, onStop);
function onStop(e:MouseEvent) {
this[targetClip].stop();
}
//Next and Previous
next_btn.addEventListener(MouseEvent.CLICK, onNext);
function onNext(e:MouseEvent) {
man_mc.nextFrame();
}
prev_btn.addEventListener(MouseEvent.CLICK, onPrev);
function onPrev(e:MouseEvent) {
man_mc.prevFrame();
}
//Playing from or stopping on particular frames (gotoAndPlay/gotoAndStop)
framestop_btn.addEventListener(MouseEvent.CLICK, onStopOn1);
function onStopOn1(e:MouseEvent) {
man_mc.gotoAndStop(1);
}
frameplay_btn.addEventListener(MouseEvent.CLICK, onPlayOn20);
function onPlayOn20(e:MouseEvent) {
man_mc.gotoAndPlay(20);
}
//Fast Forward or Last Frame using currentFrame and totalFrames
frameforward_btn.addEventListener(MouseEvent.CLICK, onFF);
function onFF(e:MouseEvent) {
man_mc.gotoAndPlay(man_mc.currentFrame + 5);
}
framelast_btn.addEventListener(MouseEvent.CLICK, onLast);
function onLast(e:MouseEvent) {
man_mc.gotoAndStop(man_mc.totalFrames);
}
//Visibility
visible_btn.addEventListener(MouseEvent.CLICK, onVis);
function onVis(e:MouseEvent) {
man_mc.visible = true;
}
invisible_btn.addEventListener(MouseEvent.CLICK, onInvis);
function onInvis(e:MouseEvent) {
man_mc.visible = false;
}
//Alpha (setting absolute values)
alpha50_btn.addEventListener(MouseEvent.CLICK, onAlpha50);
function onAlpha50(e:MouseEvent) {
man_mc.alpha = .5;
}
alpha100_btn.addEventListener(MouseEvent.CLICK, onAlpha100);
function onAlpha100(e:MouseEvent) {
man_mc.alpha = 1;
}
//Alpha (setting relative values)
alphaUp_btn.addEventListener(MouseEvent.CLICK, alphaUp);
function alphaUp(e:MouseEvent) {
man_mc.alpha += .1;
}
alphaDown_btn.addEventListener(MouseEvent.CLICK, alphaDown);
function alphaDown(e:MouseEvent) {
man_mc.alpha -= .1;
}
//Rotation (by 45 degrees)
rotateUp_btn.addEventListener(MouseEvent.CLICK, rotateUp);
function rotateUp(e:MouseEvent) {
man_mc.rotation += 45;
}
rotateDown_btn.addEventListener(MouseEvent.CLICK, rotateDown);
function rotateDown(e:MouseEvent) {
man_mc.rotation -= 45;
}
//X Scale (by 10 percent)
scaleXUp_btn.addEventListener(MouseEvent.CLICK, scaleXUp);
function scaleXUp(e:MouseEvent) {
man_mc.scaleX += .1;
}
scaleXDown_btn.addEventListener(MouseEvent.CLICK, scaleXDown);
function scaleXDown(e:MouseEvent) {
man_mc.scaleX -= .1;
}
//Y Scale (by 10 percent)
scaleYUp_btn.addEventListener(MouseEvent.CLICK, scaleYUp);
function scaleYUp(e:MouseEvent) {
man_mc.scaleY += .1;
}
scaleYDown_btn.addEventListener(MouseEvent.CLICK, scaleYDown);
function scaleYDown(e:MouseEvent) {
man_mc.scaleY -= .1;
}
//Height (by 10 pixels)
heightUp_btn.addEventListener(MouseEvent.CLICK, heightUp);
function heightUp(e:MouseEvent) {
man_mc.height += 10;
}
heightDown_btn.addEventListener(MouseEvent.CLICK, heightDown);
function heightDown(e:MouseEvent) {
man_mc.height -= 10;
}
//Width (by 10 pixels)
widthUp_btn.addEventListener(MouseEvent.CLICK, widthUp);
function widthUp(e:MouseEvent) {
man_mc.width += 10;
}
widthDown_btn.addEventListener(MouseEvent.CLICK, widthDown);
function widthDown(e:MouseEvent) {
man_mc.width -= 10;
}
//X position (horizontal position)
xUp_btn.addEventListener(MouseEvent.CLICK, onXUp);
function onXUp(e:MouseEvent) {
//man_mc.x = man_mc.x + 10;
man_mc.x += 10;
}
xDown_btn.addEventListener(MouseEvent.CLICK, onXDown);
function onXDown(e:MouseEvent) {
//man_mc.x = man_mc.x + 10;
man_mc.x -= 10;
}
//Y position (vertical position)
yUp_btn.addEventListener(MouseEvent.CLICK, onYUp);
function onYUp(e:MouseEvent) {
//man_mc.x = man_mc.x + 10;
man_mc.y += 10;
}
yDown_btn.addEventListener(MouseEvent.CLICK, onYDown);
function onYDown(e:MouseEvent) {
//man_mc.x = man_mc.x + 10;
man_mc.y -= 10;
}
//Blur Filter
blur_btn.addEventListener(MouseEvent.CLICK, onBlur);
function onBlur(e:MouseEvent) {
var blurX:Number = 25;
var blurY:Number = 25;
var filter:BlurFilter = new BlurFilter(blurX, blurY, BitmapFilterQuality.HIGH);
man_mc.filters = [filter];
}
//Drop Shadow Filter
shadow_btn.addEventListener(MouseEvent.CLICK, onShadow);
function onShadow(e:MouseEvent) {
var filter:DropShadowFilter = new DropShadowFilter();
man_mc.filters = [filter];
}
//Blend Mode
blend_btn.addEventListener(MouseEvent.CLICK, onBlender);
function onBlender(e:MouseEvent) {
man_mc.blendMode = "overlay";
}
//Color Transform
color_btn.addEventListener(MouseEvent.CLICK, onColor);
function onColor(e:MouseEvent):void {
//create a color transform by setting a hexadecimal color value
var myColor:ColorTransform = new ColorTransform();
myColor.color = 0xFF0000;
man_mc.transform.colorTransform = myColor;
//or use color multipliers and offets like below
//man_mc.transform.colorTransform = new ColorTransform(0,0,0,1,255,0,0,0);
}
//Reset all methods, properties, and effects
reset_btn.addEventListener(MouseEvent.CLICK, reset);
function reset(e:MouseEvent) {
man_mc.gotoAndPlay(1);
man_mc.visible = true;
man_mc.alpha = 1;
man_mc.rotation = 0;
man_mc.scaleX = 1;
man_mc.scaleY = 1;
man_mc.height = 190.8;
man_mc.width = 84.5;
man_mc.x = 400;
man_mc.y = 120;
man_mc.filters = [];
man_mc.blendMode = "normal";
man_mc.transform.colorTransform = new ColorTransform(1, 1, 1, 1, 0, 0, 0, 0);
}