解决<fx:Style>样式设置中报错 必须使用命名空间限定 CSS 选择器“Alert”中的类型“Alert”
2012-10-23 22:25
1116 查看
问题:
使用样式表(css)。如果在mxml中使用<fx:style>标签,即<fx:style>标签必需要mxml文档根元素的直接子元素。在给Alert设置样式时报错:必须使用命名空间限定 CSS 选择器“Alert”中的类型“Alert”。
分析:
常用的css选择器有class选择器和type选择器。使用type选择器时需要使用命名空间,语法如下:@namespace s "library://ns.adobe.com/flex/spark"; s|Button{}。
解决实例:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
<fx:Declarations>
<!-- 将非可视元素(例如服务、值对象)放在此处 -->
</fx:Declarations>
<!-- 设定应用样式 -->
<fx:Style>
@namespace mx "library://ns.adobe.com/flex/mx"; mx|Alert{
fontSize: 18pt;
}
@namespace s "library://ns.adobe.com/flex/spark"; s|Button{
fontSize: 18pt;
}
@namespace s "library://ns.adobe.com/flex/spark"; s|TextInput{
fontSize: 18pt;
}
</fx:Style>
<fx:Script>
<![CDATA[
//导入Alert类和关闭事件类
import mx.controls.Alert;
import mx.events.CloseEvent;
//定义私有函数弹出对话框
private function popAlert():void{
//修改Alert.YES和Alert.NO的显示文本
Alert.yesLabel = "是";
Alert.noLabel = "否";
//弹出对话框设定显示标题为“选择对话框”,提示内容为“请选择'是'或者'否'”,显示Alert.YES和Alert.NO两个按钮
//设定关闭Alert对话框响应的事件,设定缺省按钮为Alert.YES
Alert.show("请选择'是'或者'否'","选择对话框",Alert.YES|Alert.NO,this,clickSelectHandler,null,1);
}
//定义私有函数响应用户对Alert对话框的操作
private function clickSelectHandler(event:CloseEvent):void{
//得到用户点击的按钮
if (event.detail==Alert.YES)
//在TextInput组件当中显示的内容
displaySelect_txt.text="您选择了是";
else
displaySelect_txt.text="您选择了否";
}
]]>
</fx:Script>
<s:Button id="popAlert_btn" y="87" label="弹出对话框" horizontalCenter="0" click="popAlert()"/>
<s:TextInput id="displaySelect_txt" y="144" horizontalCenter="0"/>
</s:Application>
使用样式表(css)。如果在mxml中使用<fx:style>标签,即<fx:style>标签必需要mxml文档根元素的直接子元素。在给Alert设置样式时报错:必须使用命名空间限定 CSS 选择器“Alert”中的类型“Alert”。
分析:
常用的css选择器有class选择器和type选择器。使用type选择器时需要使用命名空间,语法如下:@namespace s "library://ns.adobe.com/flex/spark"; s|Button{}。
解决实例:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
<fx:Declarations>
<!-- 将非可视元素(例如服务、值对象)放在此处 -->
</fx:Declarations>
<!-- 设定应用样式 -->
<fx:Style>
@namespace mx "library://ns.adobe.com/flex/mx"; mx|Alert{
fontSize: 18pt;
}
@namespace s "library://ns.adobe.com/flex/spark"; s|Button{
fontSize: 18pt;
}
@namespace s "library://ns.adobe.com/flex/spark"; s|TextInput{
fontSize: 18pt;
}
</fx:Style>
<fx:Script>
<![CDATA[
//导入Alert类和关闭事件类
import mx.controls.Alert;
import mx.events.CloseEvent;
//定义私有函数弹出对话框
private function popAlert():void{
//修改Alert.YES和Alert.NO的显示文本
Alert.yesLabel = "是";
Alert.noLabel = "否";
//弹出对话框设定显示标题为“选择对话框”,提示内容为“请选择'是'或者'否'”,显示Alert.YES和Alert.NO两个按钮
//设定关闭Alert对话框响应的事件,设定缺省按钮为Alert.YES
Alert.show("请选择'是'或者'否'","选择对话框",Alert.YES|Alert.NO,this,clickSelectHandler,null,1);
}
//定义私有函数响应用户对Alert对话框的操作
private function clickSelectHandler(event:CloseEvent):void{
//得到用户点击的按钮
if (event.detail==Alert.YES)
//在TextInput组件当中显示的内容
displaySelect_txt.text="您选择了是";
else
displaySelect_txt.text="您选择了否";
}
]]>
</fx:Script>
<s:Button id="popAlert_btn" y="87" label="弹出对话框" horizontalCenter="0" click="popAlert()"/>
<s:TextInput id="displaySelect_txt" y="144" horizontalCenter="0"/>
</s:Application>
相关文章推荐
- 【flex中的小问题累积】无法解析 CSS 选择器“ToolTip”中命名空间限定的类型“ToolTip”
- ASP.NET中使用 Response.Write("<script>alert('****');</script>");后CSS界面发生变化的解决方法 (经验证)
- <已解决>使用selector设置Button按下松开的样式以及 <item> tag requires a 'drawable' attribute or child tag defining a drawable 报错
- VS2010 项目引用了DLL文件,也写了Using,但是编译时提示:未能找到类型或命名空间名称 <转>
- CS0246 未能找到类型或命名空间名“List<Vector2>”(是否缺少 using 指令或程序集引用?) RoguelikeProject C:\Users\Fang\Documents\Ro
- 启动tomcat闪退,logs中提示元素类型 "Context" 必须由匹配的结束标记 "</Context>" 终止的解决方法
- 使用<style>标签插入页面样式:
- 使用<span>标签为文字设置单独样式
- 如何使用CSS设置<input>标签的背景小图标 简单
- 简述使用<iostream.h>与<iostream>命名空间std这两种形式有什么区别?
- 使用<span>标签为文字设置单独样式
- 解决MVC使用时Views必须引用完整的命名空间才得到对象的问题
- [转载]CSS<a href>链接样式冲突解决方法!
- Jeecg中使用<t: dgCol>标签的自动构造查询条件时出现类型转换错误的解决办法。
- 使用<span>标签为文字设置单独样式
- 使用css设置的style.width ,alert(div.style.width);打印为空
- Html中<Hr>标签、样式的使用和自定义设置
- 如何使用CSS设置<input>标签的背景小图标 简单
- 如何解决“xxxxxx是“命名空间”,但此处被当做“类型”来使用”的问题
- springboot 使用thymeleaf 模板引擎时报错org.xml.sax.SAXParseException: 元素类型 "link" 必须由匹配的结束标记 "</link>" 终止