CLICK HERE TO COPY
Actionscript:
...
// loop through until we find the root note
// grab the third and the fifth and exit the loop
for (var i:int = 0; i<leng; i++){
if (cMajor[i] == note){
third = cMajor[(i + 2) % leng];
[...]
CLICK HERE TO COPY
Actionscript:
...
// loop through until we find the root note
// grab the third and the fifth and exit the loop
for (var i:int = 0; i<leng; i++){
if (cMajor[i] == note){
third = cMajor[(i + 2) % leng];
[...]
CLICK HERE TO COPY
Actionscript:
[SWF(width = 800, height = 600, frameRate = 60)]
import com.actionsnippet.qbox.*;
stage.frameRate = 60;
var sim:QuickBox2D = new QuickBox2D(this);
sim.createStageWalls();
sim.start();
var output:TextField = new TextField();
output.text = "Click anywhere to add points to a polygon. Hit any key to test.\n\n";
output.x = output.y = 50;
with(output) width = 300, height = 400, border = true, selectable = true, wordWrap = [...]
CLICK HERE TO COPY
Actionscript:
// print some floats as fractions
printFraction(0.5);
printFraction(0.75);
printFraction(0.48);
// try something a little more complex
var float:Number = 0.98765432;
trace("\na more complex example:");
printFraction(float);
var frac:Array = asFraction(float);
trace("double check it:");
trace(frac[0] + "/" + frac[1] +" = " + frac[0] / frac[1]);
/* outputs:
0.5 = 1/2
0.75 = 3/4
0.48 = 12/25
a more complex example:
0.98765432 = 12345679/12500000
double check it:
12345679/12500000 = 0.98765432
*/
function printFraction(n:Number):void{
[...]
CLICK HERE TO COPY
Actionscript:
trace(gcf(75,145));
// outputs 5
function gcf(a:int, b:int):int{
var remainder:int;
var factor:Number = 0;
while (1){
if (b> a){
var swap:int = a;
a = b;
b = swap;
}
remainder [...]
CLICK HERE TO COPY
Actionscript:
egyptianMultiply(12, 99);
// trace(12 * 99) // test to make sure it works
/* outputs:
/64 768
/32 384
16 192
8 96
4 48
/2 24
/1 12
---
1188
*/
function egyptianMultiply(valueA:Number, valueB:Number):void {
var left:Array = [];
var right:Array = []
// swap if valueB is smaller than value A
if (valueB <valueA){
[...]
CLICK HERE TO COPY
Actionscript:
var container:Sprite = new Sprite();
container.x = stage.stageWidth / 2;
container.y = stage.stageHeight / 2;
addChild(container);
var redBox:Sprite = new Sprite();
redBox.graphics.beginFill(0xFF0000);
redBox.graphics.drawRect(-50,-250,100,500);
redBox.rotationZ = 10;
container.addChild(redBox);
var logos:Array = []
var elements:Array = [];
elements.push({element:redBox, z:0});
// add the logos
for (var i:int = 0; i<6; i++){
var logoContainer:MovieClip = new MovieClip();
var logoText:TextField = new TextField();
logoText.defaultTextFormat = new TextFormat("_sans", [...]
CLICK HERE TO COPY
Actionscript:
var connect:Function = function(xp:Number, yp:Number, col:uint=0):Function{
graphics.lineStyle(0,col);
graphics.moveTo(xp, yp);
var line:Function = function(xp:Number, yp:Number):Function{
graphics.lineTo(xp, yp);
return line;
}
return line;
}
// draw a triangle
connect(200,100)(300,300)(100,300)(200, 100);
// draw a box
connect(100,100, 0xFF0000)(150,100)(150,150)(100, 150)(100,100);
This is one of those techniques that I never really get tired [...]
CLICK HERE TO COPY
Actionscript:
import com.actionsnippet.qbox.*;
import Box2D.Dynamics.*
stage.frameRate = 60;
var sim:QuickBox2D = new QuickBox2D(this, {debug:true});
// get at the b2DebugDraw instance
var debug:b2DebugDraw = sim.w.m_debugDraw;
debug.m_drawScale = 30.0;
debug.m_fillAlpha = 0.5;
debug.m_alpha = 0.5;
debug.m_lineThickness = 1.0;
debug.m_drawFlags = 0xFF;
sim.createStageWalls();
for (var i:int = 0; i<10; i++){
sim.addBox({x:3 + i, y:3 + i, width:2, height:0.5});
}
sim.addCircle({x:12, y:5, radius:2});
sim.start();
sim.mouseDrag();
Note: This snippet requires the QuickBox2D library
This snippet [...]
CLICK HERE TO COPY
Actionscript:
var slider:MovieClip = makeSlider();
slider.addEventListener(Event.CHANGE, function(evt:Event):void{
trace(evt.currentTarget.percent);
});
function makeSlider():MovieClip{
var slider:MovieClip = MovieClip(addChild(new MovieClip()));
var circle:Sprite = Sprite(slider.addChild(new Sprite()));
with (circle.graphics) beginFill(0x000000), drawCircle(0,0,10);
var line:Shape = Shape(slider.addChild(new Shape()));
with (line.graphics) [...]
Since the release of QuickBox2D 1.0 two bugs were discovered by numerous developers. The first bug was the inability to properly destroy group objects. The second bug was a small memory leak that caused most QuickObjects to remain in memory. Both of these bugs are now resolved.
Download QuickBox2D 1.1
Testing the memory leak. In QuickBox2D 1.0 [...]