views:

42

answers:

1

Hey,

I got a europe map designed in flash (1 movieclip, 1 frame, really simple), which contains the map as drawing objects directly inside the scene and in addition some specific countries as clickable buttons. So far it's working fine. What I need now is to make all the other drawing objects clickable without having to edit and script each object. I'm thinking about something like this (pseudo code):

foreach(obj in MovieClip) {
    if(obj !typeof(Button)) {
        obj.addEventListener(MouseEvent.MOUSE_DOWN, genericClickListener);
    }
}

I just don't know the syntax how to achieve that. Could anybody give me a hint?

Thanks, Mathias

+1  A: 

Try this:

function genericClickHandler(event:Event):void {
  trace('clicked');
}

// loop through all children
for (var i:int = 0; i < numChildren; i++) {
  var child:Object = getChildAt(i) as Object; 
  // check if display is not a button and check if it has a buttonMode property
  if (!(child is SimpleButton) && child.hasOwnProperty('buttonMode')) {
    child.buttonMode = true;
    child.addEventListener(MouseEvent.CLICK, genericClickHandler, false, 0, true);
  }
}
Shiki
Unfortunately it doesn't select plain drawing objects, but converting all relevant areas into symbols is done in a matter of some minutes. Thanks a lot for the solution :)
Mathias
Your welcome. Good to know it worked for you.
Shiki