通过MXML扩展MXML自定义组件 [英] Extending MXML custom components via MXML

查看:151
本文介绍了通过MXML扩展MXML自定义组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要做的是:创建一个带有一些子元素的MXML组件,然后通过MXML扩展它,以创建一个包含更多子元素的新组件,而不会丢失原始组件。
也就是说

创建一个组件bc.mxml

pre $ $ $ $ c><?xml version =1.0encoding =utf-8?>
xmlns:s =library://ns.adobe.com/flex/spark
xmlns:mx =library://ns.adobe.com/flex/mxwidth =400height =300>

< / s:BorderContainer>

然后将其扩展为一个单独的组件mc.mxml

 <?xml version =1.0encoding =utf-8?> 
< borderContainerX:bc xmlns:fx =http://ns.adobe.com/mxml/2009
xmlns:s =library://ns.adobe.com/flex/spark
xmlns:mx =library://ns.adobe.com/flex/mxxmlns:borderContainerX =borderContainerX。*>

< / borderContainerX:bc>

并获得一个包含2个按钮的组件。



<我已经看到了各种不同的线索,如何这是不可能的( 1 )或变通方法完成这个( 2 3 ),并且一直在想,随着Flex 4的出现,是否有什么改变,或者如果我们仍然坚持这些变通的最后回复在线程3似乎暗示在Flex 4修复这一切?在Flex 4中,您将不得不重写您的mxmlContent属性设置器,以便将您已经定义的子项保留在父类



这个覆盖的一个可能的实现是在这个博客条目的注释中给出的

快速提示(Flex 4):再见模板 - hello mxmlContent
$ b http://www.websector.de/blog/2009/10/02/quick-tip -flex-4-goodbye-templates-hello-mxmlcontent /


What I'd like to do: create an MXML component with some children, then extend it via MXML to create a new component with more children, without losing the original set. In other words

create a component bc.mxml

<?xml version="1.0" encoding="utf-8"?>
<s:BorderContainer xmlns:fx="http://ns.adobe.com/mxml/2009" 
                   xmlns:s="library://ns.adobe.com/flex/spark" 
                   xmlns:mx="library://ns.adobe.com/flex/mx" width="400" height="300">

    <s:Button id="b1" label="button1"/>
</s:BorderContainer>

and then extend it to a separate component mc.mxml

<?xml version="1.0" encoding="utf-8"?>
<borderContainerX:bc xmlns:fx="http://ns.adobe.com/mxml/2009" 
                     xmlns:s="library://ns.adobe.com/flex/spark" 
                     xmlns:mx="library://ns.adobe.com/flex/mx" xmlns:borderContainerX="borderContainerX.*">

    <s:Button id="b2" y="100" label="button2"/>
</borderContainerX:bc>

and get a component with 2 buttons.

I've seen various threads on how this is either not possible (1) or on workarounds to accomplish this (2, 3) and have been wondering if something has changed with the advent of Flex 4 or if we're still stuck with these workarounds the last reply in thread 3 seems to hint at Flex 4 fixing it all?

解决方案

In Flex 4, you will have to override your "mxmlContent" property setter in order to preserve your already defined children in a parent class

One of possible implementations of such a override is presented in the comment for this blog entry

Quick tip (Flex 4): Goodbye templates – hello mxmlContent

http://www.websector.de/blog/2009/10/02/quick-tip-flex-4-goodbye-templates-hello-mxmlcontent/

这篇关于通过MXML扩展MXML自定义组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆