2010.02.16

AS3 Flip Horizontal/Vertical

By underblob @ 11:21am — Categories: Flash, Tech
import flash.geom.Matrix;

public function flipHorizontal ( dsp:DisplayObject ):void {
	var matrix:Matrix = dsp.transform.matrix;
	matrix.a = -1;
	matrix.tx = dsp.width + dsp.x;
	dsp.transform.matrix = matrix;
}

public function flipVertical ( dsp:DisplayObject ):void {
	var matrix:Matrix = dsp.transform.matrix;
	matrix.d = -1;
	matrix.ty = dsp.height + dsp.y;
	dsp.transform.matrix = matrix;
}

Links

dreaminginflash.com

2010.01.22

AS3 Listeners — Loader.COMPLETE vs MovieClip.ENTER_FRAME

By underblob @ 6:31pm — Categories: Flash, Tech
Tags: , , , , ,

Trying to load a directory of hundreds of images into separate movie clips using the AS3 Loader class. By assigning an Event.COMPLETE listener to the Loader, the callback function only has a reference to the Loader and not to the image that’s being loaded or the parent that it’s being loaded into. So if I need to Tween on this image after the load is completed, no dice. Instead, assign an Event.ENTER_FRAME to the parent MovieClip and dig a byte comparison out of the contentLoaderInfo object…

 

for each ( var imgPath in imgXML.elements () ) {
	var imgLoader:Loader = new Loader ();
	imgClip.addChild ( imgLoader );
	imgClip.addEventListener ( Event.ENTER_FRAME, imgLoading );
	imgLoader.load ( new URLRequest ( imgPath ) );
}

function imgLoading ( e:Event ):void {
	var bL:Number = e.target.getChildAt ( 0 ).contentLoaderInfo.bytesLoaded;
	var bT:Number = e.target.getChildAt ( 0 ).contentLoaderInfo.bytesTotal;
	if ( bT == bL ) {
		e.target.removeEventListener ( Event.ENTER_FRAME, imgLoading );
		e.target.parent.Tweener // etc.
	}
}


2010.01.04

TweenLite Calls

By underblob @ 7:54pm — Categories: Flash, Tech
Tags: , , ,

Formatting for the GreenSock TweenLite animation AS3 Class:

TweenLite.to ( mc:MovieClip, duration:Number,
	{
		alpha:0,
		x:120,
		ease:Quint.easeInOut,
		delay:2,
		onComplete:callbackFunction,
		onCompleteParams:[ 5, mc ]
	}
 );

 

Links

GreenSock

2009.11.17

AS3 Naming and Retrieving Elements Dynamically

By underblob @ 3:51pm — Categories: Flash
Tags: , ,

Recently ran across this problem in Actionscript 3 with dynamically naming and retrieving child elements. Created a loop to name sprites and add using the name property and addChild method:

for ( var i:int = 1;  i <= 3;  i++ ) {
	var bkgd:Sprite = new Sprite ();
	bkgd.name = "bkgd" +i;
	addChild ( bkgd );
}

 

Now these sprites are accessible via getChildByName and are retrieved as DisplayObject by default. But when retrieved as DisplayObject, you can not add children via addChild method. The trick is to cast the DisplayObject as a Sprite:

var addBkgd:Sprite = Sprite ( this.getChildByName( "bkgd" +layerNum ) );
addBkgd.addChild ( layerSprite );

 

hexbkgd

2009.07.06

AS2 Disable Underlying Buttons

By underblob @ 10:47am — Categories: Flash, Tech

Create a new movie clip to block the content underneath and apply the following ActionScript:

mc_target.onRollOver = function () {};
mc_target.useHandCursor = false;

Register the empty function so Flash will treat the movie clip like a giant button so that none of the underlying buttons will be active. Add the useHandCursor property to keep the pointer hand from showing up.

2009.03.12

Callback Format for FuseKit

By underblob @ 12:43pm — Categories: Flash, Tech
clip.slideTo ( x_value, y_value, duration, easing, delay, callback );

Where callback is structure as follows:

clip.slideTo ( [...], { scope:this, func:”function_name”, args:argvalue } );

To send multiple args values, send as an array