What's a good way to make a Flex component with placeholders in it?

Posted by Daniel Brockman on Stack Overflow See other posts from Stack Overflow or by Daniel Brockman
Published on 2009-08-19T12:16:32Z Indexed on 2010/03/13 7:05 UTC
Read the original article Hit count: 241

Filed under:
|
|
|
|

I want to create a component that has a couple of "holes" that are to be filled in differently on each use. Currently, I'm doing it like this (using the Flex 4 framework in this example --- it would look almost the same for Flex 3):

public var fooComponent : IVisualElement;
public var barComponent : IVisualElement;

override protected function createChildren() : void
{
  super.createChildren();

  fooContainer.addElement(fooComponent);
  barContainer.addElement(barComponent);
}

<Group id="fooContainer"/>
<!-- ... other components ... -->
<Group id="barContainer"/>

This works well, but it's kind of a lot of code to write for something so simple.

What I'd like is something like this:

[Bindable] public var fooComponent : IVisualElement;
[Bindable] public var barComponent : IVisualElement;

<Placeholder content="{fooComponent}"/>
<!-- ... other components ... -->
<Placeholder content="{barComponent}"/>

Now, I could implement the Placeholder component myself, but I can't help wondering if there isn't a better way to do this using the existing tools in the Flex framework.

Theoretically, with the proper compiler support, it could even be boiled down to something like this:

<Placeholder id="fooComponent"/>
<!-- ... other components ... -->
<Placeholder id="barComponent"/>

© Stack Overflow or respective owner

Related posts about flex

Related posts about flex3