控制光标
使用 Adobe® Flex™ 光标
管理器可以控制 Flex 应用程序中的光标图像。 例如, 如果应用程序执行的处理需要用户等待, 直到处理完成为止, 则可以将光标更改为某个自定义的光标图像, 比如沙漏, 以使它反映该等待期。
您还可以更改光标以向用户提供反馈, 指示用户可以执行的操作。 例如, 您可以使用一个光标图像来指示用户输入被启用, 而使用另一个光标图像来指示输入被禁用。
CursorManager 类控制一个光标优先顺序列表, 在其中具有最高优先级的光标当前是可见的。 如果光标列表包含具有相同优先级的多个光标, 则光标管理器会显示最近创建的光标。
使用默认的忙光标
Flex 定义了一个默认的忙光标, 可用来指示应用程序正在处理, 且在应用程序对用户输入作出响应之前, 用户应等待, 直到处理完成。 默认的忙光标是一个动画时钟。
可以使用以下几种方式来控制忙光标:
可以使用 CursorManager 方法来设置和删除忙光标。
可以使用 SWFLoader、WebService、HttpService 和 RemoteObject 类的 showBusyCursor 属性自动显示忙光标。
下面的示例使用 CursorManager 类的静态 setBusyCursor() 和 removeBusyCursor() 方法, 根据切换按钮的状态显示和隐藏默认的 Flex 忙光标。
示例
<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" viewSourceURL="src/CursorDefaultBusy/index.html" width="400" height="160" > <mx:Script> <![CDATA[ import mx.controls.Button; import mx.managers.CursorManager; import flash.events.*; private const ON_MESSAGE:String = "Busy Cursor ON"; private const OFF_MESSAGE:String = "Busy Cursor OFF"; private function busyCursorButtonHandler(event:MouseEvent):void { var toggleButton:Button = event.target as Button; if (toggleButton.selected) { CursorManager.setBusyCursor(); toggleButton.label = ON_MESSAGE; } else { CursorManager.removeBusyCursor(); toggleButton.label = OFF_MESSAGE; } } ]]> </mx:Script> <mx:Panel paddingBottom="10" paddingTop="10" paddingLeft="10" paddingRight="10" horizontalAlign="center" verticalAlign="middle" title="Default busy cursor" > <!--Toggle button turns default busy cursor on and off. --> <mx:Button label="{OFF_MESSAGE}" toggle="true" click="busyCursorButtonHandler(event);" /> <mx:Text text="Click the button to display or hide the busy cursor."/> </mx:Panel> </mx:Application>