I have written an the following code that dynamically loads a bunch of movies into a Scrollpane. I had a question about the "click-ability" of the movieclips loaded into the scrollpane. Is it possible to attach a variable to the movieclip after it is created, and then reference that variable when the movieclip is clicked? Below is sample code of what I would like to do, but is not working:
Code:
var ScrollPane = _root.skin.Explorer.ScrollPane;
var GalleryMC = ScrollPane.content.createEmptyMovieClip("Gallery"+Gallery.id, 1);
for (var i = 0; i < Gallery.images.length; ++i) {
var Image = new Object();
Image.name = Gallery.images[i].name;
Image.width = Gallery.images[i].width;
Image.height = Gallery.images[i].height;
var ImageMC = GalleryMC.createEmptyMovieClip("Pic"+i, i);
// NOTE THE FOLLOWING LINE:
ImageMC._ImageName = Image.name;
var PicLoader = new MovieClipLoader();
PicLoader.onLoadInit = function (targetMC) {
// NOTE THE FOLLOWING LINE:
targetMC.onRelease = function() { alert(targetMC._ImageName); };
ScrollPane.invalidate();
}
PicLoader.loadClip(Gallery.path+"/"+Image.name.split(".jpg").join("_thumb.jpg"), ImageMC);
}
Although all of the individual movieclips inside of the Scrollpane are click-able, the problem is that ALL of them are sending the Image.name value of the LAST LOADED ImageMC instance to the alert() function when clicked. Any ideas?
Well normaly if you declare a onRelease function while in the {} your in the movie. And since TargetMc is from loadInit it does not exist anymore when you click or refer to the last Image create.
use this to know what's in there put that in the onRelease function
Unfortunately, that didn't work either. I just get "undefined" when any clip is clicked. However, I tried using the built in variable _name (instance name of the movie clip) and it worked - I got the unique instance name of the movieclip that was clicked:
So perhaps it had something to do with my custom variable.
Trionik, I absolutely appreciate your help and advice! I think you answered one of my other posts as well - at this rate I should just put you on our payroll!
After a few test and some head scratching i found out that when you load the clip everything is erase all variables are gone. It's the same if you are trying to put something in the movieClipLoader object. But there is a way to counter that by using a listener. I have built this to make my test and it's working.