PDA

View Full Version : Event Handler Problem on Nested MC


bluetrane
12-14-2004, 06:40 PM
I'm using the following code to dynamcially create movieclips inside another movieclip called "picStrip" from an array of JPGs:

for (var i = 0; i<imageArray.length; i++) {
var thisImage:String = "image"+i;
picStrip.createEmptyMovieClip(thisImage, picStrip.getNextHighestDepth());
eval("picStrip."+thisImage).loadMovie(imageArray[i]);
eval("picStrip."+thisImage)._x = (101*i);
eval("picStrip."+thisImage)._y = 0;
}

For some reason, I am unable to access the event handler functionality of the dynamically generated MCs:

_root.picStrip.image1.onRelease = function() {
trace("Did this work?");
}

I know my MCs exist, because I can manipulate their properties:

_root.picStrip.image1._alpha=25;


picStrip does not have any event handling on it, so that is not the issue. What am I doing wrong here? Surely there is a way to do this...

Many thanks to anyone can help!

Xeef
12-14-2004, 07:21 PM
hi

Hmmmm

if you load somthing in a MC all is't EVEN'T are overwriten by the loaded image
so you have to asign them after the load is COMPLETED !!!

bluetrane
12-14-2004, 08:04 PM
Xeef... thanks for trying to help. Can you be a bit more specific please? Here is my code. How would I modify it to insure that the image movieclips have all loaded? I am able to manipulate properties for the loaded MCs. Wouldn't that mean that they have loaded successfully?

//load images
var imageArray:Array = new Array();
imageArray[0] = "uploads/100012_people/100000.jpg";
imageArray[1] = "uploads/100012_people/100001.jpg";
imageArray[2] = "uploads/100012_people/100002.jpg";
imageArray[3] = "uploads/100012_people/100003.jpg";

//create clips dynamically for images
for (var i = 0; i<imageArray.length; i++) {
var thisImage:String = "image"+i;
picStrip.createEmptyMovieClip(thisImage, picStrip.getNextHighestDepth());
eval("picStrip."+thisImage).loadMovie(imageArray[i]);
eval("picStrip."+thisImage)._x = (100*i);
eval("picStrip."+thisImage)._y = 0;
}
// Click on dynamically loaded JPG movieclip...
_root.picStrip.image1.onRelease = function() {
trace("Do something here...");
};

Xeef
12-14-2004, 09:02 PM
_root.createEmptyMovieClip("test1", 1);
test1.onEnterFrame = function() {
trace("i am runing :) but i will by overwriten !!!");
};
//this will overwrite the onEnterFrame !!!
test1.loadMovie("http://www.macromedia.com/images/shared/product_boxes/112x112/box_studio_112x112.jpg");
/////////////////////////////////
_root.createEmptyMovieClip("test2", 2);
var mclListener:Object = new Object();
mclListener.onLoadComplete = function(target_mc:MovieClip) {
// at this point the load is complited now you can give functions to it
target_mc.onEnterFrame = function() {
trace("i am runing :) ");
};
// if you need DIFERENT functions on each loaded clip -->
// either you use for each image it's own MovieClipLoader or you need complex logic
// which function to asign
};
var image_mcl:MovieClipLoader = new MovieClipLoader();
image_mcl.addListener(mclListener);
image_mcl.loadClip("http://www.macromedia.com/images/shared/product_boxes/112x112/box_studio_112x112.jpg", test2);
/////////////////
//Hmmmm some example on this
//Will NOT work on dipher level eg. _root.Holder.My_mc in this case you woud need
//other logic !!!
/////////////////
_root.createEmptyMovieClip("pic1", 3);
_root.createEmptyMovieClip("pic2", 4);
_root.createEmptyMovieClip("pic3", 5);
var mclListener:Object = new Object();
mclListener.onLoadComplete = function(target_mc:MovieClip) {
target_mc.onEnterFrame = _root[String(target_mc).split(".")[1]];
};
var image_mcl:MovieClipLoader = new MovieClipLoader();
image_mcl.addListener(mclListener);
image_mcl.loadClip("http://www.macromedia.com/images/shared/product_boxes/112x112/box_studio_112x112.jpg", pic1);
image_mcl.loadClip("http://www.macromedia.com/images/shared/product_boxes/112x112/box_studio_112x112.jpg", pic2);
image_mcl.loadClip("http://www.macromedia.com/images/shared/product_boxes/112x112/box_studio_112x112.jpg", pic3);
pic1 = function () {
trace("Hallo this is a test");
};
pic2 = function () {
trace("this is a nother test BY "+this);
};
pic3 = function () {
trace("this is a nother test BY "+this+" shoud by PIC3 :) ");
};