Thursday, November 3, 2011

Custom Mouse Cursor

Custom Mouse Cursor 


MXMLFile

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2010/02/01/changing-the-mouse-cursor-when-rolling-over-items-in-an-mx-list-control-in-flex/ -->
<mx:Application name="MX_List_itemRollOver_cursor_test"
        xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white" backgroundGradientAlphas="[1.0, 1.0]" backgroundGradientColors="[#C0C0C0, #C5C5C5]">

    <mx:Script>
        <![CDATA[
            import flash.utils.getDefinitionByName;
            import mx.events.ListEvent;

            [Embed("assets/accept.png")]
            public const accept:Class;

            [Embed("assets/anchor.png")]
            public const anchor:Class;

            protected function list_itemRollOverHandler(evt:ListEvent):void {
                var dat:Object = evt.itemRenderer.data;
                trace("Result"+evt.itemRenderer.data);
                if (dat.hasOwnProperty("sample")) {
                    var cursorClass:Class = this[dat.sample] as Class;
                    cursorManager.setCursor(cursorClass);
                }
            }

            protected function list_itemRollOutHandler(evt:ListEvent):void{
                cursorManager.removeAllCursors();
            }
        ]]>
    </mx:Script>
   <mx:Label text="Custom Mouse Cursor" fontSize="18" fontFamily="Arial" fontWeight="bold"/>
    <mx:List id="list"
            itemRollOver="list_itemRollOverHandler(event);"
            itemRollOut="list_itemRollOutHandler(event);" height="292" width="350" fontSize="14" fontFamily="Arial">
        <mx:dataProvider>
            <mx:ArrayCollection>
                <mx:Object label="Wrong cursor" sample="anchor" />
                <mx:Object label="default cursor" />
                <mx:Object label="Wrong cursor" sample="anchor" />
                <mx:Object label="Accept cursor" sample="accept" />
                <mx:Object label="default cursor" />
                <mx:Object label="Accept cursor" sample="accept" />
               
            </mx:ArrayCollection>
        </mx:dataProvider>
    </mx:List>

</mx:Application>

Output:-




1 comment: