Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamically create varying number of buttons

Status
Not open for further replies.

maguskrool

Technical User
Dec 11, 2006
77
PT
Hi.

The website I'm currently working on has an object gallery. Whenever the user clicks one of the objects, it zooms in and displays a sub-gallery with other images of said object. The images that make up these galleries are loaded into dynamically created empty MovieClips inside a sub-gallery MovieClip. Each object has a varying number of images and they're loaded and unloaded when the zooming in/out of the object ends.

When you click one of the sub-gallery images, the main image should change and display the clicked image. However, I'm having trouble telling the MovieClips containing the sub-gallery images to do anything when they're clicked. See attached code, please.

I'm guessing this has to do with the onRelease being declared inside the onMotionFinished. The thing is I can't thing of a way to declare the onRelease for every sub-gallery image before they're loaded.

Thanks in advance.

Code:
//Variables
var raiz:MovieClip = this;
var mclGalleryLoader:MovieClipLoader = new MovieClipLoader();

//Listener
oListenerYScale.onMotionFinished = function() {
                //Number of images for this object
		for (var i = 0; i<totalImages; i++) {
			raiz.mcGallery.createEmptyMovieClip("mcImg"+i, raiz.mcGallery.getNextHighestDepth());
			raiz.mclGalleryLoader.loadClip("images/"+(i+1)+".jpg", raiz.mcGallery["mcImg"+i]);
			raiz.mcGallery["mcImg"+i].onRelease = function() {
				trace("clicked me");
	}
};
 
Thanks Kenneth. Just to make things clear, why does that happen? I don't understand why the JPEG loading clears the onRelease defined after it.

Let's say that I would create the mcGallery and then create another MovieClip inside it, and loaded the JPEGs into that new MovieClip. If I assigned the onRelease to mcGallery, would it still not work? Thanks.
 
When you load a JPEG into a MovieClip, the JPEG replaces the MovieClip timeline and becomes the MovieClip itself. Any event handler attached to the MovieClip before loading will be lost as there is no longer the original MovieClip.

Your second approach will work. Your "mcImg" inside "mcGallery" will be replaced by a JPEG, but "mcGallery" will remain intact, so will the event handlers attached to "mcGallery".

Kenneth Kawamoto
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top