views:

266

answers:

1

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);
    }

function updateFilter(e:TweenEvent):void
    {
    shader.data.amount.value = [tweenNumber];
    myMovieClip.filters = [shaderFilter];
    }
+3  A: 

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);
//...
Patrick
oh i see. i was writing the tween arguments incorrectly. Tween(this, "tweenNumber", ...) works fine. thanks.
TheDarkInI1978