Re: [Flashcoders] extends / super.function() bug

2006-06-30 Thread Jim Cheng

Joeri van Oostveen wrote:


I'm having this (weird) problem:

the doSomething() gets called 3 times!
First time the B version, which calls the A function (2nd one).
Next, the A function is called again... which should not be so!!! :(


It's a rather annoying but poorly documented bug that's been around for 
quite a while--at least since since Flash Player 6 if I'm not mistaken. 
 If you search through the ChattyFig archives, you can find some of the 
past discussions here:


http://chattyfig.figleaf.com/pipermail/flashcoders/2003-February/064363.html
http://chattyfig.figleaf.com/pipermail/flashcoders/2004-November/126203.html

In addition to this bug, the super pointer has traditionally been quite 
problematic and buggy, particularly in atypical usages such as 
referencing a method other than the currently overridden one from the 
superclass, or within a with block.


In your case, the simplest solution would be to make sure that you 
override the afflicted method in each class in your inheritance chain, 
although this can get rather ugly very quickly, particularly with large 
codebases.


I actually ran into this exact same bug myself a couple of weeks ago 
while hacking together an AOP-based run-time profiler for ActionScript 
2.0 and got myself quite confused for a while until I hit up a few 
friends of mine whom helpfully refreshed my memory.


At that time, my friend and co-worker Sean Christmann recommended the 
following fix from a previous project of his:




  _global.superFix = function(curSuper) {

 // arguments.callee is this function object
 // set the super passed in so we can use it in __resolve
 arguments.callee.__super = curSuper
 arguments.callee.__caller = arguments.caller;

 // return ourselves so the method gets called on us
 return arguments.callee;
  }

  // Now, instead of calling super.myMethod(), do the following:
  superFix(super).myMethod();



Jim


___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


[Flashcoders] extends / super.function() bug

2006-06-30 Thread Joeri van Oostveen

I'm having this (weird) problem:

(Not sure if it's Flash Player (8/Mac) related, or compiletime related (mtasc))

I have for example this code:
class A
{
public function A()
{

}

public function doSomething():Void
{
// all sort of code
}
}


class B extends A
{
public function B()
{
super();
}

public function doSomething():Void
{
super.doSomething();

// more code
}
}


class C extends B
{
public function C()
{
super();
}
}

And I for example do this:

var c:C = new C();
c.doSomething();

the doSomething() gets called 3 times!
First time the B version, which calls the A function (2nd one).
Next, the A function is called again... which should not be so!!! :(

When I do this:
class C extends B
{
public function C()
{
super();
}

// useless wrapper
public function doSomething():Void
{
super.doSomething();
}
}

The doSomething() is also called 3 times, but first the C, which calls
the B, which calls the A function. As it should...

Now I hate to have to include every override function in all the
classes, so is there a solution to this?? (or does anyone know what is
going on / wrong?)

thanks in advance!
Joeri
___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com