如何创建带有 3 个标签的自定义 Flex 4 按钮
我想创建一个带有三个标签的自定义按钮组件:左对齐、中对齐和右对齐。我不能只使用标签对齐属性,因为我想同时使用所有 3 个标签。
我熟悉创建自定义组件,但我以前从未尝试过构建这样的组件...
到目前为止,这是我所拥有的:
<?xml version="1.0" encoding="utf-8"?>
<s:Button
xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark">
<fx:Script>
<![CDATA[
private var labelContentL:String;
private var labelContentC:String;
private var labelContentR:String;
public function set labelL(value:String):void
{
labelContentL = value;
}
public function set labelC(value:String):void
{
labelContentC = value;
}
public function set labelR(value:String):void
{
labelContentR = value;
}
public function get labelL():String
{
return labelContentL;
}
public function get labelC():String
{
return labelContentC;
}
public function get labelR():String
{
return labelContentR;
}
]]>
</fx:Script>
<s:Label id="l" width="100%" text="{labelContentL}" textAlign="left" paddingLeft="10" />
<s:Label id="c" width="100%" text="{labelContentC}" textAlign="center" />
<s:Label id="r" width="100%" text="{labelContentR}" textAlign="right" paddingRight="10" />
</s:Button>
创建按钮后标签不会更改,所以我不担心关于缺少的[Bindable]
元数据。
我现在陷入困境,收到以下编译器错误:
“String”类型的默认属性“label”的多个初始值设定项值。
...对于 3
行中的每一行。
基于这个答案 对于类似的问题,我尝试将 label=""
添加到我的
声明中,但这只会增加另一个错误。
我该如何解决这个问题?
I would like to create a custom Button component with three labels: left-, center-, and right-justified. I can't just use the label justification property, because I want to use all 3 labels at the same time.
I'm familiar with creating custom components, but I've never tried to build one quite like this before...
Here's what I have so far:
<?xml version="1.0" encoding="utf-8"?>
<s:Button
xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark">
<fx:Script>
<![CDATA[
private var labelContentL:String;
private var labelContentC:String;
private var labelContentR:String;
public function set labelL(value:String):void
{
labelContentL = value;
}
public function set labelC(value:String):void
{
labelContentC = value;
}
public function set labelR(value:String):void
{
labelContentR = value;
}
public function get labelL():String
{
return labelContentL;
}
public function get labelC():String
{
return labelContentC;
}
public function get labelR():String
{
return labelContentR;
}
]]>
</fx:Script>
<s:Label id="l" width="100%" text="{labelContentL}" textAlign="left" paddingLeft="10" />
<s:Label id="c" width="100%" text="{labelContentC}" textAlign="center" />
<s:Label id="r" width="100%" text="{labelContentR}" textAlign="right" paddingRight="10" />
</s:Button>
The labels won't change after the button is created, so I'm not worried about the missing [Bindable]
metadata.
I'm stuck right now, getting the following compiler error:
Multiple initializer values for default property, 'label', of type 'String'.
...for each of the 3 <s:Label>
lines.
Based on this answer to a similar question, I tried adding label=""
to my <s:Button>
declaration, but that just adds another error.
How do I fix this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的问题是按钮标签下名为 label 的标签不是标签类型的项目,它是按钮上使用的标签,并且是字符串类型。
为什么不将其作为皮肤而不是自定义组件呢?
这将适用于此类:
Your problem is that a tag named label under the button tag isn't an item of type label, it's the label used on the button, and is of type string.
Why not do it as a skin, rather than a custom component?
This will work with this class: