By Zevan | February 16, 2009
Actionscript:
-
trace("min", Math.min(100, 99, 32, 75, 44, 90));
-
trace("max", Math.max(100, 99, 32, 75, 44, 90));
-
/*outputs:
-
32
-
100
-
*/
It's easy not to notice that Math.min() and Math.max() can take any number of arguments. I've seen people nest min/max calls instead of using the above option.... like this:
Actionscript:
-
trace(Math.min(1, Math.min(2, 3)));
Posted in misc | Tagged actionscript, flash |
By Zevan | February 15, 2009
C:
-
SELECT * FROM _users WHERE SOUNDEX(name) LIKE SOUNDEX('jon');
Not ActionScript, but the coolest thing I've seen in Mysql in awhile, the soundex function will convert a string into a soundex index... read more about it on wikipedia.
I did some tests and it matches things like:
what's your name? & whats yer name
very cool... since this isn't ActionScript, I will post another snippet right after this.
UPDATE: Actually started reading more about this stuff and dug up some algorithms... metaphone etc... fun stuff, maybe I'll port some of it to actionscript...
By Zevan | February 11, 2009
Actionscript:
-
private var _correctPath:String;
-
-
//.... somewhere a little later
-
-
if (root.loaderInfo.url.split("http://").length == 1){
-
_correctPath = "http://www.mywebsite.com/this/is/an/absolute/path/";
-
}else{
-
_correctPath = "";
-
}
I like to do something like this when I'm working locally... it automatically tells my swf to use an absolute path for php files, xml files etc.... then, when I upload it, the LoaderInfo.url property contains an "http://" so it uses a relative path for all the external files. This is common especially if you don't have php and mysql installed on your machine and need to test these using your server.
Posted in misc | Tagged actionscript, flash |
By Zevan | February 10, 2009
Actionscript:
-
// see previous post for details, this code won't run on it's own
-
with(addChild(window)){
-
x = 10, y = 10;
-
with(addChild(c0)) x = 10, y = 10;
-
with(addChild(c1)) x = 20, y = 10;
-
with(addChild(box)){
-
x = 50, y = 10;
-
with(addChild(txt)) x = 5, y = 5;
-
}
-
}
It's entertaining to try and think of different DisplayObject nesting techniques. I have a few more of these rolling around in my head that I'll try out soon.... The only good/notable thing about the above is that it shows that nested with statements actually work like you'd expect them to....
Posted in misc | Tagged actionscript, flash |