无法将 css 样式应用于 flex 中的警报
Unable to apply css style to Alert in flex
我正在尝试使用 flex 4.6 中的 CSS 为 mx.controls.Alert
组件添加外观,但该样式不适用于警报。我之前已经成功实现了这个但是这次我无法隔离问题。
这是我的代码:
<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas 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="400">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Style>
@namespace flexlib "http://code.google.com/p/flexlib/";
@namespace s "library://ns.adobe.com/flex/spark";
@namespace mx "library://ns.adobe.com/flex/mx";
@namespace components "components.*";
@namespace flexgif "org.gif.flexgif.*";
mx|Alert{
background-color:#FFFFFF;
background-alpha:1;
color:#FFFFFF;
border-color:#223f56;
border-style:solid;
border-thickness:1;
button-style-name:"alertButton";
chromeColor:#223f56;
header-height:30;
drop-shadow-enabled: true;
messageStyleName:"messageStyle";
titleStyleName:"titleStyle";
}
.alertButton{
emphasizedSkin: ClassReference('skins.CustomButtonSkin');
skin: ClassReference('skins.CustomButtonSkin');
buttonHeight: 30;
color: #FFFFFF;
verticalAlign: middle;
horizontalAlign:center;
paddingBottom: 4;
textRollOverColor: #FFFFFF;
fontFamily:MavenPro_R;
/* drop-shadow-enabled:false;
theme-color:#40779f;
chromeColor:#40779f;
color:#FFFFFF;
backgroundColor:#40779f;
verticalAlign:middle;
horizontalAlign:center;
buttonHeight:30;
paddingBottom:5px; */
}
.messageStyle{
fontFamily:MavenPro_R;
font-size :12;
color:#595959;
}
.titleStyle{
backgroundColor:#223f56;
font-size :14;
font-weight:bold;
color:#FFFFFF;
}
mx|Alert, mx|Button {
fontFamily:MavenPro_B;
textFieldClass: ClassReference("mx.core.UIFTETextField");
}
</fx:Style>
<fx:Script>
<![CDATA[
import mx.controls.Alert;
public function showAlert(event:MouseEvent):void{
Alert.show("Hi, I'm a test alert");
}
]]>
</fx:Script>
<mx:Button id="testButton" click="showAlert(event)" label="Alert" x="200" y="200"/>
</mx:Canvas>
这是我在主应用程序中使用的组件。
它在 mx:Alert 处发出警告 "CSS type selectors are not supported in components: 'mx.controls.Alert'"
我也试过以下link:
Flex Alert.styleName not working for me
但是报错:
1067: Implicit coercion of a value of type mx.styles:CSSStyleDeclaration to an unrelated type mx.controls:Alert
行:
alertCSS = StyleManager.getStyleDeclaration("Alert");
非常感谢任何帮助。
请原谅我可能犯的任何错误,因为我是 flex 的新手。
您应该在顶级应用程序中定义您的样式,它是包含 s:Application 标记的文件。
只需将 fx:style 块移动到顶级应用程序即可。
我正在尝试使用 flex 4.6 中的 CSS 为 mx.controls.Alert
组件添加外观,但该样式不适用于警报。我之前已经成功实现了这个但是这次我无法隔离问题。
这是我的代码:
<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas 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="400">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Style>
@namespace flexlib "http://code.google.com/p/flexlib/";
@namespace s "library://ns.adobe.com/flex/spark";
@namespace mx "library://ns.adobe.com/flex/mx";
@namespace components "components.*";
@namespace flexgif "org.gif.flexgif.*";
mx|Alert{
background-color:#FFFFFF;
background-alpha:1;
color:#FFFFFF;
border-color:#223f56;
border-style:solid;
border-thickness:1;
button-style-name:"alertButton";
chromeColor:#223f56;
header-height:30;
drop-shadow-enabled: true;
messageStyleName:"messageStyle";
titleStyleName:"titleStyle";
}
.alertButton{
emphasizedSkin: ClassReference('skins.CustomButtonSkin');
skin: ClassReference('skins.CustomButtonSkin');
buttonHeight: 30;
color: #FFFFFF;
verticalAlign: middle;
horizontalAlign:center;
paddingBottom: 4;
textRollOverColor: #FFFFFF;
fontFamily:MavenPro_R;
/* drop-shadow-enabled:false;
theme-color:#40779f;
chromeColor:#40779f;
color:#FFFFFF;
backgroundColor:#40779f;
verticalAlign:middle;
horizontalAlign:center;
buttonHeight:30;
paddingBottom:5px; */
}
.messageStyle{
fontFamily:MavenPro_R;
font-size :12;
color:#595959;
}
.titleStyle{
backgroundColor:#223f56;
font-size :14;
font-weight:bold;
color:#FFFFFF;
}
mx|Alert, mx|Button {
fontFamily:MavenPro_B;
textFieldClass: ClassReference("mx.core.UIFTETextField");
}
</fx:Style>
<fx:Script>
<![CDATA[
import mx.controls.Alert;
public function showAlert(event:MouseEvent):void{
Alert.show("Hi, I'm a test alert");
}
]]>
</fx:Script>
<mx:Button id="testButton" click="showAlert(event)" label="Alert" x="200" y="200"/>
</mx:Canvas>
这是我在主应用程序中使用的组件。 它在 mx:Alert 处发出警告 "CSS type selectors are not supported in components: 'mx.controls.Alert'"
我也试过以下link: Flex Alert.styleName not working for me
但是报错:
1067: Implicit coercion of a value of type mx.styles:CSSStyleDeclaration to an unrelated type mx.controls:Alert
行:
alertCSS = StyleManager.getStyleDeclaration("Alert");
非常感谢任何帮助。 请原谅我可能犯的任何错误,因为我是 flex 的新手。
您应该在顶级应用程序中定义您的样式,它是包含 s:Application 标记的文件。
只需将 fx:style 块移动到顶级应用程序即可。