By Zevan | December 9, 2008
Actionscript:
-
var map:Vector.<Vector.<int>> = new Vector.<Vector.<int>>();
-
map[0] = new Vector.<int>();
-
map[0].push(1);
-
map[0].push(0);
-
map[0].push(0);
-
-
map[1] = new Vector.<int>();
-
map[1].push(0);
-
map[1].push(1);
-
map[1].push(0);
-
-
map[2] = new Vector.<int>();
-
map[2].push(0);
-
map[2].push(0);
-
map[2].push(1);
-
-
/*
-
map:
-
1,0,0
-
0,1,0
-
0,0,1
-
*/
This creates a two dimensional Vector of ints (flash 10 player only). The first line is the real snippet... took me a few minutes to get the syntax right the first time I needed a 2D Vector.
Posted in Vector, arrays | Also tagged actionscript |
By Zevan | December 8, 2008
Actionscript:
-
stage.frameRate = 30;
-
var xp:Number = 0;
-
var yp:Number = 0;
-
var counter:Number = 0;
-
graphics.lineStyle(0,0x999999);
-
graphics.moveTo(200,200);
-
addEventListener(Event.ENTER_FRAME, onLoop);
-
function onLoop(evt:Event):void {
-
for (var i:int = 0; i <20; i++) {
-
counter += .05;
-
xp=200 + counter * Math.cos(counter);
-
yp=200 + counter * Math.sin(counter);
-
graphics.lineTo(xp, yp);
-
}
-
if (counter> 400) {
-
removeEventListener(Event.ENTER_FRAME, onLoop);
-
}
-
}
Draws a spiral over time.
By Zevan | December 7, 2008
Actionscript:
-
Object.prototype.myVar = "I am a variable";
-
-
var s:Sprite = new Sprite();
-
-
trace(Object(s).myVar);
-
-
var v:Video = new Video();
-
trace(Object(v).myVar);
This.... should not be done... and setting myVar like this:
Actionscript:
-
Object(s).myVar = "hello";
Will cause an error....
I keep a folder on my laptop for this website..... when I have a random snippet idea I put it in this folder.... Every couple of weeks I go through this folder and turn select snippets into posts.... when I rediscovered this snippet today it really made me laugh....
By Zevan | December 6, 2008
Actionscript:
-
var xp:Number=Math.random() * stage.stageWidth;
-
var yp:Number=Math.random() * stage.stageHeight;
-
graphics.lineStyle(0,0x000000);
-
graphics.moveTo(xp, yp);
-
addEventListener(Event.ENTER_FRAME, onLoop);
-
function onLoop(evt:Event):void {
-
xp+=Math.random()*10-5;
-
yp+=Math.random()*10-5;
-
graphics.lineTo(xp, yp);
-
}
Nothing special here, but its good to know that this technique has a name... and that it's NOT Brownian Motion... more here.