Flash Advisor logo
:: Desktop Shortcut
:: Flash Help
Advice from Experts

+ Reply to Thread
Results 1 to 8 of 8
  1. #1

    Default AS3 Button rollout issue

    Hello kind folks, I currently have a crosshair type cursor that follows the mouse over my flash project, however i only require this action over a certain area, so i have so far converted my image of a map into a button and came up with the following code:

    Code:
    map.addEventListener(MouseEvent.ROLL_OVER, manageMouseOver, false, 0, true);
    map.addEventListener(MouseEvent.ROLL_OUT, manageMouseOut, false, 0, true);
     
    function manageMouseOver(event:MouseEvent):void
    {   
        Mouse.hide();
        var lineX:linex = new linex();
        var lineY:liney = new liney();
        addChild(lineX);
        addChild(lineY);
        stage.addEventListener(MouseEvent.MOUSE_MOVE, track);
    
        function track(e:Event):void
        {
             lineX.y = mouseY;
             lineY.x = mou***;
        }
    }
     
    function manageMouseOut(event:MouseEvent):void
    {
         // I have no idea how to do this bit
    }
    The problem I have is that I cant figure out how to make the crosshair cursor invisible on rollout.

    If you wish to see the project swf live you can do so at www.hackingtolearn.com as it's too big to attach. Thanks in advance
    Last edited by Vlykarye; 04-17-2012 at 10:12 PM.

  2. # ADS
    Join Date
    Always
    Posts
    Many
     
  3. #2
    Join Date
    Jun 2009
    Location
    Houston, Tx
    Posts
    581

    Default

    Simple. For every addEventListener you have, you should have a removeEventListener counterpart.
    By following this practice, we can clear up your code a bit, and solve your problem.
    Last edited by Vlykarye; 04-17-2012 at 10:43 PM.

  4. #3
    Join Date
    Jun 2009
    Location
    Houston, Tx
    Posts
    581

    Default

    Sorry. The code I posted was wrong for you. Had to switch over from C++ thinking to AS thinking. Here is the code you want:

    Code:
    map.addEventListener(MouseEvent.ROLL_OVER, manageMouseOver, false, 0, true);
    map.addEventListener(MouseEvent.ROLL_OUT, manageMouseOut, false, 0, true);
    
    var lineX:linex = new linex();
    var lineY:liney = new liney();
    
    function track(e:Event):void
    {
        lineX.x = mou***;
        lineX.y = mouseY;
        lineY.x = mou***;
        lineY.y = mouseY;
    }
    
    function manageMouseOver(event:MouseEvent):void
    {
        Mouse.hide();
        addChild(lineX);
        addChild(lineY);
    
        stage.addEventListener(MouseEvent.MOUSE_MOVE, track);
    }
    
    function manageMouseOut(event:MouseEvent):void
    {
        Mouse.show();
        removeChild(lineX);
        removeChild(lineY);
    
        stage.removeEventListener(MouseEvent.MOUSE_MOVE, track);
    }
    (mou*** = m o u s e X)

    We pulled the lineX and lineY variables out of the functions.
    We added a removeEventListener to the manageMouseOut function.
    We also added Mouse.show() to show the mouse again, and two removeChild() for lineX and lineY.
    This will remove the objects from the stage, but keep their variables alive so that we can simply add them back to the stage when needed.
    Last edited by Vlykarye; 04-17-2012 at 10:48 PM.

  5. #4

    Default

    Hi Vlykarye,

    When I originally tried this my attempts were looking very much like the C++ code you shown earlier. thanks for the help, although I had the following issue:

    The code below would turn the crosshair into strange shapes when implemented
    Code:
    lineX.x = mou***;     
    lineX.y = mouseY;     
    lineY.x = mou***;      
    lineY.y = mouseY;
    I changed the above code to this below:
    Code:
    lineX.y = mouseY;
    lineY.x = mou***;
    that change did technically work, however the crosshair cursor blinks quite
    a bit more than it used to when being moved over the map, I don't suppose you know how to prevent that?

    Thanks again

  6. #5
    Join Date
    Jun 2009
    Location
    Houston, Tx
    Posts
    581

    Default

    If the code doesn't work, then the problem is not with the code, but with how you made the crosshairs.
    I don't know how you made them, all I know is that you are adding two objects to the screen and changing their x and y coordinates.
    You will need to give me more information about how you implemented the crosshairs for me to know what they are doing.

    Fortunately, I still have your fla file from earlier, so I will just go and look at how you made them. If you changed them from before, then let me know.

  7. #6

    Default

    OK thanks, they are the same in the old file that you have

  8. #7
    Join Date
    Jun 2009
    Location
    Houston, Tx
    Posts
    581

    Default

    Hmm. What exactly is the map? I can't find it.

  9. #8
    Join Date
    Jun 2009
    Location
    Houston, Tx
    Posts
    581

    Default

    Can you email me actually? I'll give you my email through private message.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Sponsors
Create Speaking Characters for your website and Flash movies. 15 Day Free Trial