Tweening Pixel Bender Filter Using Number Value With Basic Tween Class in Actionscript 3.0
i'm studying Pixel Bender. i have a filter who's parameter i want to tween. as far as i know, in order to tween a pixel bender parameter, i need to tween a number object and assign the tweening number object as the array value for the shader data.
i was convinced the following would work, but it seems that Number class doesn't have a value property, so i don't know what property to use when setting up a new tween for the number object:
import fl.transitions.*;
import fl.transitions.easing.*
var shader:Shader;
var shaderFilter:ShaderFilter;
var motionTween:Tween;
var tweenNumber:Number = new Number(0.0);
var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.BINARY;
loader.addEventListener(Event.COMPLETE, dataLoaded);
loader.load(new URLRequest("PBFilter.pbj"));
function dataLoaded(e:Event):void
{
loader.removeEventListener(Event.COMPLETE, dataLoaded);
shader = new Shader(e.target.data);
shaderFilter = new ShaderFilter(shader);
flower.filters = [shaderFilter];
motionTween = new Tween(tweenNumber, "value", Bounce.easeOut, 0.0, 100.0, 5, true);
motionTween.addEventListener(TweenEvent.MOTION_CHANGE, updateFilter);
}
fu开发者_如何学运维nction updateFilter(e:TweenEvent):void
{
shader.data.amount.value = [tweenNumber];
myMovieClip.filters = [shaderFilter];
}
Perhaps you can add a getter and setter for your tweening into your test class :
//...
public function get amount():Number {
return tweenNumber;
}
public function set amount(value:Number):void {
tweenNumber=value;
}
//...
motionTween = new Tween(this, "amount", Bounce.easeOut, 0.0, 100.0, 5, true);
motionTween.addEventListener(TweenEvent.MOTION_CHANGE, updateFilter);
//...
-- or do the update into your setter
//...
public function get amount():Number {
return tweenNumber;
}
public function set amount(value:Number):void {
tweenNumber=value;
shader.data.amount.value = [value];
myMovieClip.filters = [shaderFilter];
}
//...
motionTween = new Tween(this, "amount", Bounce.easeOut, 0.0, 100.0, 5, true);
//...
精彩评论