Hi

for Tour de Jewel I'm trying to create a component in AS that could be
extended in MXML. The component creates a Tab and two SectionContent.
One is for the current example and the other shows the source code loaded
from GitHub.

So when I add content in mxml to an instance of this component, I don't
want to add to the root of the component. I want to add to one of the tabs.
For this I tried to override addedToParent, but I find that the content is
created in the root and in the tab.

If we see the code:

override public function addedToParent():void
        {
            if (!_initialized)
            {
                // each MXML file can also have styles in fx:Style block
                ValuesManager.valuesImpl.init(this);
            }

            super.addedToParent();

            if (!_initialized)
            {
                MXMLDataInterpreter.generateMXMLInstances(_mxmlDocument,
this, MXMLDescriptor);

                dispatchEvent(new Event("initBindings"));
                dispatchEvent(new Event("initComplete"));
                _initialized = true;

                //?? why was this added here? childrenAdded(); //?? Is this
needed since MXMLDataInterpreter will already have called it
            }
        }

I think the problem is in super.addedToParent(); That will create the
content in the root, and we can't change that.

One way to do this is refactor this part :

MXMLDataInterpreter.generateMXMLInstances(_mxmlDocument, this,
MXMLDescriptor);

                dispatchEvent(new Event("initBindings"));
                dispatchEvent(new Event("initComplete"));


to a function that can be overriden in subclasses, so we can change the
"this" to other component, making it more reusable, .or do other changes

thoughts?


-- 
Carlos Rovira
http://about.me/carlosrovira

Reply via email to