将自定义样式属性添加到 MXML 自定义组件
我有一个自定义组件,它有几个画布,并为其分配了一些背景颜色。现在我已经对颜色进行了硬编码,我想将它们移动到外部 css 文件。
所以我想要这样的 css 声明:
ControlBar
{
dividerRightColor: #ffffff;
dividerLeftColor: #f3f3f3;
}
我的问题是我是否可以定义像 dividerRightColor
这样的自定义样式名称,如果可以,我如何在我的 MXML 组件中使用该值?我见过在 Pure AS 组件中使用它们的示例。
I have a Custom Component that has a couple of Canvas with some background colors assigned to them. Now i have hard coded the colors, i want to move them to an external css file.
So i would like to have the css declaration like this :
ControlBar
{
dividerRightColor: #ffffff;
dividerLeftColor: #f3f3f3;
}
My question is if i can define custom style names like dividerRightColor
and if so, how can i use that value inside my MXML Component? I have seen examples of using them inside Pure AS components.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 CSS 中:
在 MXML 中:
In CSS:
In MXML:
在我看来,您需要在组件中创建样式;不仅仅是将样式值作为其他答案发送到组件中。
阅读此文档。
基本上,样式的定义方式与属性的定义方式不同。您可以在所需的组件上设置任何样式名称。然而,组件需要知道如何使用样式。为此,您需要重写 styleChanged 方法:
常见的方法是设置“styleChanged”属性并使显示列表无效,然后在 updateDisplayList() 方法中进行适当的样式更改。
要使样式在代码提示中可用,您需要添加元数据,如下所示:
仅当您希望将样式设置为 MXML 中的属性时才需要这样做。
It sounds to me like you need to create the style in the component; not just send the style values into the component as the other answer.
Read this documentation.
Basically, styles don't get defined the same way that properties get defined. You can set any style name on the component you want. However, the component needs to know what to do w/ the style. To do that you need to override the styleChanged method:
A common approach is to set "styleChanged" properties and invalidate the display list and then make the appropriate style changes in the updateDisplayList() method.
To make the style available in code hinting, you'll need to add metadata, like this:
This will only be required if you wish to set the style as a property in MXML.