Unique Child Bounds
Drag the ball and toss it.
JAVASCRIPT NEEDED TO DO THIS WITH STRIKEDISPLAY:
var root = new StrikeDisplay("main","#000000",30,true); var wid = root.stage.stageWidth; var hei = root.stage.stageHeight;
var b = new Ball("#FFFFFF",30); b.disp.x = b.disp.y = 200; root.stage.addChild(b.disp);
var b2 = new Ball("#CCCCCC",10); b2.disp.x = -b.disp.width; b2.disp.y = -b.disp.height; b.disp.addChild(b2.disp);
b.disp.addEventListener("mouseDown",startDrag); root.stage.addEventListener("enterFrame",runLoop); var dragging = false; var prlx = [0,0]; var vel = [0,0];
function Ball(_color,_size) { this.c = _color; this.disp = new Sprite(); this.disp.graphics.beginFill(this.c,1); this.disp.graphics.drawCircle(0,0,_size); this.disp.graphics.endFill(); this.disp.addEventListener("enterFrame",this.rotateMe.bind(this)); } Ball.prototype.rotateMe = function(evt) { this.disp.rotation+=3; } function startDrag(evt) { vel = [0,0]; root.stage.addEventListener("mouseUp",killDrag); b.disp.removeEventListener("mouseDown",startDrag); prlx = [root._mouse.x-b.disp.x,root._mouse.y-b.disp.y]; dragging = true; } function runLoop(e) { if (dragging) { var n = root._mouse.x-prlx[0]; var m = root._mouse.y-prlx[1]; vel = [n-b.disp.x,m-b.disp.y]; b.disp.x = n; b.disp.y = m; } else { b.disp.x += vel[0]; b.disp.y += vel[1]; } if (b.disp.x>root.stage.stageWidth-b.disp.width/2 || b.disp.x<b.disp.width/2) { b.disp.x=b.disp.x<b.disp.width?b.disp.width/2:root.stage.stageWidth-b.disp.width/2; vel[0]*=-1; } if (b.disp.y>root.stage.stageHeight-b.disp.height/2 || b.disp.y<b.disp.height/2) { b.disp.y=b.disp.y<b.disp.height/2?b.disp.height/2:root.stage.stageHeight-b.disp.height/2; vel[1]*=-1; } } function killDrag(evt) { root.stage.removeEventListener("mouseUp",killDrag); b.disp.addEventListener("mouseDown",startDrag); dragging = false; } function showB() { root.showRedrawBounds = (document.getElementById('bounds').checked); } function uniqueB() { root._uniqueChildBoundaries = (document.getElementById('unique').checked); }