将属性传递给 Flash Builder 4 中的自定义组件

发布于 2024-09-18 18:33:29 字数 1046 浏览 5 评论 0原文

我试图将一些属性传递给我在 Flash Builder 4 中创建的组件。在下面的示例中,我想传递“label”属性来更新 Button 的 label 属性。

任何帮助将不胜感激。提前致谢。

// MyApp.mxml
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication 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:local="*">
    <fx:Script>
        <![CDATA[
            protected function buttonText():void
            {
                myButton.label = 'Clicked!';
            }
        ]]>
    </fx:Script>
<local:MyComp id="myButton" label="My Button" click="buttonText()"/>
</s:WindowedApplication>

// MyComp.mxml
<?xml version="1.0" encoding="utf-8"?>
<s:Group 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/>
</s:Group>

I'm trying to pass some properties to a component I've created in Flash Builder 4. In my example below I want to pass the "label" property to update the label property of the Button.

Any help would be greatly appreciated. Thanks in advance.

// MyApp.mxml
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication 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:local="*">
    <fx:Script>
        <![CDATA[
            protected function buttonText():void
            {
                myButton.label = 'Clicked!';
            }
        ]]>
    </fx:Script>
<local:MyComp id="myButton" label="My Button" click="buttonText()"/>
</s:WindowedApplication>

// MyComp.mxml
<?xml version="1.0" encoding="utf-8"?>
<s:Group 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/>
</s:Group>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

终难遇 2024-09-25 18:33:29
<fx:Script>
    <![CDATA[
        private var _label:String;

        public function get label() : String {
          return _label;
        }
        public function set label(value:String) : void {
          _label = value;
          myButton.label = value;
        }

        protected function buttonText():void
        {
            myButton.label = 'Clicked!';
        }
    ]]>
</fx:Script>

这将在控件的 label 属性和 myButton.label 的 label 属性之间创建默认绑定。您还可以在 label 属性的 getter 上使用 [Bindable] 元标记。

无论哪种方式,您只需设置组件的 label 属性,并且 myButton 标签的值将反映新值。

<fx:Script>
    <![CDATA[
        private var _label:String;

        public function get label() : String {
          return _label;
        }
        public function set label(value:String) : void {
          _label = value;
          myButton.label = value;
        }

        protected function buttonText():void
        {
            myButton.label = 'Clicked!';
        }
    ]]>
</fx:Script>

This creates a default bind between the label property of your control and the label property of the myButton.label. You could also use the [Bindable] metatag on the getter of the label property.

Either way, you would just set the label property of your component and the value of the myButton label would reflect the new value.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文