A Flash Developer Resource Site

Results 1 to 10 of 10

Thread: replace mouse cursor with image

  1. #1
    Junior Member
    Join Date
    Dec 2011
    Posts
    10

    replace mouse cursor with image

    Hi i have this code which allows me to replace the mouse cursor with an image but i would also like to change the image when the mouse is clicked down using a different image. the code i am using for just replacing the mouse cursor is:

    Mouse.hide();
    stage.addEventListener(MouseEvent.MOUSE_MOVE,follo w);
    function follow(evt:MouseEvent){
    hover1_mc.x = mouseX;
    hover1_mc.y = mouseY;
    }

    i tried using a different code which i found but it failed to work with my project can anyone help me please

  2. #2
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    On a mouse click you load a different image into hover1_mc.
    - The right of the People to create Flash movies shall not be infringed. -

  3. #3
    Junior Member
    Join Date
    Dec 2011
    Posts
    10
    how would i do that sorry if im asking an obvious question

  4. #4
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    Youfirst create a Loader object and add it to the MovieClip.

    var myLoader:Loader = new Loader();
    hover1_mc.addChild(myLoader);

    Then you create a stage eventlistener for the mouse click and load the image into the loader randomly.

    stage.addEventListener (MouseEvent.CLICK,loadImage);
    function loadImage (evt:MouseEvent)
    {
    var myURLs:Array = new Array("img1.jpg","img2.jpg");
    var ranImg:int = Math.random() * 2;
    myLoader.load (new URLRequest(myURLs[ranImg]));
    }
    - The right of the People to create Flash movies shall not be infringed. -

  5. #5
    Junior Member
    Join Date
    Dec 2011
    Posts
    10
    Quote Originally Posted by cancerinform View Post
    Youfirst create a Loader object and add it to the MovieClip.

    var myLoader:Loader = new Loader();
    hover1_mc.addChild(myLoader);

    Then you create a stage eventlistener for the mouse click and load the image into the loader randomly.

    stage.addEventListener (MouseEvent.CLICK,loadImage);
    function loadImage (evt:MouseEvent)
    {
    var myURLs:Array = new Array("img1.jpg","img2.jpg");
    var ranImg:int = Math.random() * 2;
    myLoader.load (new URLRequest(myURLs[ranImg]));
    }
    that didnt work

  6. #6
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    Create a fla and Movieclip in the library. The id of the clip is holder and the class is Holder. Then put this script in the actions of the main timeline. Do not place the Movieclip on stage. Replace the urls with urls of your own images.

    import flash.display.MovieClip;

    var hover1_mc:MovieClip = new Holder();
    addChild (hover1_mc);
    var myLoader:Loader = new Loader();
    hover1_mc.addChild (myLoader);
    myLoader.load(new URLRequest("noimage.jpg"));
    stage.addEventListener (MouseEvent.CLICK,loadImage);
    function loadImage (evt:MouseEvent)
    {
    var myURLs:Array = new Array("kayokitty.png","noimage.jpg");
    var ranImg:int = Math.random() * 2;
    myLoader.load (new URLRequest(myURLs[ranImg]));
    }

    Mouse.hide ();
    stage.addEventListener (MouseEvent.MOUSE_MOVE,follow);
    function follow (evt:MouseEvent)
    {
    hover1_mc.x = mouseX;
    hover1_mc.y = mouseY;
    }
    - The right of the People to create Flash movies shall not be infringed. -

  7. #7
    Junior Member
    Join Date
    Dec 2011
    Posts
    10
    this code makes both images appear at the same time side by side :S

    this is how i have edited the code:

    Actionscript Code:
    import flash.display.MovieClip;

    var hover1_mc:MovieClip = new Holder();
    addChild (hover1_mc);
    var myLoader:Loader = new Loader();
    hover1_mc.addChild (myLoader);
    myLoader.load(new URLRequest("hover.png"));
    stage.addEventListener (MouseEvent.CLICK,loadImage);
    function loadImage (evt:MouseEvent)
    {
    var myURLs:Array = new Array("click.png","hover.png");
    var ranImg:int = Math.random() * 2;
    myLoader.load (new URLRequest(myURLs[ranImg]));
    }

    Mouse.hide ();
    stage.addEventListener (MouseEvent.MOUSE_MOVE,follow);
    function follow (evt:MouseEvent)
    {
    hover1_mc.x = mouseX;
    hover1_mc.y = mouseY;
    }
    Last edited by dt10jja; 02-03-2012 at 01:13 AM.

  8. #8
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    The path to your image is not correct.
    - The right of the People to create Flash movies shall not be infringed. -

  9. #9
    Junior Member
    Join Date
    Dec 2011
    Posts
    10
    i was getting an error saying that before then i made sure both of my images were on mydesktop where the swf and fla files are.

  10. #10
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    Place fla and images into a folder and try again and make sure the location of the swf is in the same place.
    - The right of the People to create Flash movies shall not be infringed. -

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center