A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: target objects by name?

  1. #1
    Senior Member Big 'Un's Avatar
    Join Date
    Aug 2004

    target objects by name?

    I have a series of movie clips being placed on the stage and I want to assign MouseEvents to all of them.

    Is there any way to refer to them by their names?

    Here is the code that is placing them on the stage and naming them:
    var startPos:int = 10;
    for (var i:int = 0; i<5; i++) {
    	var mybox:box = new box(); //mc linked from Library
    	mybox.name = "box"+i;
    	mcs[i] = "box"+i;
    	mybox.x = startPos;
    	startPos += 100;
    How might I turn each of these into a button?

  2. #2
    Join Date
    Nov 2006
    maybe I'm missing your purpose exactly but it seems the easiest way to make "box" from your library into a button is to make sure that in the Linkage properties it extends "flash.display.SimpleButton" class, which it does by default it it's typed as a button...

    ...if "mcs" is a valid Array, you could say:

    mcs[i].addEventListener(MouseEvent.CLICK, someFunc);
    hope that helps...I think that should work, but I didn't test it...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Click Here to Expand Forum to Full Width

HTML5 Development Center