By Zevan | January 1, 2010
CLICK HERE TO COPY
Actionscript:
loop(20);
function loop(i:int):void {
if (i <0) return;
trace(i);
loop(i - 1);
}
/* outputs:
20
19
18
17
16
15
14
13
12
11
10
9
8
7
6
5
4
3
2
1
0
*/
This snippet uses a recursive function to count down from some number. Recursion is pretty useless in actionscript, it will eventually cause an error... If you were to try to countdown from a higher number it [...]
By Zevan | December 31, 2009
CLICK HERE TO COPY
Actionscript:
var one:Array = [1,2,3];
var two:Array = [10, 20, 30];
var zipOneTwo:Array = zip(one, two);
// trace each tupple
for each (var tuple:Array in zipOneTwo){
trace(tuple);
}
/* outputs:
1,10
2,20
3,30
*/
function zip(a:Array, b:Array):Array{
var longest:Array = (a.length>= b.length) ? a : b;
var zipped:Array = [];
for (var i:int = 0; i<longest.length; i++){
[...]
Posted in arrays | Tagged actionscript, as3, flash |
By Zevan | December 30, 2009
CLICK HERE TO COPY
Actionscript:
var boxA:Shape = Shape(addChild(new Shape()));
with (boxA.graphics) beginFill(0), drawRect(-10,-10,20,20);
var boxB:Shape = Shape(addChild(new Shape()));
with (boxB.graphics) beginFill(0), drawRect(-10,-10,20,20);
boxA.x = 100;
boxA.y = 100;
boxB.x = 200;
boxB.y = 100;
var rot:Number = 32750;
addEventListener(Event.ENTER_FRAME, onLoop);
function onLoop(evt:Event):void {
rot += 1
// will stop rotating
boxA.rotation = rot
// will keep rotating
boxB.rotation = rot % 360;
}
I recently [...]
By Zevan | December 17, 2009
I took some pictures of Four by Four last night:
Have a look at them over at flickr...
Posted in binary | Tagged misc |