How to get html text in a Flex Alert panel.
2010-04-28 11:09
453 查看
A client asked me to do something seemingly simple.
"I want the Alert to have just this one sentence bolded."
Well, it's not exactly simple, so here's how you do it:
there are two solutions as below :
import mx.core.IUITextField;
use namespace mx.core.mx_internal;
message +="Press Yes to continue or No to cancel";
}
if(message.length>0){
Alert.yesLabel="Yes"
var alert:Alert=Alert.show(message,"Alert",3,null,alertHandlerForSO);
// alert.mx_internal::alertForm.mx_internal::textField.htmlText = message;
IUITextField(alert.alertForm.textField).htmlText = message;
}
=========================
更多 Flex 4 示例,请到 http://www.slsay.com
Alert 控件是 Halo 控件中的一种。
所有的 Flex 组件都能够调用 Alert 类的静态方法 show ( ) ,来打开一个带有消息、标题、按钮和图表的弹出式对话框。
当点击了一个按钮时, Alert 控件将被关闭。
Alert.show ( ) 方法的语法如下:
public static show (
text:String,
title:String=null,
flags:uint=mx.controls.Alert.OK,
parent:Sprite=null,
clickListener:Function=null,
iconClass:Class=null,
defaultButton:uint=mx.controls.Alert.OK
):Alert
返回一个 Alert 控件对象。
下表描述了 show ( ) 方法的参数:
要使用 Alert 控件,需要引入 Alert 类,然后调用 show ( ) 方法,如下所示:
此例中,当选择按钮就控件是,将复制 TextInput 控件中的文本至 TextArea 控件,并且显示 Alert 控件。
也可以定义 Button 控件的事件侦听器,如下所示:
主题:在 show ( ) 方法创建对话框之后, Flex 仍在处理你的应用程序,而不是等待用户关闭对话框。
设置 Alert 控件的大小
Alert 控件将自行设置其大小以适应其文本、按钮和图标。可以使用 show ( ) 方法返回的 Alert 对象指定 Alert 控件的大小,如下所示:
此例中通过设置 height 和width 属性来指定 Alert 对象的大小。
在 Alert 控件上使用时间侦听器
下面的例子为 Alert 控件的弹出式对话框添加了事件侦听器。事件侦听器在用户选择 Alert 控件中的按钮时执行处理过程。传递给事件侦听器的事件对象是 CloseEvent。
下面的例子中,只是在用户选择了OK 按钮时执行文本的复制。
此例中,为 Alert 控件定义了一个事件侦听器。不用设置事件侦听器体,可以通过检查事件对象的 detail 属性来判定哪个按钮被按下。如果用户按了 OK 按钮就,则执行文本复制。如果用户按其他任何的按钮,或者按了 Esc 见,则不复制文本。
指定 Alert 控件的图标
可以在 Alert 控件中包含一个图标,显示在提示文本的左边。
"I want the Alert to have just this one sentence bolded."
Well, it's not exactly simple, so here's how you do it:
there are two solutions as below :
import mx.core.IUITextField;
use namespace mx.core.mx_internal;
message +="Press Yes to continue or No to cancel";
}
if(message.length>0){
Alert.yesLabel="Yes"
var alert:Alert=Alert.show(message,"Alert",3,null,alertHandlerForSO);
// alert.mx_internal::alertForm.mx_internal::textField.htmlText = message;
IUITextField(alert.alertForm.textField).htmlText = message;
}
=========================
更多 Flex 4 示例,请到 http://www.slsay.com
Alert 控件是 Halo 控件中的一种。
所有的 Flex 组件都能够调用 Alert 类的静态方法 show ( ) ,来打开一个带有消息、标题、按钮和图表的弹出式对话框。
当点击了一个按钮时, Alert 控件将被关闭。
Alert.show ( ) 方法的语法如下:
public static show (
text:String,
title:String=null,
flags:uint=mx.controls.Alert.OK,
parent:Sprite=null,
clickListener:Function=null,
iconClass:Class=null,
defaultButton:uint=mx.controls.Alert.OK
):Alert
返回一个 Alert 控件对象。
下表描述了 show ( ) 方法的参数:
参数 | 描述 |
text | 对话框中的消息文本 |
title | 对话框标题栏中的文本 |
flags | 指定对话框按钮按钮 mx.controls.Alert.OK : Ok 按钮 mx.controls.Alert.YES : Yes 按钮 mx.controls.Alert.NO : No 按钮 mx.controls.Alert.CANCEL : Cancel 按钮 |
parent | Alert 控件的父对象 |
clickListener | 指定 click 事件的侦听器 |
iconClass | 指定对话框中消息文本左侧的图标 |
defaultButton | 使用一个标志参数的合法值指定默认按钮。当用户按下回车时,此按钮就被选中,其默认值是 Alert.OK. |
<?xml version="1.0"?> |
<!-- http://www.slsay.com/archives/473 --> |
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"> |
<mx:Script> |
<![CDATA[ |
import mx.controls.Alert; |
]]> |
</mx:Script> |
<mx:TextInput id="myInput" |
width="150" |
text=""/> |
<mx:Button id="myButton" |
label="Copy Text" |
click="myText.text = myInput.text; |
Alert.show('Text Copied!', 'Alert Box', |
mx.controls.Alert.OK);"/> |
<mx:TextInput id="myText"/> |
</mx:Application> |
此例中,当选择按钮就控件是,将复制 TextInput 控件中的文本至 TextArea 控件,并且显示 Alert 控件。
也可以定义 Button 控件的事件侦听器,如下所示:
<?xml version="1.0"?> |
<!-- http://www.slsay.com/archives/473 --> |
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"> |
<mx:Script> |
<![CDATA[ |
import mx.controls.Alert; |
private function alertListener():void |
{ |
myText.text = myInput.text; |
Alert.show("Text Copied!", "Alert Box", Alert.OK); |
} |
]]> |
</mx:Script> |
<mx:TextInput id="myInput" |
width="150" |
text=""/> |
<mx:Button id="myButton" |
label="Copy Text" |
click="alertListener();"/> |
<mx:TextInput id="myText"/> |
</mx:Application> |
主题:在 show ( ) 方法创建对话框之后, Flex 仍在处理你的应用程序,而不是等待用户关闭对话框。
设置 Alert 控件的大小
Alert 控件将自行设置其大小以适应其文本、按钮和图标。可以使用 show ( ) 方法返回的 Alert 对象指定 Alert 控件的大小,如下所示:
<?xml version="1.0"?> |
<!-- http://www.slsay.com/archives/473 --> |
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"> |
<mx:Script> |
<![CDATA[ |
import mx.controls.Alert; |
// Define variable to hold the Alert object. |
public var myAlert:Alert; |
private function openAlert():void |
{ |
myAlert = Alert.show("Copy Text?", "Alert", |
Alert.OK | Alert.CANCEL); |
// Set the height and width of the Alert control. |
myAlert.height=150; |
myAlert.width=150; |
} |
]]> |
</mx:Script> |
<mx:TextInput id="myInput" |
width="150" |
text=""/> |
<mx:Button id="myButton" |
label="Copy Text" |
click="openAlert();"/> |
<mx:TextInput id="myText"/> |
</mx:Application> |
此例中通过设置 height 和width 属性来指定 Alert 对象的大小。
在 Alert 控件上使用时间侦听器
下面的例子为 Alert 控件的弹出式对话框添加了事件侦听器。事件侦听器在用户选择 Alert 控件中的按钮时执行处理过程。传递给事件侦听器的事件对象是 CloseEvent。
下面的例子中,只是在用户选择了OK 按钮时执行文本的复制。
<?xml version="1.0"?> |
<!-- http://www.slsay.com/archives/473 --> |
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"> |
<mx:Script> |
<![CDATA[ |
import mx.controls.Alert; |
import mx.events.CloseEvent; |
private function alertListener(eventObj:CloseEvent):void |
{ |
// Check to see if the OK button was pressed. |
if (eventObj.detail==Alert.OK) { |
myText.text = myInput.text; |
} |
} |
]]> |
</mx:Script> |
<mx:TextInput id="myInput" |
width="150" |
text="" /> |
<mx:Button id="myButton" |
label="Copy Text" |
click='Alert.show("Copy Text?", "Alert", |
Alert.OK | Alert.CANCEL, this, |
alertListener, null, Alert.OK);'/> |
<mx:TextInput id="myText"/> |
</mx:Application> |
此例中,为 Alert 控件定义了一个事件侦听器。不用设置事件侦听器体,可以通过检查事件对象的 detail 属性来判定哪个按钮被按下。如果用户按了 OK 按钮就,则执行文本复制。如果用户按其他任何的按钮,或者按了 Esc 见,则不复制文本。
指定 Alert 控件的图标
可以在 Alert 控件中包含一个图标,显示在提示文本的左边。
<?xml version="1.0"?> |
<!-- http://www.slsay.com/archives/473 --> |
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"> |
<mx:Script> |
<![CDATA[ |
import mx.controls.Alert; |
import mx.events.CloseEvent; |
[Embed(source="assets/alertIcon.jpg")] |
[Bindable] |
public var iconSymbol:Class; |
private function alertListener(eventObj:CloseEvent):void |
{ |
// Check to see if the OK button was pressed. |
if (eventObj.detail==Alert.OK) { |
myText.text = myInput.text; |
} |
} |
]]> |
</mx:Script> |
<mx:TextInput id="myInput" |
width="150" |
text=""/> |
<mx:Button id="myButton" |
label="Copy Text" |
click='Alert.show("Copy Text?", "Alert", |
Alert.OK | Alert.CANCEL, this, |
alertListener, iconSymbol, Alert.OK );'/> |
<mx:TextInput id="myText"/> |
</mx:Application> |
相关文章推荐
- How to make item view render rich (html) text in Qt
- How to get the password text in a text with password property from another process using C++ - 用C++如何从不同进程获取密码框文本
- Adding links to a Panel container’s status text in Flex
- flex/in the datagrid,how to get the new value of cell in the datagrid after edit
- How to get the nearest parent node given a text node in jQuery?
- JS. How to replace html element with another element/text, represented in string?
- How to get HTML code of a WebElement in Selenium
- How to put a space character before option text in a HTML select element?
- How to get the HTML source of a webpage in Ruby
- how to get url and hostname and url text in one page
- How to get a path to a resource in a Java JAR file
- string - How to get the filename without the extension from a path in Python? - Stack Overflow
- How to embed VideoIO in your Flex/Flash application?
- how to display Error message including Html tag in apex trigger
- How to use GET and POST methods in HTTP from a MIDlet
- prjGetWriteINIFile - How to Read-Write INI file using VB & API - 读取/写入INI文件 - VB6 + API - SourceCode - HackerJLY
- how to get keyboard key with non blocking in terminal
- How to make TWebBrowser get focus in Delphi
- How to use getBodyClass() in magento?
- SQL: How to get a series of dates in sql using connect by