PDA

View Full Version : Loading Images into Movie Clip Dynamically


newUser007
06-08-2007, 03:18 PM
I am trying to create thumbnails and when I try to load the image onto the dynamic movie clip...it suddenly becomes non-clickable.

if I create a movieClip with borders and color, it is fine.it just messes up when I load images onto the dynamically created movie clip.

It is baffling. any help would be appreciated.

here's the code for it:

myPhoto = new XML();

myPhoto.ignoreWhite = true;
myPhoto.onLoad = function(success) {
numImages = this.firstChild.childNodes.length;
d1 = 1;spacing = 70;
trace(numImages);
x = 250;d2 = 1;
for (i=0; i<numImages; i++) {
_root.createEmptyMovieClip("btn"+i,100+i);
_root["btn"+i].lineStyle(2, 0x000000, 100);
_root["btn"+i].beginFill(0xFF0000, 100);
_root["btn"+i].lineTo(25, -10);
_root["btn"+i].lineTo(25, 10);
_root["btn"+i].lineTo(-25, 10);
_root["btn"+i].endFill(-25, -10);

_root["btn"+i]._x = x + i*spacing;
_root["btn"+i]._y = 420;
trace(this.firstChild.childNodes[i].attributes.thmb);

//the line below is the one that messes up things

loadMovie(this.firstChild.childNodes[i].attributes.thmb,_root["btn"+i]);
}
btn1.onRelease = function(){
trace("Inside btn1");
}
btn2.onRelease = function(){
trace("Inside btn2");
}
btn3.onRelease = function(){
trace("Inside btn3");
}
btn4.onRelease = function(){
trace("Inside btn4");
}
btn5.onRelease = function(){
trace("Inside btn5");
}
btn6.onRelease = function(){
trace("Inside btn6");
}
btn7.onRelease = function(){
trace("Inside btn7");
}
btn8.onRelease = function(){
trace("Inside btn8");
}
trace(this.firstChild.childNodes[1].attributes.main);
//loadMovie(this.firstChild.childNodes[1].attributes.main);

};
myPhoto.load("xmlphoto.xml");

newUser007
06-08-2007, 04:12 PM
I finally figured it out..trial and error SUCKS!!!!!!!!

looks like root.createEmptyMovieClip("btn"+i,100+i); alone is not adequate:that is just the holder.

we need to create a reference to it as in:

thumbHolder = _root.createEmptyMovieClip("btn"+i,100+i);

and then create Movie Clips for the images themselves as in:

thumbLoader = thumbHolder.createEmptyMovieClip("thumb"+i,100+i);

and then load the movie:

thumbLoader.loadMovie(this.firstChild.childNodes[i].attributes.thmb);


and then for the trigger:

btn1.onRelease = function(){
trace("Inside Btn1");
}

so there needs to be a movie clip inside a movie clip for it to work.

I really don't quite know why.