Handling button events in Flash 8 by event capturing has some caveats

December 14th, 2006

The situation is as follows:

I have an extenal asset in SWF format with some “onPress” button event handlers specified.

I load this external asset via MovieClipLoader class into the SWF container and all those “onPress” button event handlers became unresponsive because of the SWF container itself has specified event handlers for another! button events – “onRollOver” and “onRollOut“.

Code for embedding external SWF asset follows:

var myMCL = new MovieClipLoader();//create an instance of MovieClipLoader
myMCL.loadClip("externalAsset.swf", "_root.image1_mc");
myMCL.onLoadComplete = function (targetMC) {
          image_mc.onRollOver = function() {
              trace ("onRollOver button handler works great, 
              but my onPress button event handlers are lost");

The article written by Trevor McCauley gave me an good insight to create an solution for this type of the problem, but I do not like the fact by itself that such a problem occurred =)

My solution is to substitute onRollOver event handler with onMouseMove event handler ( which is not a button event):

this.onMouseMove = onCustomMouseMove;
function onCustomMouseMove() {  
 if (bgd_mc.hitTest(_root._xmouse, _root._ymouse, true))  {      
  if (image1_mc._xscale < MAX_SCALE && bgd_mc._width == 215 && 
!myTween1.isPlaying) {      
 } else { 
  if (image1_mc._xscale > MIN_SCALE && bgd_mc._width == MAX_WIDTH && !myTween1.isPlaying) {