By Zevan | December 18, 2008
Actionscript:
-
addEventListener(Event.ENTER_FRAME, onLoop);
-
-
function onLoop(evt:Event):void {
-
var boolA:Boolean = false;
-
var boolB:Boolean = false;
-
-
if (mouseX> 200){
-
boolA = true;
-
}else{
-
boolA = false;
-
}
-
-
if (mouseY <200){
-
boolB = true
-
}else{
-
boolB = false;
-
}
-
-
if (boolA || boolB){
-
trace("regular or");
-
}
-
-
// this is the XOR conditional
-
if (int(boolA) ^ int(boolB)){
-
trace("exclusive or");
-
}
-
-
}
There's an obvious more logical ways to do this. But I thought it was somewhat interesting to see....
So in binary XOR will give us:
0^0 = 0;
0^1 = 1;
1^0 = 1;
1^1 = 0;
What other operator might you use to get the same results?... that's right !=
With regular OR we get:
0|0 = 0;
0|1 = 1;
1|0 = 1;
1|1 = 1;
By Zevan | December 17, 2008
Actionscript:
-
trace((new Date()).getTime() + Math.random()*0xFFFFFF);
A hacky way to get a unique ID, although this isn't, perfect it works well enough. For a project that you really expect to get huge amounts of traffic... you might consider using php's uniqid() function and passing it into your swf. That said, the odds of two users getting the same two ID values are about as good as the odds of you winning the lottery twice in a row.
Here is a version wrapped in a function, with a prefix argument:
Actionscript:
-
trace(uniqid("z"));
-
-
function uniqid(prefix:String):String{
-
return prefix + (new Date()).getTime() + Math.random()*0xFFFFFF;
-
}
By Zevan | December 11, 2008
Actionscript:
-
for (var i:int = 1; i<26; i++) with(addChild(new TextField())) x = 10, y = i * 10, text = "line" + i;
code will create 25 TextFields that say "line1", "line2", "line3" etc...
If you don't already know, Keith Peters has started up the 25 line actionscript contest again... The first round of results are in and you can view the 12 finalists swfs and code here.
I was particularly impressed with this one...by Cay Garrido... when I looked at it I really couldn't figure out how that kind of seemingly complex flocking could be done with 25 lines. You can see the code here.
Inspired by the entries, Peters created a strange attractor in 6 lines.
I can't wait to see next months entries.
Posted in misc | Tagged actionscript, flash |