Link to home
Start Free TrialLog in
Avatar of Aspirin99
Aspirin99

asked on

How do I use setCursor in Flash?

I'm using the list component in Flash (I'm using the Flash MX version in Flash 2004). I want to change the mouse to a selection hand when I mouse over items in my list. I have not been able to get setCursor to work. I want something like:

onClipEvent(enterFrame) {
    this.onRollOver = function() {
  fl.tools.setCursor( 7 );
}  
}
Avatar of Billystyx
Billystyx

_root.useHandCursor=true;

Billystyx
but put the code on the main timeline (or the parent to the mc)


    myList.onRollOver = function() {
 this.useHandCursor=true;
}  

billystyx
click your list component.
press F9 to open action script panel.
then add:

on(itemRollOver){
    fl.tools.setCursor( 7 );
}

/*
you mightn't be able to change the cursor by useHandCursor=true;
hope the fl.tools.setCursor( 7 ) include the drag() method to attach the cursor and hide the original cursor.
*/
you can - I tested it first:)
it's different between itemRollOver and rollOver   o^^O
@ Billystyx: your method sets the use of handCursor on the list component itself (because treats it as a big button, making it quite useless, as you cannot click items)
@ ddlam & Aspirin99: setCursor is a Flash javascript  method, not an Actionscript one, to be used only during authoring time, useless in a public movie

@ Aspirin99: if you want to do it in a public movie (not to be used as an authoring panel), the quickest way to do it without creating a custom cell renderer is to write in the first frame of your movie:

import mx.controls.listclasses.SelectableRow;

SelectableRow.prototype._setValue = SelectableRow.prototype.setValue;
SelectableRow.prototype.setValue = function(itmObj:Object, state:String):Void
{
      this._setValue(itmObj, state);
      this.backGround.useHandCursor = itmObj != undefined;
}
thanks negatyve - i didn't actually test the list control:)
(looks pretty though!)

billystyx
Avatar of Aspirin99

ASKER

Thanks to all for the help, but I'm not getting any of it to work correctly. Here's what happens.

_root.door.song_list.onRollOver = function() {
 this.useHandCursor=true;
}

For the above, I get a hand cursor. I thought this was the solution, but when I use this either on the movie or outside of the movie, none of the items in the list can be selected.

For the following:
on(itemRollOver){
    fl.tools.setCursor( 7 );
}

Or

on(itemRollOver){
this.useHandCursor=true;
}

The above does nothing in my movie.  I've tried placing it on the list component as a solo piece of code and in a clip event everframe and as a function.

As for:

import mx.controls.listclasses.SelectableRow;

SelectableRow.prototype._setValue = SelectableRow.prototype.setValue;
SelectableRow.prototype.setValue = function(itmObj:Object, state:String):Void
{
     this._setValue(itmObj, state);
     this.backGround.useHandCursor = itmObj != undefined;
}

I could not get the above to work. Is that compatible with Flash MX?
>I could not get the above to work. Is that compatible with Flash MX?

ok, the you are using ListBox component (not List as I thought). Use this:

FSelectableItemClass.prototype._displayContent = FSelectableItemClass.prototype.displayContent;
FSelectableItemClass.prototype.displayContent = function(itmObj, selected)
{
      this._displayContent(itmObj, selected);
      this.highlight_mc.useHandCursor = (this.fLabel_mc.labelField.text != "")
}
Do I need to change any of that to match my list component's instance name? For example, what are .highlight_mc and .fLabel_mc?  The path to my list component is: _root.door.song_list.

 I plugged it into the first frame on the timeline that contains the list component, and it had no effect.
ASKER CERTIFIED SOLUTION
Avatar of negatyve
negatyve

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for making the FLA. I moved the code from frame one of the timeline that contained the component to frame one of the _root timeline (like you said from the start), and it worked. I will use this code A LOT. Thanks a million!