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 14, 2009
Actionscript:
-
[SWF(width=600,height=400,backgroundColor=0x000000,frameRate=30)]
-
var mcs:Vector.<MovieClip> = new Vector.<MovieClip>();
-
var num:int = 2000;
-
for (var i:int = 0; i<num; i++){
-
var s:MovieClip = new MovieClip();
-
s.graphics.lineStyle(0,0xFFFFFF);
-
s.graphics.drawCircle(0,0, Math.random()*30 + 3);
-
s.x = Math.random()*stage.stageWidth;
-
s.y = Math.random()*stage.stageHeight;
-
// comment out to kill your cpu
-
s.cacheAsBitmap = true;
-
addChild(s);
-
s.vx = Math.random() * 2 - 1;
-
s.vy = Math.random() * 2 - 1;
-
mcs.push(s);
-
}
-
addEventListener(Event.ENTER_FRAME, onCenter);
-
function onCenter(evt:Event):void{
-
for (var i:int = 0; i<num; i++){
-
mcs[i].x += mcs[i].vx;
-
mcs[i].y += mcs[i].vy;
-
}
-
}
This was created in response to a question about the real speed gain of cacheAsBitmap. Just comment out the cacheAsBitmap line to see the difference.
Despite it's extreme simplicity, this is actually a rather fun file to play with, change some of the graphics class method calls around and see what happens.
By Zevan | February 13, 2009
Actionscript:
-
var path:String = "section/home.swf";
-
-
var deepLinkValue:String = path.split("/")[1].split(".swf")[0];
-
-
trace(deepLinkValue);
-
/*outputs:
-
home
-
*/
As a primarily self taught programmer there was a time when I didn't know what a regular expression was. There was also a time when ActionScript didn't have them (you had to use a library). Sometimes when I'm in a rush I still do weird things like the above instead of regular expressions... pretty nasty I know.
Here are two different regular expressions that do the same thing:
Actionscript:
-
var path = "section/home.swf"
-
-
trace(path.match(/\w+(?=\.)/))
-
/*outputs:
-
home
-
*/
-
-
trace(path.replace(/.+\/|\..+/g, ""))
-
/* also outputs:
-
home
-
*/
Actually, I'd be curious to see other regular expressions that only return one value (not an array) that achieve this same thing... feel free to post of a comment if you can think of one...
By Zevan | February 12, 2009
Actionscript:
-
var someString:String = "_file";
-
trace(someString.substr(1));
-
/*
-
ouptuts:
-
file
-
*/
Turns out the second argument of substr() is optional..... not sure how I never noticed that before.