Skip navigation
Currently Being Moderated

Mouseover highlight not aligned to shape

Feb 15, 2012 2:33 AM

Hi guys,

 

I'm sure i'm missing something painfully obvious (i hope anyway) but it's driving me mad.

I have 3 buttons (on this example), each has a mouseover so the button will highlight once the mouse enters the shape. This all works, however the mouseover area seems to be aligned half OFF of the shape.

EG the shape will highlight when hovering off of the shape on one side, and from half way accross the shape on the other.

 

Here are some grabs and the general code i have.

 

 

Hover Help 1.jpgHover Help 2.jpg

for(var x = 1; x < 4; x++)

{

 

 

                var currentBut = eval("but"+x);

 

 

                currentBut.onMouseMove = function(){

 

 

                                 if(this._xmouse > 0 && this._xmouse < this._width && this._ymouse > 0 && this._ymouse < this._height){

 

 

                                                this.gotoAndStop(2);

                                }

 

                                else

                                {

 

                                                this.gotoAndStop(1);

                                }

                };

}

 

 

 

[edit] - CS4 - Action Script 2

 

Thanks guys!

 
Replies
  • kglad
    72,212 posts
    Jul 21, 2002
    Currently Being Moderated
    Feb 15, 2012 7:47 AM   in reply to andersonOllie

    check your button's hit frame.  its contents are mis-aligned.

     
    |
    Mark as:
  • kglad
    72,212 posts
    Jul 21, 2002
    Currently Being Moderated
    Feb 16, 2012 6:26 AM   in reply to andersonOllie

    i re-read your message and it looks like you're using movieclip buttons and you're using code that would only work correctly if you movieclip graphics were aligned at the upper left of the movieclip's center-stage (that plus-sign on the movieclip's timeline).  your movieclip graphics are off-center.

     

    you could remedy by re-aligning your graphics or using the following code:

     

    for(var x = 1; x < 4; x++)

    {

                    var currentBut = eval("but"+x);

                    currentBut.onMouseMove = function(){

                                     if(this.hitTest(_xmouse,_ymouse)){

                                                    this.gotoAndStop(2);

                                    }

                                    else

                                    {

                                                    this.gotoAndStop(1);

                                    }

                    };

    }

     
    |
    Mark as:
  • kglad
    72,212 posts
    Jul 21, 2002
    Currently Being Moderated
    Feb 17, 2012 6:56 AM   in reply to andersonOllie

    you must be using a bitmap for your movieclip button and that bitmap must not have a transparent background.  to remedy, use a bitmap with a transparent background or convert your bitmap to a vector (modify/bitmap/trace bitmap).

     
    |
    Mark as:
  • kglad
    72,212 posts
    Jul 21, 2002
    Currently Being Moderated
    Feb 20, 2012 7:46 AM   in reply to andersonOllie

    in flash, create one diamond shape, that matches your movieclips' shape, using an alpha=0.  right click the shape, click convert to object, assign it a name (eg, mc), select movieclip and click ok.  that transparent movieclip will be in your library.

     

    drag that transparent movieclip from the library to your stage and place it over your first movieclip and assign it a name (in the properties panel), mc1.  likewise for the next two transparent movieclips (naming them mc2 and mc3) being placed over your 2nd and 3rd movieclips.

     

    you can then remove your previous code and use:

     

    var tl:MovieClip=this;

     

    for(var i = 1; i < 4; i++){

    tl["mc"+i].ivar=i;

     

    tl["mc"+i].onRollOver=function(){

    tl["but"+this.ivar].gotoAndStop(2):

    }

    tl["mc"+i].onRollOut=function(){

    tl["but"+this.ivar].gotoAndStop(1):

    }

     

    }

     
    |
    Mark as:
  • kglad
    72,212 posts
    Jul 21, 2002
    Currently Being Moderated
    Feb 21, 2012 7:17 AM   in reply to andersonOllie

    replace the two  full colons ( : ) with semi-colons ( ; )

     

    and no, you don't need to add a hover state the the transparent buttons.  you're still using the hover frame of your movieclips.

     
    |
    Mark as:
  • kglad
    72,212 posts
    Jul 21, 2002
    Currently Being Moderated
    Feb 22, 2012 6:56 AM   in reply to andersonOllie

    you're welcome.

     
    |
    Mark as:
  • kglad
    72,212 posts
    Jul 21, 2002
    Currently Being Moderated
    Feb 27, 2012 6:31 AM   in reply to andersonOllie

    copy and paste your message into a new topic.

     
    |
    Mark as:
  • kglad
    72,212 posts
    Jul 21, 2002
    Currently Being Moderated
    Mar 1, 2012 7:01 AM   in reply to andersonOllie

    neds already answering that thread and it's generally rude for someone else to jump into that conversation.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points