创建自定义的MXML组件

7
当我在MXML组件中定义自定义属性时,我也想定义该属性的一组可能值,以使Flex Builder在调用代码完成功能时显示它们(自定义属性的可能值)。
有什么好的方法可以实现吗?
2个回答

9

使用具有enumeration属性的[Inspectable]元标记。

[Inspectable]元数据标记定义有关组件属性的信息,您可以在代码提示和Flex Builder的属性检查器区域中公开该信息。

[Inspectable(defaultValue="abc", enumeration="abc,xyz,pqr")]
public var myProp:Boolean;

1

你的自定义组件的Mxml部分,就像我的一样:

 <com:CustomWindow width="100" height="130" frontImageSrc="{rp.currentItem.path}" 
   showText="{rp.currentItem.imgtext}" hideImage="{rp.currentItem.noImage}" 
   buttonMode="true" useHandCursor="true" mouseChildren="true"/>

动作脚本部分是:

//Inspectable metadata tag gives you the option in the flex builder 
//to choose an option from the available selected options
//Put it with the getter of that particular property 

[Inspectable(defaultValue="true", enumeration="true,false")]
public function get showImage():Boolean
{
       return _imgVisible;
}
public function set showImage(str:Boolean):void
{
 _imgVisible = str;
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接