Skip to main content
Known Participant
August 31, 2009
Question

How bout an IAttachable Interface?

  • August 31, 2009
  • 1 reply
  • 1490 views

In the layouts, I need to perform certain actions just as the layout is basically "attached" to the group, and when it is "detached".  A few of the basic cases are hardcoded right in the GroupBase's layout accessor, such as setting the target to null and removing an eventlistener, and I would like to customize that.

For instance, some layouts might modify the includeInLayout property on their children, or might add an offset to the position that's required for the layout, for centering, rotation, etc....  So when I switch layouts, I need to make sure I reset the defaults, in the "detach" method.

public interface IAttachable

{

     function attach(target:Object):void;

    

     function detach(target:Object):void;

}

You can also use that for an IAnimator, if there was one, and IController, or ICamera, ILayout, etc.

- Lance

This topic has been closed for replies.

1 reply

August 31, 2009

Lance - what would you gain from having a generic interface common to al these types?

E.

viatroposAuthor
Known Participant
August 31, 2009

Ely,

1) Developer would have a consistent and well defined way of implementing classes that could be added and removed from a component.

2) It's paints a much clearer picture of what's actually going on... it's the next logical step of refactoring the LayoutBase for instance.

3) It would give you a well-defined space to do work when an item is attached and detached from a component.

Right now the ideas almost in there, but not quite.  If there was that interface, when I looked through the code I'd be like "ohhhh... that's how it works" much faster than it is right now.  And I could easily add a lot of new functionality in those methods, knowing that an IAttachable, when attached does 'this', when detached does 'that'.

It's not an interface like IVisualElement where you need to know if it's an IVisualElement in the Layout for example, but an interface that helps structure and organize the code so the developer has a few more tools and helpful patterns at hand.

Lance

September 2, 2009

Lance -- it sounds like you're looking for a generic way to attach

anything to a component. Is that right?

Ely.