Pergunta

I'm new to Flex. I have some doubt regarding Interface in Flex. As we know AS3 is also an Object Oriented Language. Questions are :

1.if class A extends Class B. Then Class A can't implements interface C. Why ?

  1. The class which don't extends other class can implement the interface. What is the reason behind that ?

  2. why we can't give access specifier to the functions declaration in Flex Interface ?

    Why can't we write like class A extends class B implements C

Updates Of My Question with Code

Interface Part ->

package
{
    public interface InterfaceTesting
    {
        function foo():void;        
    }

}

Class A ->

package
{
    import mx.controls.Alert;

    public class A 
    {
        public function test():void
        {
            trace("control is in Top Class")
            Alert.show("control is in Top Class");
        }   

    }

}

Class B ->

package
{
    import mx.controls.Alert;
    import mx.messaging.channels.StreamingAMFChannel;
    import mx.states.OverrideBase;

    public class B extends A implements InterfaceTesting
    {
        override public function test():void
        {
            Alert.show("We are in Second Class");
        }

      public function foo():void
        {
            Alert.show("This is Interface Implementation");
        }
}
}

I'm getting an Error in class B. which is 1024- Overriding a function which is not marked for override.

Please Guide me.

Foi útil?

Solução

I'm not entirely sure what you're asking, but what you're describing should be possible.

A valid example:

ClassA.as

package  {
    public class ClassA extends ClassB implements InterfaceC {
        public function ClassA() {

        }

        public function bar():void {

        }
    }
}

ClassB.as

package  {
    public class ClassB {

        public function ClassB() {

        }

        public function foo():void {

        }
    }
}

InterfaceC.as

package {
    public interface InterfaceC {
        function foo():void; // Will be inherited from ClassB 
        function bar():void; // Is defined in ClassA
    }
}

Edit: Regarding your third question:

To comply with an interface, the methods defined in the interface needs to be either public or internal. This is because an interface is useful only for declaring what methods are available publicly.

If your class implements InterfaceC (above) and contains the function foo() but has declared it private - it cannot be reached externally and hence won't comply with the interface.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top