If you are new to using Pixel Bender shaders in Spark, you may run into the same issue I did. That is, when you try to use a .pbj filter as the AnimateTransitionShader‘s shaderByteCode, the Pixel Bender filter must have two image ‘inputs’.
Here is an example of Pixel Bender code declaring two inputs and one output:
input image4 frontImage;
input image4 backImage;
output pixel4 dst;
If there is only one input, then AnimateTransitionShaderInstance will throw a TypeError #1010:
TypeError: Error #1010: A term is undefined and has no properties. at spark.effects.supportClasses::AnimateTransitionShaderInstance/play()
[E:\dev\hero_private\frameworks\projects\spark\src\spark\effects\supportClasses\AnimateTransitionShaderInstance.as:298] at spark.effects.supportClasses::AnimateInstance/startEffect()
[E:\dev\hero_private\frameworks\projects\spark\src\spark\effects\supportClasses\AnimateInstance.as:433] at mx.effects.effectClasses::SequenceInstance/playCurrentChildSet()
[E:\dev\hero_private\frameworks\projects\framework\src\mx\effects\effectClasses\SequenceInstance.as:631] at mx.effects.effectClasses::SequenceInstance/playNextChildSet()
[E:\dev\hero_private\frameworks\projects\framework\src\mx\effects\effectClasses\SequenceInstance.as:657] at mx.effects.effectClasses::SequenceInstance/onEffectEnd()
[E:\dev\hero_private\frameworks\projects\framework\src\mx\effects\effectClasses\SequenceInstance.as:603] at mx.effects.effectClasses::CompositeEffectInstance/http://www.adobe.com/2006/flex/mx/internal::effectEndHandler()
[E:\dev\hero_private\frameworks\projects\framework\src\mx\effects\effectClasses\CompositeEffectInstance.as:457] at flash.events::EventDispatcher/dispatchEventFunction() at flash.events::EventDispatcher/dispatchEvent() at mx.effects::EffectInstance/finishEffect()
[E:\dev\hero_private\frameworks\projects\framework\src\mx\effects\EffectInstance.as:806] at spark.effects.supportClasses::AnimateInstance/finishEffect()[E:\dev\hero_private\frameworks\projects\spark\src\spark\effects\supportClasses\AnimateInstance.as:873] at spark.effects.supportClasses::FadeInstance/finishEffect()
[E:\dev\hero_private\frameworks\projects\spark\src\spark\effects\supportClasses\FadeInstance.as:269] at spark.effects.supportClasses::AnimateInstance/animationEnd()[E:\dev\hero_private\frameworks\projects\spark\src\spark\effects\supportClasses\AnimateInstance.as:812] at spark.effects.animation::Animation/sendAnimationEvent()
[E:\dev\hero_private\frameworks\projects\spark\src\spark\effects\animation\Animation.as:861] at spark.effects.animation::Animation/end()
[E:\dev\hero_private\frameworks\projects\spark\src\spark\effects\animation\Animation.as:980] at spark.effects.animation::Animation/doInterval()[E:\dev\hero_private\frameworks\projects\spark\src\spark\effects\animation\Animation.as:808] at spark.effects.animation::Animation$/timerHandler()
[E:\dev\hero_private\frameworks\projects\spark\src\spark\effects\animation\Animation.as:702] at flash.utils::Timer/_timerDispatch() at flash.utils::Timer/tick()
Not all Pixel Bender filters are designed to operate with two source images. The simplest solution for implementing single input Pixel Bender filters in Spark is to use ShaderFilter instead of AnimateTransitionShader. The difference being ShaderFilter does not capture before and after bitmaps, instead the ShaderFilter is applied directly to one bitmap.
Here is an example of a Group with a ShaderFilter applied to it:
<s:Group>
<s:filters>
<s:ShaderFilter id="myShader" shader="@Embed(source='myFilter.pbj')"/>
</s:filters>
</s:Group>
That filter can be easily animated with AnimateFilter. In the following example, the AnimateFilter class interpolates the “size” paramater of the ShaderFilter in the above example.
<s:AnimateFilter bitmapFilter="{myShader}" duration="500">
<s:SimpleMotionPath valueFrom="0" valueTo="100" property="size"/>
</s:AnimateFilter>