topical media & game development
shader-image.mx
shader-image.mx
(swf
)
[ flash
]
flex
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:ae="*"
layout="absolute"
backgroundColor="#000000"
applicationComplete="complete()">
<mx:Script>
<![CDATA[
import flash.filters.*;
import flash.utils.ByteArray;
import flash.utils.getTimer;
//[SWF(width="512",height="512",frameRate="60",backgroundColor="#000000")]
//the file that contains the binary bytes of the PixelBender filter
[Embed("shader-crystal.pbj", mimeType="application/octet-stream")]
private var CustomFilter:Class;
camera -- as usual
import flash.media.Camera;
private var camera:Camera;
private function attach() : void {
stack.selectedIndex = state; // activate before attach
camera = Camera.getCamera();
ca.attachCamera(camera);
//stack.selectedIndex = state; // delay until ready
}
next / display(s)
private var state:Number = 0;
private var max:Number = 3;
private function next():void {
state+=1;
if (state >= max) state = 0;
if (state == 2) attach();
if (state != 2) stack.selectedIndex = state;
}
loop / effect(s)
private function loop(e : Event) : void {
shader.data.size.value = [ 10 + Math.random()*20 ];
stack.filters = [filter];
}
private var shader:Shader;
private var filter:ShaderFilter;
on completion
private function complete():void
{
//Pass the loaded filter to the Shader as a ByteArray
shader = new Shader(new CustomFilter() as ByteArray);
shader.data.size.value = [20.0];
filter = new ShaderFilter(shader);
//add the filter to the image
stack.filters = [filter];
stage.addEventListener(Event.ENTER_FRAME, loop);
}
]]>
</mx:Script>
component(s)
<ae:component_screen id="display"/>
<mx:ViewStack id="stack" width="100%" height="100%">
<mx:Canvas>
<mx:Image id="im" click="next();" right="0" left="0" top="0" bottom="0" maintainAspectRatio="false" source="@Embed(source='soutine.jpg')"/>
</mx:Canvas>
<mx:Canvas>
<mx:Image id="vd" click="next();" right="0" left="0" top="0" bottom="0" maintainAspectRatio="false" source="@walk.png"/>
</mx:Canvas><mx:Canvas>
<mx:VideoDisplay id="ca" click="next();" right="0" left="0" top="0" bottom="0" maintainAspectRatio="false" />
</mx:Canvas>
</mx:ViewStack>
<mx:HBox left="5" bottom="10">
<mx:Button color="gray" borderColor="0" fillAlphas="[0, 0]" label="next" click="next();"/>
</mx:HBox>
<mx:HBox right="5" bottom="10">
<mx:Button color="gray" borderColor="0" fillAlphas="[0, 0]" label="fullscreen" click="display.toggle();"/>
</mx:HBox>
</mx:Application>
(C) Æliens
20/2/2008
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.