You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@royale.apache.org by Carlos Rovira <ca...@apache.org> on 2018/12/25 12:14:51 UTC

Trying to add MXML content to a sub component of the document

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

Re: Trying to add MXML content to a sub component of the document

Posted by Carlos Rovira <ca...@apache.org>.
Hi Alex,

El mar., 25 dic. 2018 a las 18:19, Alex Harui (<ah...@adobe.com.invalid>)
escribió:

> Ideally, there won't be any Royale components that are "MXML-only",
> meaning they can only be used in MXML.


Right, this component should be used in AS, maybe I was mixing my use case
in the explanation, but I always think in components and not if they are
used in AS3 or MXML.

It sounds like there is "one set of children" for this component,


No. The components declared are part of what we call "Chrome" in components
like Panel you referred.


> so folks will be tempted to call addElement to add children from AS.


Yes. doing "component.addElement(childComponent)" must add childComponent
to the right subelement in component like in Panel.


> Basic Panel already has code that redirects the actual parent to an
> internal container.  Maybe that's what you want.
>
>
Yes, I already worked with Panel. And Jewel Wizard really follows Panel way
of doing things. But I wasn't trying to create a complex royale component
with various files (strand, beads, with model, controller, view, and so
on...).

Maybe the difference is that Panel is a more elaborated component and I was
searching for some basic way of doing things. But maybe the only approach
is go the Panel approach, since I must use addElement for the initial
components as well.

I'm not sure if we have a component that has multiple sets of children, but
> it is certainly possible.


I really don't look for multiple sets por children. I think that would be
somewhat problematic for the end user.

Ok, so I'll follow Panel convention for this case too.

Thanks!

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

Re: Trying to add MXML content to a sub component of the document

Posted by Alex Harui <ah...@adobe.com.INVALID>.
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" <ca...@apache.org> 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