views:

22

answers:

1

Hello!

Is there any way to get interface to play along with custom namespace? Example follows.

IHeaderRenderer.as:

public interface IHeaderRenderer{
 function set header(value:IHeader):void;
 function get header():IHeader;
}

HeaderRenderer.as

import fi.test.internalNamespace;
public class HeaderRenderer implements IHeaderRenderer{
    internalNamespace function set header(value:IHeader):void{
         // do something
    }

    internalNamespace function get header():IHeader{
         // do something
    }
}

This gives you the basic compiler error:

1044: Interface method get header in namespace fi.gridutils.headerrenderers:IHeaderRenderer not implemented by class fi.gridutils.headerrenderers.implementation:HeaderRenderer.

Why is this needed, you might ask. I'm developing a component, where the header accessors should not be directly visible to the components end user (developer), but if the developer wants to create his own Renderer he should know that they are needed. This is because the parent component will use these accessors to give the custom renderer the data it needs to render the header correctly.

Now to my mind there seems to be only three choices:

1) use public access control. This has the setback that the end developer will see accessors, which should not be directly accessed by him. Plus they add unnecessary clutter as they appear in auto-complete.

2) do not use interface. This means the end user has pretty poor options of developing the component further.

3) use the interface, but omit the accessors that use internalNamespace. Now the end developer will not know that he should add also header accessors to his custom headerrenderer class, which ends up in Flash Player giving following error to the developer in runtime:

Cannot create property internalNamespace/::header on fi.gridutils.headerrenderers.implementation.HeaderRenderer.

Sorry for all the blabbing. Any cunning ideas how this kind of situation could be handled?

+1  A: 

In ActionScript, the interface methods need to be public. What good is an interface, if you can't guarantee the component using it can access the relevant interface methods?

that said, you can use the exclude metadata to prevent properties from showing up in code hinting.

Something like this:

[Exclude(name="header", kind="property")] 

More info

www.Flextras.com