Ideally, there won't be any Royale components that are "MXML-only", meaning 
they can only be used in MXML.   MXML is a declarative language which implies 
you can declare all of the children at compile-time.  There is probably always 
some scenario for any Royale component that requires determining at least one 
of the children at run-time, so there should be a good AS API for all Royale 
components.

It sounds like there is "one set of children" for this component, so folks will 
be tempted to call addElement to add children from AS.  Basic Panel already has 
code that redirects the actual parent to an internal container.  Maybe that's 
what you want.

I'm not sure if we have a component that has multiple sets of children, but it 
is certainly possible.  The key part of the code you posted is the property 
MXMLDescriptor.  It is a special data structure generated from the children of 
any component with an "mxmlContent" property.  But it should be ok for any 
component to have another property that is an Array and MXML children can be 
declared for it.  The only trick is that by default, those children will be set 
earlier than MXMLDescriptor since they are not special cased.  I think our 
single-MXML-file examples work this way in Basic:  what you set as initialView 
gets created and added earlier than it would in other Containers.

So, decide on your AS API and how children are to be handled.  Then see if 
there are any remaining issues with MXML.  The default code will call 
addElement just like anyone using the component from AS.

HTH,
-Alex

On 12/25/18, 4:15 AM, "Carlos Rovira" <[email protected]> wrote:

    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
    
https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fabout.me%2Fcarlosrovira&amp;data=02%7C01%7Caharui%40adobe.com%7C29c3815b6f3449bcd4d408d66a629c4b%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C636813369142181975&amp;sdata=3IXx0FrWQ2wj8lBm2HDZ%2B8Mju9J8s8zC3naFfvEyZyE%3D&amp;reserved=0
    

Reply via email to