Hi David,

I to am an AS3 novice. Wrote my first(trivial) action script file about 
an hour ago. :)

A couple of ideas. Not sure if they will be of much help to you, but 
incase you hadnt considered them already..

. you could return the value returned by the call to super.
   ie)
   Camera c = super.move;
   //....// some local x,y stuff
   return c;

. you could use an interface as the return value. eg) interface ICamera 
would define the move and rotate methods and return an ICamera and your 
Camera classes would implement ICamera.

I realise that these options do not do what you asked for, but you might 
find one of these is an acceptable alternative.

HTH.

cheers,
  - shaun

David_Stafford wrote:
> Please pardon this simple-minded question from an AS3 novice.
> 
> My base class often returns 'this' from methods which makes it 
> convenient to write code like:
> 
>   camera.move( 10, 12 ).rotateX( 45 ).rotateY( 90 );
> 
> The problem comes when code extends the base class and overrides one 
> of these functions.  The compiler insists, correctly, that the return 
> type of an overriding function must match the one in the base class.  
> What I want to do is return the 'this' object that is of the type of 
> the derived class.  Is this possible?
> 
> The following is a contrived example to demonstrate.  It won't 
> compile because the overridden function in the derived class wants to 
> return a type of MyCamera rather than Camera:
> 
> 
> public class Camera
>   {
>   var x:int = 0;
>   var y:int = 0;
> 
>   public function move( x:int, y:int ) :Camera
>     {
>     this.x += x;
>     this.y += y;
> 
>     return( this );
>     }  
>   }
> 
> public class MyCamera extends Camera
>   {
>   override public function move( x:int, y:int ) :MyCamera
>     {
>     super.move( x, y ); 
> 
>     if( x < 0 )  x = 0;
>     if( y < 0 )  y = 0;
> 
>     return( this );
>     } 
>   }


Reply via email to