views:

218

answers:

1

I'm using FlashBuilder 4 beta2. My base class has a function foo():

protected function foo(s:String, z:String=null): void{}

Literally "foo" so that there's no chance I'm stepping on a built-in method. I am getting an "Incompatible override" error when attempting to override the method in a subclass:

override protected function foo(s:String, z:String=null): void{}

Does the optional parameter do something "behind the scenes" that makes it illegal to override the method?

Thanks

T.

A: 

Never seen an issue like that before. Maybe you want to copy/paste your function from the base class into your extended class and add the "override" then. I have a feeling your method signatures don't match.

BaseClass.as

package {   
    public class BaseClass {
        protected function foo(s:String, z:String = null) {
            // implement in derived class
        }
    }
}

SubClass.as

package {
    public class SubClass extends BaseClass {

        override protected function foo(s:String, z:String = null) {
            trace("s = " + s);
            trace("z = " + z);
        }

        public function bar(s:String, z:String = null) {
            foo(s, z);
        }
    }
}

Then elsewhere:

var c:SubClass = new SubClass();
c.bar("string1", "string2");

traces

s = string1
z = string2
sberry2A
Thanks for the reply. It is good to know that the approach I'd like to take is legit ActionScript. But FB4 beta 2 is somewhat flaky:I delete the foo() function and recompile the project and the error goes away. Then I recreate the foo() function exactly as before and recompile and the error does not come back. Then I uncomment a different function and the error returns on foo().
Tim