topical media & game development
basic-mask.mx
basic-mask.mx
(swf
)
[ flash
]
flex
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
styleName="plain"
backgroundColor="0x000000"
xmlns:ae="*"
paddingLeft="0" paddingTop="0" paddingBottom="0" paddingRight="0"
layout="absolute"
initialize="init();"
>
<ae:component_screen id="display"/>
script
<mx:Script>
<![CDATA[
import flash.media.Camera;
private var camera:Camera; // = Camera.getCamera();
import mx.collections.ArrayCollection;
import mx.events.CuePointEvent;
import mx.controls.videoClasses.CuePointManager;
import mx.managers.SystemManager;
[Bindable] public var movie:String = "../assets/clips/tube/balloon.flv";
[Bindable] private var radius:uint = 100;
[Bindable] private var ball:Shape = new Shape();
[Bindable] private var square:Shape = new Shape();
[Bindable] private var vx:Number;
[Bindable] private var vy:Number;
[Bindable] private var bounce:Number = -0.999;
[Bindable] private var gravity:Number = .0001;
private function init():void {
var h:Number = systemManager.stage.stageHeight;
var w:Number = systemManager.stage.stageWidth;
//radius = ( h + w ) / 14;
square.graphics.beginFill(0);
square.graphics.drawRect(0, 0, w,h);
//square.x = 400;
//square.y = 400;
ball.graphics.beginFill(0);
ball.graphics.drawCircle(0, 0, radius);
ball.x = 400;
ball.y = 300;
vx = Math.random() * 30 - 5;
vy = -20;
//myVid.addChild(square);
myVid.addChild(ball);
myVid.mask = ball;
show = 0;
addEventListener(Event.ENTER_FRAME, frame);
}
private function attach(v:Object) : void {
camera = Camera.getCamera();
myVid.attachCamera(camera);
}
private function frame(event:Event):void {
var h:Number = systemManager.stage.height;
var w:Number = systemManager.stage.width;
var dx:Number = Math.random() * 2 - 1;
var dy:Number = Math.random() * 2 - 1 ;
vx += dx; vy += dy;
var s:Number = w/800;
ball.scaleX = w/800;
ball.scaleY = h/600;
vy += gravity;
ball.x += vx;
ball.y += vy;
var left:Number = 0;
var right:Number = myVid.width;
var top:Number = 0;
var bottom:Number = myVid.height;
if(ball.x + radius > right)
{
ball.x = right - radius;
vx *= bounce;
}
else if(ball.x - radius < left)
{
ball.x = left + radius;
vx *= bounce;
}
if(ball.y + radius > bottom)
{
ball.y = bottom - radius;
vy *= bounce;
}
else if(ball.y - radius < top)
{
ball.y = top + radius;
vy *= bounce;
}
// myVid.mask = ball;
}
[Bindable] private var arrColl:ArrayCollection = new ArrayCollection();
[Bindable] private var state:uint = 0;
private var off:int = 0;
[Bindable] private var cuepoints:Array = [
{name:'cue 0', time:0.00},
{name:'cue 1', time:4.60},
{name:'cue 2', time:6.75},
{name:'cue 3', time:12.75},
{name:'cue 4', time:20.75}
];
[Bindable] private var info:String = "cue -";
[Bindable] private var show:uint = 0;
private function clear(video:Object):void {
if (show == 0) {
myVid.removeChild(ball);
// myVid.addChild(square);
myVid.mask = null;
show = 1;
// tileList.visible = false;
// arrColl.removeAll();
// tileList.invalidateList();
// removeEventListener(Event.ENTER_FRAME, frame);
}
else {
show = 0;
// tileList.visible = true;
//myVid.removeChild(square);
myVid.addChild(ball);
myVid.mask = ball;
addEventListener(Event.ENTER_FRAME, frame);
}
}
private function cue(evt:Object):void {
// if (show == 1) { show = 0; tileList.visible = true; }
var pad:String = " ";
var bm:Bitmap = copy(myVid as DisplayObject);
var time:String = format(myVid.playheadTime);
if (state < 4) info = cuepoints[state].name;
if (state == 0) { story.text = "..."; }
else if (state == 1) { story.text = "... once upon a time"; }
else if (state == 2) { story.text = "there was a ..."; }
else if (state == 3) { story.text = ""; }
else { off = 1; story.text = ""; info="cue -"; state = 0; }
// arrColl.addItem({pad:pad, bitmap:bm, info:info, time:time});
state += 1;
if (off == 1) story.text = "";
}
private function copy(source:DisplayObject):Bitmap {
var bmd:BitmapData = new BitmapData(source.width, source.height);
bmd.draw(source);
return new Bitmap(bmd);
}
private function format(value:Number):String{
var sec:int = (value * 60) / 60;
var mil:int = (value - sec) * 100;
var result:String = sec.toString() + "." + mil.toString();
return result;
}
]]>
</mx:Script>
display
<mx:VideoDisplay id="myVid" source="{movie}" height="100%" width="100%" autoPlay="false"
cuePointManagerClass="mx.controls.videoClasses.CuePointManager"
cuePoints="{cuepoints}"
cuePoint="cue(event)"
/>
<mx:Label text="{movie} / {state}" color="white" top="10" right="20"/>
<mx:Label id="story" text="" color="white" top="75" left="100" fontSize="40"/>
<mx:Label text="{format(myVid.playheadTime)} / {info}" color="white" top="10" left="20"/>
controls
<mx:HBox left="20" bottom="10">
<mx:Button color="white" borderColor="0" fillAlphas="[0,0]" label="!" click="cue(myVid);"/>
<mx:Button color="gray" borderColor="0" fillAlphas="[0,0]" label="%" click="clear(myVid);"/>
<mx:Button color="gray" borderColor="0" fillAlphas="[0,0]" label="@" click="attach(myVid);"/>
</mx:HBox>
<mx:HBox right="20" bottom="10">
<mx:Button color="gray" borderColor="0" fillAlphas="[0, 0]" label=">" click="myVid.play();"/>
<mx:Button color="gray" borderColor="0" fillAlphas="[0, 0]" label="||" click="myVid.pause();"/>
<mx:Button color="gray" borderColor="0" fillAlphas="[0, 0]" label="_" click="myVid.stop();"/>
<mx:Button borderColor="0" fillAlphas="[0.0, 0.0]" label="full" click="display.toggle();"/>
</mx:HBox>
tile(s)
</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.