How to Get Around Stage Resizing Lag in Flex

Posted by | Posted in Actionscript 3.0, Flex | Posted on 19-03-2009

I've always hated how Flex lags when the browser is resized and how the background shows. I recently came across some code that showed me how to not do this. It appears that it's for the sake of efficiency and that the resizing actually happens "late" so as to save resources. To get around this all you need to do is call validateNow(), like this:

addEventListener(Event.RESIZE, onStageResize);
function onStageResize(e:Event = null):void
{
	this.validateNow();
}

I added the null default value so you that you don't have to have an event to call this function. Enjoy. (original post)

Motion Blurs for Tweening engines

Posted by | Posted in Actionscript 3.0, Flash, Flex, Resources | Posted on 17-03-2009

I've been using TweenMax for a while but I always want to add motion blurs to everything.  I've seen a few approaches where you would detect if the movie is moving and just apply a generic blur, but I didn't like those.  Here is a little utility class that comes in handy.  It will apply horizontal and vertical blurs perfectly but since there are no real directional blurs in Flash, I've cancelled the diagonal blurring since it will only blur out the ball completely.  To add that just surround the statements on lines 23-24 with a Math.abs. This class makes it really easy to add motion blurs to tween with code that looks like

TweenMax.to(mc, 0.4, {x: 1000, onUpdate: BlurHelper.blur, onUpdateParams: [mc]});

With the BlurHelper class below

package
{
	import flash.filters.BlurFilter;
 
	public class BlurHelper {
 
		private static var _items:Array = new Array();
		private static var modx:Number = 0.5;
		private static var mody:Number = 0.5;
 
		public static function blur(aItem:*):void
		{
 
			var bl:BlurFilter = new BlurFilter();
 
			if(_items[aItem.name] == null)
			{
				_items[aItem.name] = new Object();
				_items[aItem.name].ox 	= 0;
				_items[aItem.name].oy 	= 0;
			}
 
			bl.blurX = (aItem.x - _items[aItem.name].ox)/modx;
			bl.blurY = (aItem.y - _items[aItem.name].oy)/mody;
 
			_items[aItem.name].ox = aItem.x;
			_items[aItem.name].oy = aItem.y;
 
			aItem.filters = [bl];
 
		}
 
		public static function killBlur(aItem:*):void
		{
			aItem.filters = new Array();
		}
	}
}

Getting Started with Away3D

Posted by | Posted in Actionscript 3.0 | Posted on 09-03-2009

I have been playing around with Papervision3D for some time and have also lately started playing with Away3D during my free time and at work.  I decided to do a little survey of the most popular, open source engines out there, namely Papervision, Away3D and Sandy.  So as a first installment and since there are so many Papervision3D tutorials out there, I decided to make the first one about Away3D.  This is more of a code snippet than anything, but that usually is enough to explain what's going on.   The following code is a document class that initializes Away3D and creates a plane out of a movie clip with the instance name "test" that is on the stage. Read the rest of this entry »