topical media & game development
shader-crystal.mx
shader-crystal.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;
private function click ( event:MouseEvent ):void
{
myLabel.text = "hello world";
}
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 = 4;
private function next():void {
state+=1;
if (state >= max) state = 0;
stack.selectedIndex = state;
//if (state == 2) attach();
}
loop / effect(s)
private function loop(e : Event) : void {
shader.data.size.value = [ 10 + Math.random()*20 ];
if (state == 3) shader.data.size.value = [ 0 + Math.random()*5 ];
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" source="../assets/clips/tube/balloon.flv"/>
</mx:Canvas>
<mx:Panel title="hello world" horizontalAlign="center"
paddingTop="10" paddingBottom="10" paddingLeft="10" paddingRight="10">
<mx:Label id="myLabel" width="180" fontWeight="bold" fontSize="24"/>
<mx:Button id="myButton" label="click me!" click="click(event);" />
</mx:Panel>
</mx:ViewStack>
<mx:HBox right="5" top="10">
<mx:Button color="gray" borderColor="0" fillAlphas="[0, 0]" label="camera" click="attach();"/>
</mx:HBox>
<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="stop" click="ca.stop();"/>
<mx:Button color="gray" borderColor="0" fillAlphas="[0, 0]" label="play" click="ca.play();"/>
<mx:Button color="gray" borderColor="0" fillAlphas="[0, 0]" label="fullscreen" click="display.toggle();"/>
</mx:HBox>
</mx:Application>
(C) Æliens
04/09/2009
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.