Groups | Blog | Home
all groups > flash actionscript > july 2007 >

flash actionscript : Broadcasting Events with EventDispatcher


MaxManNH
7/6/2007 5:08:21 PM
Greetings all,

I am putting together a game where I have some clickable areas that dispatch
events to some movieclips on my stage. When I add the movie clips onto the
stage and add each clip to the broadcaster object with addEventListener it
works great. However when I add the movieclips to the stage with a for loop the
addEventListener doesn't seem to work. The event is being dispatched but the
movieclips on stage don't seem to be getting them.

The for loop that is adding the clips is inside a function that is being
called every three seconds by a setInterval call.

function addBlockToConveyors()
{
for(var index = 1; index < 4; index++)
{
var nm = "con" + index;
var dn = "block" + blocks.getNextHighestDepth();
var dt = "productDots" + 1;
var clip:MovieClip = blocks.attachMovie(dt, bn, blocks.getNextHighestDepth()
, {_conveyor:nm, _scope:conveyors, _dx:1});

clip._x = conveyors[nm]._x;
clip._y = conveyors[nm]._y - clip._height + 5;

broadcaster.addEventListener("onHopperActivate", clip);
broadcaster.addEventListener("onHopperDeactivate", clip);
}
}
kglad
7/6/2007 5:48:30 PM
MaxManNH
7/6/2007 5:52:38 PM
MaxManNH
7/6/2007 6:08:00 PM
Well I think I found the problem cause it is working now. Apparently the class
that contains the code for the movieclips that are broadcasting did not like
the way I was initializing the broadcaster object. I changed it to be inline
with the attachMovie function and now they are all working fine.
kglad
7/6/2007 6:09:57 PM
AddThis Social Bookmark Button