Category Archives: misc

Math.min() Math.max() …rest

Actionscript:
  1. trace("min", Math.min(100, 99, 32, 75, 44, 90));
  2. trace("max", Math.max(100, 99, 32, 75, 44, 90));
  3. /*outputs:
  4. 32
  5. 100
  6. */

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:
  1. trace(Math.min(1, Math.min(2, 3)));

Posted in misc | Tagged , | Leave a comment

MYSQL SOUNDEX

C:
  1. 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...

Also posted in string manipulation, strings | Leave a comment

Is This swf Online?

Actionscript:
  1. private var _correctPath:String;
  2.  
  3. //.... somewhere a little later
  4.  
  5.  if (root.loaderInfo.url.split("http://").length == 1){
  6.         _correctPath = "http://www.mywebsite.com/this/is/an/absolute/path/";
  7.     }else{
  8.         _correctPath = "";
  9.     }

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 , | 4 Comments

The Big init() #2

Actionscript:
  1. // see previous post for details, this code won't run on it's own
  2. with(addChild(window)){
  3.     x = 10, y = 10;
  4.     with(addChild(c0)) x = 10, y = 10;
  5.     with(addChild(c1)) x = 20, y = 10;
  6.     with(addChild(box)){
  7.         x = 50, y = 10;
  8.         with(addChild(txt)) x = 5, y = 5;
  9.     }
  10. }

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 , | Leave a comment