将属性传递给 Flash Builder 4 中的自定义组件
我试图将一些属性传递给我在 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这将在控件的 label 属性和 myButton.label 的 label 属性之间创建默认绑定。您还可以在 label 属性的 getter 上使用 [Bindable] 元标记。
无论哪种方式,您只需设置组件的 label 属性,并且 myButton 标签的值将反映新值。
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.