Re: [flexcoders] rewriting a function using prototype?

2009-12-28 Thread Paul Andrews
mitchgrrt wrote:
>
>
> We have a situation where some ActionScript classes are automatically 
> generated by an Ant script.  So we can't edit them because they are 
> regenerated on each build.
>
> I want to make one function in one of these classes behave 
> differently.  If I had normal source code editing available, I could 
> just add a line to the function and be done.
How about extending the Ant generated classes and overriding the function?

Paul
>
> I tried rewriting the function using prototype.  It didn't quite work. 
>  Doing some reading, it sounds like this would have worked with old 
> versions of Flex but no longer with Flex 3.  Here's a little example:
>
>  public static function createJunk():void {
>   junk1.prototype["f1"] = function ():void { Alert.show("junk1 f1
> override"); };
>   junk1.prototype["f2"] = function ():void { Alert.show("junk1
> f2"); };
>  
>   var j:junk1 = new junk1();
>   j["f1"]();
>   j["f2"]();
>  }
>
> class junk1 {
> import mx.controls.Alert;
> public function f1():void { Alert.show("junk1 f1"); }
> }
>
> The call to f2 works, showing "junk1 f2", but the call to f1 doesn't 
> get overwritten.  It still shows "junk1 f1".
>
> Doing some reading, I found here 
> 
>  that 
> "fixed properties are always preferred over prototype properties" 
> which explains the behavior.
>
> Does anybody know of a way to use prototype, or some other clever 
> trick, to overwrite a function at runtime?  Thanks.
>
>
> 



[flexcoders] rewriting a function using prototype?

2009-12-28 Thread mitchgrrt
We have a situation where some ActionScript classes are automatically
generated by an Ant script.  So we can't edit them because they are
regenerated on each build.
I want to make one function in one of these classes behave differently. 
If I had normal source code editing available, I could just add a line
to the function and be done.
I tried rewriting the function using prototype.  It didn't quite work. 
Doing some reading, it sounds like this would have worked with old
versions of Flex but no longer with Flex 3.  Here's a little example:
  public static function createJunk():void {  junk1.prototype["f1"] =
function ():void { Alert.show("junk1 f1 override"); }; 
junk1.prototype["f2"] = function ():void { Alert.show("junk1 f2"); };   
var j:junk1 = new junk1();  j["f1"]();  j["f2"](); }
class junk1 { import mx.controls.Alert; public function f1():void {
Alert.show("junk1 f1"); }}
The call to f2 works, showing "junk1 f2", but the call to f1 doesn't get
overwritten.  It still shows "junk1 f1".
Doing some reading, I found here
  that "fixed properties are always preferred over prototype
properties" which explains the behavior.
Does anybody know of a way to use prototype, or some other clever trick,
to overwrite a function at runtime?  Thanks.