Log in

View Full Version : Dynamically created objects do not get events?!?



BullD0G
12-09-2008, 07:48 AM
Hi guys.
I have a little bit of trouble with dynamically creating some elements and applying some event to them. The objects appear as i want to but do not accept the event i try to append! Here is the code:

function loadThumbs(){
for(n=0;n<total;n++){
_root.thumb.duplicateMovieClip ("thumb"+n, _root.getNextHighestDepth());
thisClip=_root["thumb"+n];
thisClip._y = 481;
thisClip._x = xPosition;
xPosition = xPosition + 87
thisClip.loadMovie(th[n], 1);
thisClip._alpha = 60;
thisClip.onRollOver = function(){
thisClip._alpha=100;
}
thisClip.onRollOut = function(){
thisClip._alpha=60;
}
thisClip.onRelease = function(){
var currentBtn:String = thisClip._name;
var currentIndex:String = currentBtn.substring(5,7);
loadImage(currentIndex);
}

}
}

function loadImage(j) {
if (loaded == filesize) {
bi_holder._alpha = 0;
bi_holder.loadMovie(image[j], 1);
picture_num();
}
}

I'd appreciate any ideas because i'm really stuck!

Medyman
12-09-2008, 02:31 PM
Have you tested the value of currentBtn and currentIndex to see if it's giving you the values that you expect? I suspect that you might have a problem with the scope of some of those variables.

Also, it might be less confusing to use the "this" keyword instead of thisClip inside of the mouse events. You don't have to, but it'll reduce the chance of mistakes.

BullD0G
12-09-2008, 03:02 PM
Thanks for the tip. Will test to see if i can reach them. And yeah using this would be useful instead of variable. Just didn't see it there:) Thanks!