Skip to main content
Participant
April 26, 2006
Question

add OnPress function to dynamically-created movieclips

  • April 26, 2006
  • 5 replies
  • 366 views
I am able to dynamically generate movieClips in a loop. However, I wish to enable each of those duplicated movie clips to have an onPress function. Can that be done? If so, how?

relevant code:
button.onPress = function() { // button is clicked, revealing parent movieClip which will contain duplicated child movieClips
parent_mc._visible = true;
for (var i:Number = 0; i < 8; i++) {
var clip:MovieClip = parent_mc.child_mc.duplicateMovieClip("child_mc"+i; i);
clip.loadMovie(image_arr ); // each new movieClip loads a picture referenced in the array
}
};

Can onPress functionality be added to each new clip? I'd like each picture to be clickable so that clicking a picture invokes another function.
This topic has been closed for replies.

5 replies

kglad
Community Expert
Community Expert
April 26, 2006
again, use preloader code or the moviecliploader class so you define your handlers after loading is complete and the target movieclip is (re)instantiated.
Marghoob Sulemaan
Inspiring
April 26, 2006
please clarify. what is your actual requirement. thanx
jcane1Author
Participant
April 26, 2006
To clarify:
The duplicated movieClips each contain an image. I want each image movieClip to be clickable, so that when clicked,
1) the parent_mc is set to be hidden
2) loads the clicked image in another movieClip that is already on the Stage (by passing a variable)

Thanks.
kglad
Community Expert
Community Expert
April 26, 2006
that'd work if jcane wanted to define a button handler for the parent of the new clips.
Marghoob Sulemaan
Inspiring
April 26, 2006
>> clip.loadMovie(image_arr);

after above code please following line.

clip._parent.onPress = function() {
//
trace(this)
}
may be it will work :
jcane1Author
Participant
April 26, 2006
No, I wish the child clips to be clickable. And clip.onPress doesn't work.
I'll try kglad's recommendations.
Thank you.
kglad
Community Expert
Community Expert
April 26, 2006
wait until loading is complete (use preloader code or the onLoadInit() function of the moviecliploader class) and then define your button handlers.