bounce
[Bindable] private var radius:uint = 100;
[Bindable] private var ball:Sprite = new Sprite();
[Bindable] private var square:Sprite = new Sprite();
[Bindable] private var vx:Number;
[Bindable] private var vy:Number;
[Bindable] private var bounce:Number = -0.9;
[Bindable] private var gravity:Number = .5;
private var oldX:Number;
private var oldY:Number;
private function init() : void {
input.text = first;
myVid.source = movie;
off = 1;
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;
addEventListener(Event.ENTER_FRAME, frame);
addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
}
import flash.media.Camera;
private var camera:Camera; // = Camera.getCamera();
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;
}
if (ball.y > (height/2)+(height/5)) gravity = (-gravity);
if (ball.y < (height/5)) gravity = (-gravity);
// myVid.mask = ball;
}
private function onMouseDown(event:MouseEvent):void
{
// story.text = "click: " + ball.x + "/" + ball.y;
oldX = ball.x;
oldY = ball.y;
addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
ball.startDrag();
removeEventListener(Event.ENTER_FRAME, frame);
addEventListener(Event.ENTER_FRAME, trackVelocity);
}
private function onMouseUp(event:MouseEvent):void
{
stage.removeEventListener(MouseEvent.MOUSE_UP, onMouseUp);
ball.stopDrag();
removeEventListener(Event.ENTER_FRAME, trackVelocity);
addEventListener(Event.ENTER_FRAME, frame);
}
private function trackVelocity(event:Event):void
{
vx = ball.x - oldX;
vy = ball.y - oldY;
oldX = ball.x;
oldY = ball.y;
}
private var peep:uint = 0;
private function hide(video:Object):void {
if (peep == 0) {
myVid.removeChild(ball);
// myVid.addChild(square);
myVid.mask = null;
peep = 1;
// tileList.visible = false;
// arrColl.removeAll();
// tileList.invalidateList();
// removeEventListener(Event.ENTER_FRAME, frame);
}
else {
peep = 0;
// tileList.visible = true;
//myVid.removeChild(square);
myVid.addChild(ball);
myVid.mask = ball;
addEventListener(Event.ENTER_FRAME, frame);
}
}
[Bindable] private var cuepoints:Array = [
{name:'cue 0', time:1.00},
{name:'cue 1', time:2.00},
];
[Bindable] private var info:String = "cue -";
[Bindable] private var show:uint = 0;
private function clear(video:Object):void {
if (show == 0) {
show = 1; tileList.visible = false;
arrColl.removeAll();
tileList.invalidateList();
}
else { show = 0; tileList.visible = true; }
}
private function select(event:Event):void {
myVid.close();
tileList.visible = false;
arrColl.removeAll();
tileList.invalidateList();
tileList.visible = true;
show = 0;
movie = input.text;
myVid.source = movie;
myVid.cuePoints = cuepoints;
story.text = movie;
myVid.play();
off = 0;
state = 0;
}
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 < 2) info = cuepoints[state].name;
if (state == 0) { story.text = "click ! to annotate ..."; }
else if (state == 1) { story.text = "... "; }
else { off = 1; story.text = ""; info="cue " + state; }
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;
}
]]>
<br;\ >
name: {data.info}
time: {data.time}