Flex:如何在自定义 as3 组件的 init/构造函数中应用样式(来自外部 CSS)?
我有一个自定义 MXML 组件,我已将其转换为扩展 Canvas 的纯 AS3 组件。我从 MXML 中获取样式,即 alpha、颜色等,并将它们添加到 /src/assets/ 下的 .css 文件中。
我的问题是,如何在自定义 AS3 组件(即构造函数或 init())中应用这些样式?
我读到您仅使用
在 MainApp.mxml 中声明样式源。如果是这样,那么我该如何应用它?
.css 示例如下
/* CSS file */
Canvas.roundedCanvasYellow{
backgroundColor:#ffffcc;
cornerRadius:5;
dropShadowEnabled:true;
dropShadowColor:#2A2929;
borderStyle:solid;
borderThickness:0;
backgroundAlpha:0.9;
}
I had a custom MXML component, that I have converted to a pure AS3 component that extends Canvas. I took the stylings i.e. alpha, color etc. from the MXML and added them to a .css file under /src/assets/.
My question is, how do I apply these styles within the custom AS3 component i.e. constructor or init()?
I read that you declare the style source only in your MainApp.mxml using <mx:Style source="assets/css/swimlaneStyle.css"/>
. If so, then how do I then apply it?
The .css example is below
/* CSS file */
Canvas.roundedCanvasYellow{
backgroundColor:#ffffcc;
cornerRadius:5;
dropShadowEnabled:true;
dropShadowColor:#2A2929;
borderStyle:solid;
borderThickness:0;
backgroundAlpha:0.9;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
应该像这样做一样简单:(
我在示例中使用了
this.
只是为了清楚起见,您通常不会将其包含在实际代码中)。或者,当您以编程方式在组件实例中创建时,请执行
instance.styleName = "roundedCanvasYellow"
操作,或者如果您在 mxml 中创建实例,只需照常设置styleName
属性即可。Should be as straight forward as doing:
(I've used
this.
in my example just to make it clear, you usually wouldn't include that in your real code).Or when you create in instance of your component programmatically do
instance.styleName = "roundedCanvasYellow"
, or if you create an instance in mxml just set thestyleName
attribute as normal.我认为当您使用
this.styleName="roundedCanvasYellow"
而不是this.styleName="Canvas.roundedCanvasYellow"
时,效果很好。I think this works well when you use
this.styleName="roundedCanvasYellow"
instead ofthis.styleName="Canvas.roundedCanvasYellow"
.