A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: Quick Rollover Question

  1. #1
    Junior Member
    Join Date
    Jun 2009
    Posts
    5

    Quick Rollover Question (Resolved)

    First post. I welcome the hazing.

    It appears that on MOUSE_OVER, if you MOUSE_OUT before the clip is finished, it won't see the MOUSE_OUT and the clip remains in the Out frame. What can I do to fix this?

    Code is AS3.

    Code:
    Btn1_hit.addEventListener(MouseEvent.MOUSE_OVER,Button1Over);
    Btn1_hit.addEventListener(MouseEvent.MOUSE_OUT,Button1Out);
    Btn1_hit.addEventListener(MouseEvent.MOUSE_DOWN, Button1Click);
    Btn1_hit.addEventListener(MouseEvent.MOUSE_UP,Button1Up);
    
    function Button1Over(e:MouseEvent):void
    {
    		btn1.gotoAndPlay("1Over")
    }
    
    function Button1Out(e:MouseEvent):void
    {
    		btn1.gotoAndPlay("1Up");
    }
    
    function Button1Click(e:MouseEvent):void
    {
    		btn1.gotoAndPlay("1Click")
    }
    
    function Button1Up(e:MouseEvent):void
    {
    		btn1.gotoAndStop("1Up")
    }
    Last edited by PeterPun; 07-01-2009 at 11:03 PM.

  2. #2
    ReMember gobbles's Avatar
    Join Date
    Nov 2002
    Location
    Denmark
    Posts
    983
    try using MOUSE_LEAVE
    http://www.rickigregersen.com ...finally a blog!

    Your damned if you do...but your particually damned if you don´t

  3. #3
    Junior Member
    Join Date
    Jun 2009
    Posts
    5
    No Dice. I got:
    1119: Access of possibly undefined property MOUSE_LEAVE through a reference with static type Class.

  4. #4
    ReMember gobbles's Avatar
    Join Date
    Nov 2002
    Location
    Denmark
    Posts
    983
    Ahh that is AIR specific for the stage I think, sorry

    I just looked at some mouse up/down drag code I did a few months back. I have only a mouse over listener, then when rolling over I remove this and add the mouse out listener, and vice versa. Maybe you get several mouseEvents fired at the same time and something goes missing? When moving the mouse away from the button these events will all fire: MOUSE_OUT, MOUSE_MOVE and ROLL_OUT, maybe even MOUSE_DOWN and MOUSE_UP depending on what the user is doing and what the intention is with the button.

    I'm not a fan of having listeners for things that can not happen in a particular state, like if you are not over a button, the mouse out event can not be fired so no need to have it hanging around.
    http://www.rickigregersen.com ...finally a blog!

    Your damned if you do...but your particually damned if you don´t

  5. #5
    Junior Member
    Join Date
    Jun 2009
    Posts
    5
    Figured it out...

    I removed the stop() that keeps the roll out from continuing into the roll in. Then changed the code:

    //Button 1 Listeners and Functions
    Btn1_hit.addEventListener(MouseEvent.MOUSE_OVER,Bu tton1Over);
    Btn1_hit.addEventListener(MouseEvent.MOUSE_OUT,But ton1Out);
    Btn1_hit.addEventListener(MouseEvent.MOUSE_DOWN,Bu tton1Click);
    Btn1_hit.addEventListener(MouseEvent.MOUSE_UP,Butt on1Up);


    //Mouse Over
    function Button1Over(e:MouseEvent):void
    {
    Btn1.gotoAndPlay("1Over");
    Btn1.addEventListener(Event.ENTER_FRAME,Stop1);

    function Stop1(e:Event):void
    {
    if (Btn1.currentFrameLabel == "1Out")
    {
    Btn1.stop();
    }
    }
    }

    //Mouse Out
    function Button1Out(e:MouseEvent):void
    {
    Btn1.addEventListener(Event.ENTER_FRAME,Play1);

    function Play1(e:Event):void
    {
    if (Btn1.currentFrameLabel == "1Out")
    {
    Btn1.gotoAndPlay("1Out");
    }
    }
    }

    function Button1Click(e:MouseEvent):void
    {
    Btn1.gotoAndStop("1Click");
    }

    function Button1Up(e:MouseEvent):void
    {
    Btn1.gotoAndStop("1Out");
    //link to scene
    }

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