Back to Entry Page

Imitating the rollOver event for Movie Clips

Unlike button symbols, Flash 5 movie clips do not respond to the rollOver event. However, by adapting the code needed to localize mouse clicks for movie clips (see my notes about the click problem), you can imitate rollovers for movie clips pretty closely. Here's the necessary handler:

onClipEvent(mouseMove){

//You talking to ME?
  //Assuming registration point is in middle of symbol, 
  //find left, top, right, bottom limits
  myLeft = this._x - (this._width/2);
  myRight = this._x + (this._width/2);
  myTop = this._y-(this._height/2);
  myBottom = this._y +(this._height/2);	

  //Was mouse movement within limits of this clip?
  if(_root._xmouse > myLeft && _root._ymouse > myTop 
  && _root._xmouse < myRight && _root._ymouse < myBottom )
    {
      //response goes here;
    }
  else
    {
      //un-do the response action if necesary;
    }
}

The demonstration below shows this script in action. Try clicking in each of the objects below (both movie clips) as well as mousing over them.

The source file for this demo, rollOverClips.fla, can be found on Crow in multimediaShare/clickProblem/.


University of Baltimore Logo

Copyright © 2002 School of Information Arts and Technologies