flash - How can I make a class constructor be callable as a function? -


some of top level classes can instantiated called function (e.x. new number() , number(), new boolean() , boolean(), new array() , array()).

usually used type conversion or shortcut instantiation. able same thing:

public class foo {   public function foo():void   {     //do   } }  public function foo():foo {   //do stuff;   return new foo(); } 

is possible? if so, how?

edit clarify:

what wanted create logging class interact flash/javascript, , cross-browser compatible. wanted able use log function alias of method in log class. got me wondering whether implement custom casting function because. i've realized it's not possible, fun play anyway.

you can define classes:

package [package name] {   public class foo   {     public function foo():void     {       //do stuff     }   } } 

and can define functions:

package [package name] {   public function foo():bar   {     return new bar();   } } 

but classes , functions cannot have naming collisions. otherwise you'll script error.

a custom casting function cannot defined same name class, can implemented under different name:

package [package name] {   public function castfoo(foo:*):foo   {     //do stuff     return foo(foo);   } } 

Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -