views:

447

answers:

2

If I have 2 classes and the first extends the second, how can the second class call a static function from the first?


package p1 {
    class a {
        static function a1() {
            //do soemthing
        }
    }

    class b extends a {
        static function b1() {
            //do something else
        }
    }
}

a.a1(); // this works
b.a1(); // this doesn't work
b.b1(); //this works
A: 

Use super to call the parent method.

super.b1();

EDIT: Ok, looking at what you wrote, I think you need to set the scope of a1 to be public or protected.

CookieOfFortune
b1 is in the subclass b, and if it's extending a, it should inherit a's functions and be able to call them normally.
quoo
+2  A: 

When "B extends A" - this actually is not the same as "class B has all methods and properties of A". Not class, but object of class B implements all properties and methods, defined in class A. When you call a static method or property - you deal with classes but not objects (it looks very similar to namespaces usage).

ADDED: The only way solve your task is to override a1(args) in class B and to call super.a1(args) inside... 1 string of code. But it seems to me, that you have a software architect problem if it's not possible to avoid such kind of usage.

Jet
This answer is correct. To expand a tad, when you call a method on an *instance* of class b, if that method doesn't exist then Flash will check class a. But when you call static methods, you call them via a (global) reference to the qualified class name, which is not something that has any kind of inheritance hierarchy.
fenomas
Makes sense. Not what I wanted to hear but I can deal with it.
Kevin