PDA

View Full Version : Using the hand cursor


10basetom
01-06-2007, 10:12 AM
Hi guys,

I'm trying to change the default cursor (pointer) to the hand cursor in the following two cases, without much luck:

1. Change cursor to hand when hovering over a ComboBox. I followed an Adobe tech article that instructed to add these properties to the component:

useHandCursor="true" buttonMode="true" mouseChildren="false"

This changes the cursor to the hand all right, but the problem is you are no longer able to select from the ComboBox :(.

2. Change cursor to a hand when hovering over a chart data point. The only thing I can think of is to change the cursor using the dataTipFunction, but I haven't figured how to do that. I would like to use the system hand cursor instead of creating a custom cursor.

TIA,
Tom

Tink
01-06-2007, 03:34 PM
buttonMode turns the whole ComboBox into a Button and you can't have Buttons within Buttons.

If you listen for a MouseEvent.MOUSE_OVER on either area and then change the cursor using the CursorManager (not sure u can actually target the hand cursor so you may have to make a copy of it and change the cursor to that).

10basetom
01-08-2007, 05:44 AM
buttonMode turns the whole ComboBox into a Button and you can't have Buttons within Buttons.

If you listen for a MouseEvent.MOUSE_OVER on either area and then change the cursor using the CursorManager (not sure u can actually target the hand cursor so you may have to make a copy of it and change the cursor to that).

Hi Tink,

Thanks for the input. I managed to get the hand cursor using the CursorManager with the mouse over event. Two things of note:

1. I had to save the hand cursor to a bitmap and create a custom cursor

2. I have three custom components that I'd like to use the hand cursor with. Right now I'm manually creating the cursor in each component with this code:


import mx.managers.CursorManager;

private var cursorID:int = 0;

[Embed(source="hand.gif")]
private var handCursor:Class;


It seems inefficient to have to manually define the custom cursor three times -- is there a way to create the cursor once and share it with all the components? I tried creating the cursor in a separate package with this code:


package
{
public class CustomCursors
{
public var cursorID:int = 0;

[Embed(source="hand.gif")]
public var handCursor:Class;

}
}


And accessing the hand cursor from my components with this code (inside the component tag):


itemRollOver="CustomCursors.cursorID=CursorManager.setCursor(Cus tomCursors.handCursor)" itemRollOut="CursorManager.removeCursor(CustomCursors.cursorID)"


However, when I compile I get the errors "Access of undefined property cursorID" and "Access of undefined property handCursor".

Please advise on a way to share a custom cursor between more than one component.

Thanks,
Tom

Tink
01-08-2007, 10:40 AM
How bout u extend CursorManager and embed the image in there, and then add a method to show and remove the cursor such as they have done with the busy cursor.

dr_zeus
01-08-2007, 06:19 PM
Tink's solution is a good idea. The reason you're receiving an error in the code above is because the variable CustomCursors.handCursor is not static.

10basetom
01-09-2007, 04:01 AM
Tink's solution is a good idea. The reason you're receiving an error in the code above is because the variable CustomCursors.handCursor is not static.

thanks tink and dr. zeus. i'm just starting on with flex, so still have a lot to study and learn. i'll research tink's suggestion and go from there.

dr. zeus, small world -- i went to fremont hs!

tom

10basetom
01-09-2007, 10:42 AM
Tink I tried your suggestion and it worked like a charm :). I had to dissect CursorManager.as from the SDK to create my own custom cursors package; here's the code for anyone who might be interested:


package {

import mx.managers.CursorManager;
import mx.managers.CursorManagerPriority;

public class Cursors extends CursorManager {

/**
* @private
*/
private static var handCursorList:Array = [];

public static function setHandCursor():void
{

[Embed(source="hand.gif")]
var handCursorClass:Class;

handCursorList.push(setCursor(handCursorClass, CursorManagerPriority.MEDIUM));

}

public static function removeHandCursor():void
{
if (handCursorList.length>0) removeCursor(int(handCursorList.pop()));
}

}

}


I've just added a custom hand cursor, but you can add as many custom cursors as you want. Here's how to use the package:


(in AS section)
import Cursors

(inside mx tag)
itemRollOver="Cursors.setHandCursor()" itemRollOut="Cursors.removeHandCursor()"


Thanks for your help, guys. This forum rocks!

Tom

SrihariCh
05-28-2009, 07:44 AM
Hi 10basetom,dr_zeus &Tink,
I am new to Flash & ActionScript-3.0. Presently,I am using Flash CS3 version and coding in ActionScript3.0.
My problem also matches to that of 10basetom,but,a small change in my requirement.
My explaination about requiement starts here:
I have created a ComboBox using flash.display.ComboBox class in AS3.0 and also added items into the ComboBox using AS3 code(Not drag & drop in Flash). Now, I need to view handCursor when I place my mousePointer on either ComboBox or on the items/elements of the ComboBox.
I have tried by using the following code which works well in case of CheckBox:

var chkSprite:Sprite=new Sprite();
chkSprite=chk_dispAttachments;
chkSprite.buttonMode=true;
chkSprite.useHandCursor=true;

So, how to do this in case of ComboBox?
I tried with same code for ComboBox instance, but, no added items are seen in Combobox, instead , it looks like a SimpleButton without Label.

Please, I request you people to help me in this context. As you are familiar with this problem, I think you feel free in posting the reply to my post.

I will be waiting for your reply...
Thanks in advance.....

Srihari.Ch

robbob22
06-11-2009, 01:55 PM
Simply extend the combobox and override the commitproperties method

package com.resource.flex.controls
{
import mx.controls.ComboBox;

public class ComboBoxButtonMode extends ComboBox
{
public function ComboBoxButtonMode()
{
super();
}

override protected function commitProperties():void
{
super.commitProperties();
textInput.buttonMode = true;
textInput.useHandCursor = true;
textInput.mouseChildren = false;
}

}
}