• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How to change cursor on roll over function

Contributor ,
Oct 13, 2013 Oct 13, 2013

Copy link to clipboard

Copied

I'm making a point and click game in AS3 with flash.

I've changed the skin of my cursor by creating a new class "Souris". It's working just fine. Now I'm trying to change the skin of the cursor when it's on an object on the scene.

I've read that the MouseEvent.ROLL_OVER is the good method but I can't figure out how to do it...

I've got my Souris class like that :

public class Souris extends MovieClip
   
{
private var engine:Engine;
       
private var stageRef:Stage;
       
private var p:Point = new Point();

       
public function Souris(stageRef:Stage)
       
{
           
Mouse.hide(); //make the mouse disappear
            mouseEnabled
= false; //don't let our cursor block anything
mouseChildren
= false;

           
this.stageRef = stageRef;
            x
= stageRef.mouseX;
            y
= stageRef.mouseY;

            stageRef
.addEventListener(MouseEvent.MOUSE_MOVE, updateMouse, false, 0, true);
            stageRef
.addEventListener(Event.MOUSE_LEAVE, mouseLeaveHandler, false, 0, true);
            stageRef
.addEventListener(Event.ADDED, updateStack, false, 0, true);
            stageRef
.addEventListener(MouseEvent.ROLL_OVER,hover);

       
}

       
private function updateStack(e:Event) : void
       
{
            stageRef
.addChild(this);
       
}
       
private function hover(e:MouseEvent😞void {
souris
.visible = false;
}

       
private function mouseLeaveHandler(e:Event) : void
       
{
            visible
= false;
           
Mouse.show(); //in case of right click
            stageRef
.addEventListener(MouseEvent.MOUSE_MOVE, mouseReturnHandler, false, 0, true);
       
}

       
private function mouseReturnHandler(e:Event) : void
       
{
            visible
= true;
           
Mouse.hide(); //in case of right click
            removeEventListener
(MouseEvent.MOUSE_MOVE, mouseReturnHandler);
       
}

       
private function updateMouse(e:MouseEvent) : void
       
{
            x
= stageRef.mouseX;
            y
= stageRef.mouseY;

            e
.updateAfterEvent();
       
}

   
}

}
}

In my main class (Engine class) I've got :


private var souris:Souris;

public function Engine(){



                        souris
= new Souris(stage);
            stage
.addChild(souris);

       
}
private function startGame(e:Event😞void{
....
..

I've tried to put in the "Souris" class


stageRef.addEventListener(MouseEvent.ROLL_OVER,hover);

private function hover(e:MouseEvent😞void {
Engine.souris.visible = false;
handCursor
.visible = true ;
}

But It seems wrong... I don't know what to put in my hover function.. (I've got the "handCursor" in my library).

Thank you very much for your help !

TOPICS
ActionScript

Views

1.1K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Contributor , Oct 14, 2013 Oct 14, 2013

Thx for your answers, I've found a solution to my problem. It was MouseEvent.MOUSE_OVER. and not roll over. But thanks for the links, I've read it and it helps me with some codes.

Thanks for your time !

Votes

Translate

Translate
LEGEND ,
Oct 13, 2013 Oct 13, 2013

Copy link to clipboard

Copied

If you want to have rolling over objects trigger something to occur relative to the souris object, then you need to assign the ROLL_OVER and ROLL_OUT event listeners to the objects that get rolled over.  You can have the event handler functions for those call upon the souris object to execute whatever function it executes for the cursor change you want to have happen.

main_obj.addEventListener(MouseEvent.ROLL_OVER, changeCursor);

function changeCursor(evt:MouseEvent):void {

         souris.showRolloverCursor();

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Oct 14, 2013 Oct 14, 2013

Copy link to clipboard

Copied

Don`t bother with writing your own cursor from the ground up, you are in for trouble, especially when you make a game with dynamicly created objects ( for example:I see no sorting algorithm that gurantees that your custom cursor stays in front of all other objects at all times).

Use sth like this: http://asgamer.com/2009/an-even-better-as3-oop-flash-custom-cursor

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Oct 14, 2013 Oct 14, 2013

Copy link to clipboard

Copied

LATEST

Thx for your answers, I've found a solution to my problem. It was MouseEvent.MOUSE_OVER. and not roll over. But thanks for the links, I've read it and it helps me with some codes.

Thanks for your time !

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines