代码之家  ›  专栏  ›  技术社区  ›  James McMahon

在flex中扩展MX类时,如何在MXML中引用它?

  •  2
  • James McMahon  · 技术社区  · 16 年前

    意思是,如果我有:

    <mx:Tree>
        <!-- ... -->
    </mx:Tree>
    

    我想通过(在as中)更改控件的一些行为或添加功能:

    class ChristmasTree extends mx.controls.Tree {
        // ...
    }
    

    如何更改MXML以使用我的类?

    the manual it says how to extend components via MXML 但我该如何处理AS?

    2 回复  |  直到 14 年前
        1
  •  7
  •   James McMahon    16 年前

    好吧,那是最好的LazyWeb。当然也在 TFM 实际上非常干净。在AS中,你这样做:

    package myComponents
    {
        // as/myComponents/TextAreaFontControl.as    
        import mx.controls.TextArea;
    
        public class TextAreaFontControl extends TextArea 
        {
    
            // add / change behaviour, properties etc. ...
    
        }
    
    }
    

    然后在MXML中,您需要:

    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" 
       xmlns:MyComp="myComponents.*">
    
    <!-- ... -->
    
    <MyComp:TextAreaFontControl />
    

    酷。

        2
  •  1
  •   Grauzone    14 年前

    我觉得其实不一样…

    第二个示例u只导入了主应用程序中的自定义文本区域组件,该组件已在textAreaFontControl MXML文件中扩展。textAreaFontControl是一个组件,您的案例如下:

    <?xml version="1.0" encoding="utf-8"?>
    <mx:TextArea xmlns:mx="http://www.adobe.com/2006/mxml">
        <!-- her comes the Script block and other suff -->
    </mx:TextArea>
    

    u通过从现有组件创建组件来扩展组件 真是一句废话。