Adobe Flex迷你教程 — CursorManager使用
flex中是通过包mx.managers中CursorManager类控制
1.系统默认忙碌状态光标
MXML语言:
<?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:Script>
<![CDATA[
import mx.managers.CursorManager;
private function setCursor():void
{
CursorManager.removeAllCursors();
}
private function setCursorBusy():void
{
CursorManager.setBusyCursor();
}
private function canCursorBusy():void
{
CursorManager.removeBusyCursor();
}
]]>
</fx:Script>
<s:HGroup>
<s:Button label="忙碌光标" click="setCursorBusy()"/>
<s:Button label="取消忙碌光标" click="canCursorBusy()"/>
<s:Button label="恢复正常光标" click="setCursor()"/>
</s:HGroup>
</s:Application>
<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:Script>
<![CDATA[
import mx.managers.CursorManager;
private function setCursor():void
{
CursorManager.removeAllCursors();
}
private function setCursorBusy():void
{
CursorManager.setBusyCursor();
}
private function canCursorBusy():void
{
CursorManager.removeBusyCursor();
}
]]>
</fx:Script>
<s:HGroup>
<s:Button label="忙碌光标" click="setCursorBusy()"/>
<s:Button label="取消忙碌光标" click="canCursorBusy()"/>
<s:Button label="恢复正常光标" click="setCursor()"/>
</s:HGroup>
</s:Application>
代码说明:
注意下面2个方法:
removeAllCursors () 方法
public static function removeAllCursors():void
删除光标列表中的所有光标并存储系统光标。
removeBusyCursor () 方法
public static function removeBusyCursor():void
从光标列表中删除忙状态光标。如果光标列表中还有其它忙状态光标请求处于活动状态,也就是说您已多次调用 setBusyCursor() 方法,那么,只有从列表中删除了所有忙状态光标后,忙状态光标才会消失。
也就是说在本例题中,要是连续点了2下"忙碌光标"按钮,你得连点2下"取消忙碌光标"按钮才可以把光标的忙碌状态完全取消。光标状态是存放在一个列表中的.
2.使用自定义光标
MXML语言:
<?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:Script>
<![CDATA[
import mx.managers.CursorManager;
[Embed('asset/openhand.png')]
private static const HAND_CURSOR:Class;
private function setCursor():void
{
CursorManager.removeAllCursors();
}
private function setCursorHand():void
{
CursorManager.setCursor(HAND_CURSOR,3);//3,光标优先级
}
]]>
</fx:Script>
<s:HGroup>
<s:Button label="手型光标" click="setCursorHand()"/>
<s:Button label="恢复正常光标" click="setCursor()"/>
</s:HGroup>
</s:Application>
<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:Script>
<![CDATA[
import mx.managers.CursorManager;
[Embed('asset/openhand.png')]
private static const HAND_CURSOR:Class;
private function setCursor():void
{
CursorManager.removeAllCursors();
}
private function setCursorHand():void
{
CursorManager.setCursor(HAND_CURSOR,3);//3,光标优先级
}
]]>
</fx:Script>
<s:HGroup>
<s:Button label="手型光标" click="setCursorHand()"/>
<s:Button label="恢复正常光标" click="setCursor()"/>
</s:HGroup>
</s:Application>