Flex的Alert消息框中设置icon图标的例子
2009-11-11 13:03
417 查看
前面的Flex中给按钮设置icon图标的例子一文中,我们了解到了如何在按钮控件中嵌入icon图标的一些技巧,接下来我们来研究一下如何在Alert中嵌入icon图标。下面的第一个例子展示了如何直接将icon图标嵌入Alert消息框中,显示在文本的左边,而第二个例子演示了如何将icon图标嵌入到Alert对话框的按钮中。
下面是完整代码:
Download: main.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
verticalAlign="middle"
creationComplete="showAlert();"
backgroundColor="white">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.events.CloseEvent;
// Embed the error.png image.
[Bindable]
[Embed(source='assets/error.png')]
private var Icon:Class;
private var a:Alert;
private function showAlert():void {
var titleText:String = "WARNING";
var messageText:String = "Are you sure you would like to erase the Internet?\n\nPress OK to continue, or Cancel to abort.";
/* Display the Alert, show the OK and Cancel buttons,
and show an icon represented by the Icon binding. */
a = Alert.show(messageText, titleText, Alert.OK | Alert.CANCEL, null, doClose, Icon);
}
private function doClose(evt:CloseEvent):void {
// do nothing.
}
]]>
</mx:Script>
<mx:Button label="Launch Alert" click="showAlert();" />
</mx:Application>
下面第二个例子利用了mx_internal命名空间(namespace)来访问两个内部属性(可以察看代码的文档):
注意:由于这个例子中用到了mx_internal命名空间(namespace),无法保证在后面的Flex SDK中都可以正常工作,使用的时候要自己判断。
Download: main.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
verticalAlign="middle"
creationComplete="showAlert();"
backgroundColor="white" >
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.events.CloseEvent;
[Bindable]
[Embed(source='assets/error.png')]
private var Icon:Class;
[Bindable]
[Embed(source='assets/tick.png')]
private var TickIcon:Class;
[Bindable]
[Embed(source='assets/cross.png')]
private var CrossIcon:Class;
private var a:Alert;
private function showAlert():void {
/* Set button width so it is large enough to accomodate
an icon and default button labels. */
Alert.buttonWidth = 100;
var titleText:String = "WARNING";
var messageText:String = "Are you sure you would like to erase the Internet?\n\nPress OK to continue, or Cancel to abort.";
/* Display the Alert, show the OK and Cancel buttons,
and show an icon represented by the Icon binding. */
a = Alert.show(messageText, titleText, Alert.OK | Alert.CANCEL, null, doClose, Icon);
/* Get a reference to the Alert control's internal
buttons array. */
var buttonArray:Array = a.mx_internal::alertForm.mx_internal::buttons;
/* Set the first button to the TickIcon class, and the
second icon to the CrossIcon class. */
buttonArray[0].setStyle("icon", TickIcon);
buttonArray[1].setStyle("icon", CrossIcon);
progressBar.visible = false;
}
private function doClose(evt:CloseEvent):void {
if (evt.detail == Alert.OK) {
progressBar.visible = true;
} else if (evt.detail == Alert.CANCEL) {
// do nothing.
}
}
]]>
</mx:Script>
<mx:Button label="Launch Alert"
click="showAlert();" />
<mx:ProgressBar id="progressBar"
label="Deleting..."
indeterminate="true"
visible="false" />
</mx:Application>
下面是完整代码:
Download: main.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
verticalAlign="middle"
creationComplete="showAlert();"
backgroundColor="white">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.events.CloseEvent;
// Embed the error.png image.
[Bindable]
[Embed(source='assets/error.png')]
private var Icon:Class;
private var a:Alert;
private function showAlert():void {
var titleText:String = "WARNING";
var messageText:String = "Are you sure you would like to erase the Internet?\n\nPress OK to continue, or Cancel to abort.";
/* Display the Alert, show the OK and Cancel buttons,
and show an icon represented by the Icon binding. */
a = Alert.show(messageText, titleText, Alert.OK | Alert.CANCEL, null, doClose, Icon);
}
private function doClose(evt:CloseEvent):void {
// do nothing.
}
]]>
</mx:Script>
<mx:Button label="Launch Alert" click="showAlert();" />
</mx:Application>
下面第二个例子利用了mx_internal命名空间(namespace)来访问两个内部属性(可以察看代码的文档):
alertForm― Alert中包含文本内容,图标和按钮的内部AlertForm对象
buttons― 一个包含显示在Alert中所有按钮的数组
注意:由于这个例子中用到了mx_internal命名空间(namespace),无法保证在后面的Flex SDK中都可以正常工作,使用的时候要自己判断。
Download: main.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
verticalAlign="middle"
creationComplete="showAlert();"
backgroundColor="white" >
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.events.CloseEvent;
[Bindable]
[Embed(source='assets/error.png')]
private var Icon:Class;
[Bindable]
[Embed(source='assets/tick.png')]
private var TickIcon:Class;
[Bindable]
[Embed(source='assets/cross.png')]
private var CrossIcon:Class;
private var a:Alert;
private function showAlert():void {
/* Set button width so it is large enough to accomodate
an icon and default button labels. */
Alert.buttonWidth = 100;
var titleText:String = "WARNING";
var messageText:String = "Are you sure you would like to erase the Internet?\n\nPress OK to continue, or Cancel to abort.";
/* Display the Alert, show the OK and Cancel buttons,
and show an icon represented by the Icon binding. */
a = Alert.show(messageText, titleText, Alert.OK | Alert.CANCEL, null, doClose, Icon);
/* Get a reference to the Alert control's internal
buttons array. */
var buttonArray:Array = a.mx_internal::alertForm.mx_internal::buttons;
/* Set the first button to the TickIcon class, and the
second icon to the CrossIcon class. */
buttonArray[0].setStyle("icon", TickIcon);
buttonArray[1].setStyle("icon", CrossIcon);
progressBar.visible = false;
}
private function doClose(evt:CloseEvent):void {
if (evt.detail == Alert.OK) {
progressBar.visible = true;
} else if (evt.detail == Alert.CANCEL) {
// do nothing.
}
}
]]>
</mx:Script>
<mx:Button label="Launch Alert"
click="showAlert();" />
<mx:ProgressBar id="progressBar"
label="Deleting..."
indeterminate="true"
visible="false" />
</mx:Application>
相关文章推荐
- Flex中给按钮设置icon图标的例子
- Flex中如何通过getHeaderAt()函数以及selectedUpIcon,selectedOverIcon和selectedDownIcon样式给Accordion头部设置一个分割用图标的例子
- Flex中给按钮设置icon图标的例子
- Flex中如何通过getHeaderAt()函数以及selectedUpIcon,selectedOverIcon和selectedDownIcon样式给Accordion头部设置一个分割用图标的例子
- Flex中通过disabledIconColor样式设置NumericStepper控件图标(icon)无效时的颜色的例子
- Flex中利用stretchCursor样式设置自定义的拉伸光标图标的例子
- Flex中如何通过iconField样式给LinkBar添加Icon图标的例子
- Flex中如何利用titleIcon和iconClass属性,给Alert添加Icon图标
- flex中如何设置Alert背景图片的例子
- Flex中如何利用defaultLeafIcon样式去掉Tree叶子节点图标的例子
- Flex中如何利用iconFunction属性在ComboBox控件的下拉菜单中设定自定义图标的例子
- Flex中如何利用titleIcon属性给Panel容器标题部添加一个ICON图标的例子
- Flex中如何利用folderOpenIcon, folderClosedIcon和defaultLeafIcon样式改变默认文件夹和子项目图标的例子
- 【iOS开发-31】UITabBar背景、icon图标颜色、被选中背景设置以及隐藏UITabBar的两种方式
- Flex中设置面板容器(Panel container)背景透明度的例子
- Flex中如何通过mode属性设置进度条ProgressBar动画状态的例子
- Flex的DateChooser控件中如何通过设置maxYear属性来设定允许的最大年限的例子
- Flex中如何通过设置editable属性创建一个可编辑的DataGrid控件的例子
- Flex的NumericStepper控件中如何通过textAlign样式设置文本对齐方式的例子
- Flex中通过focusAlpha样式设置NumericStepper控件获取光标时透明度的例子