开发者

Flex: How to set hand cursor?

I'm trying to set the hand cursor on an HBox. I've tried buttonMode and useHandCursor but have had no luck. Thi开发者_C百科s example displays the busy cursor. Can anyone tell me how to make it display the flashPlayer's hand cursor?

<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" xmlns:components="com.dn2k.components.*"  >

<fx:Script>
    <![CDATA[
        private var cursorID:int;
        //cursorManager

        protected function box_mouseOverHandler(event:MouseEvent):void
        {
            cursorManager.setBusyCursor()
        }
    ]]>
</fx:Script>

<mx:HBox id="box" useHandCursor="true" buttonMode="true" mouseChildren="false" backgroundColor="0xcc0000" mouseOver="box_mouseOverHandler(event)">
    <s:Label text="Hiya sexy..."/>
</mx:HBox>


This code shows it perfectly while mouse is over container:

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:mx="library://ns.adobe.com/flex/mx"
    xmlns:s="library://ns.adobe.com/flex/spark">
    <mx:HBox backgroundColor="0xcc0000" buttonMode="true" id="box" mouseChildren="false" useHandCursor="true">
        <s:Label text="Hiya sexy..." />
    </mx:HBox>
</s:Application>


If you want to set hand cursor in Label you must set mouseChildren=”false” and below is the revised code

<mx:HBox backgroundColor="0xcc0000" buttonMode="true" id="box" useHandCursor="true">
        <s:Label text="Hiya sexy..." buttonMode="true" mouseChildren="false" useHandCursor="true" />
    </mx:HBox>

Hope this works for you.


What Jeff said. Also you can use CursorManager.setCursor(). You'll have to embed a graphic for the cursor though.


You can also use the newer Mouse class which provides a higher frame rate native cursor.

<mx:HBox rollOver="Mouse.cursor = MouseCursor.BUTTON" 
         backgroundColor="0" backgroundAlpha="0"
         rollOut="Mouse.cursor = MouseCursor.AUTO"/>

The background color and background alpha are used to draw out graphics that are used as the hit area. In empty Spark containers there is a mouseEnabledWhereTransparent property that I don't think existed in mx containers. Here is documentation on it:

When true, this property ensures that the entire bounds of the Group respond to mouse events such as click and roll over. This property only goes in to effect if mouse, touch, or flash player gesture events are added to this instance. In addition, it assumes that the calls to addEventListener()/removeEventListener() are not superfluous.

Having said that it seems that this works without setting the mouseEnabledWhereTransparent property:

<s:Group id="testingHitGroup" left="10" top="10" 
         rollOver="cursorObject_rollOver(event)" width="100" height="100"/>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜