Hello world!
Helo as-cripters!
Yes, just another as3 blog, what can this bring new? Have no idea, maybe this is just for personal use, to keep track of my discoveries in the fascinating world of flash/flex/as3. Or maybe you can benefit somehow. I sure hope so!
First of all, this is by far the best language i ever coded in. Fast, friendly, flexible, portable… what else?
One of the goodies it has, maybe my most precious: closures.
You can write something like this:
//we have a class class MyClass { public function MyClass(str:String) { this.str = str; } private var str:String; public function myMethod():void { trace(str); } } //somwere else var obj1:MyClass = new MyClass('foo'); var obj2:MyClass = new MyClass('bar'); var c1:Function = obj1.myMethod; var c2:Function = obj2.myMethod; c1(); c2();
And why is this working? Because in AS3, a function reference also stores the object it belongs to. That’s fun, basically because it spares me an extra function call to that Delegate thing when adding an event. The code gets cleaner and safer.
You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.



Leave a Reply