|
From: Stephan B. <be...@xs...> - 2007-02-05 18:29:30
|
Owen van Dijk wrote: > Hi all, > > What's the recommended 'style' of tweening filters and scrollrects? > Through the AQProperty helper method? > > Hi Owen, I wouldn't recommend AQProperty in this case, since it's only useful for a single numerical parameter. In general I guess you'd like to animate more than one parameter for filters. I have been using the ActionQueue to animate filters, and have written my own custom functions to achieve this. The documentation for the ActionQueue class describes how to do this: http://asapframework.org/api/org_asapframework_util_actionqueue_ActionQueue.html#addAction (see the part of the example that starts with "You can also create a custom function ..."). If you like your code clean and nice, you can put these functions into your own helper classes. This is an example for a blur filter: class com.lostboys.animation.AQFilter { /** * Animate the Flash 8 blur filter properties; no other filters are expected to be applied. * @param inDestObject: object on which filter has to be applied * @param duration: duration in seconds of the animation * @param fromX: start value of the x-value of the filter * @param fromY: start value of the y-value of the filter * @param fromQ: start value of the quality value of the filter * @param toX: end value of the x-value of the filter * @param toY: end value of the y-value of the filter * @param toQ: end value of the quality value of the filter * @param effect: effect function * @param effectParams: array of parameters for effect function * @return data block for the ActionQueue process */ public static function blur (inDestObject:MovieClip, duration:Number, fromX:Number, fromY:Number, fromQ:Number, toX:Number, toY:Number, toQ:Number, effect:Function, effectParams:Array) : ActionQueuePerformData { var performFunction:Function = function (inPerc:Number) : Boolean { var newX:Number = toX - (inPerc * (toX - fromX)); var newY:Number = toY - (inPerc * (toY - fromY)); var newQ:Number = toQ - (inPerc * (toQ - fromQ)); var f:BlurFilter = new BlurFilter(newX, newY, newQ); inDestObject.filters = [f]; return true; }; // Set up the data so ActionQueue will perform the function performFunction: return new ActionQueuePerformData( performFunction, duration, 1, 0, effect, effectParams); } } As you can see, the function "blur" assumes that only a blur filter will be applied. It often depends on specific project requirements whether that's enough (think of stacking of filters), so I think it's a good idea if you look closely into this and other examples, and get some skill in writing your own ActionQueue custom functions. With some proper copy-paste actions you can easily achieve complex effects that apply to a single project, without necessarily making them very reusable. It often yields more elegant, understandable and maintainable code than if you were to use the AQReturnValue or AQProperty functionality. The same applies to scrollRect. With a custom function, you can animate the x- & y-values, and if you wish, the width and height, of a Rectangle object that is then set as the scrollRect property of a MovieClip. Hope this helps! Stephan |