# Problems setting up handlers for dynamically created movie clips

**URL:** <https://forum.kirupa.com/t/problems-setting-up-handlers-for-dynamically-created-movie-clips/218388>\
**Category:** flash\
**Created:** [March 7, 2007, 12:52pm UTC](https://forum.kirupa.com/t/problems-setting-up-handlers-for-dynamically-created-movie-clips/218388 "2007-03-07T12:52:29Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![mtt\_losd2](https://avatars.discourse-cdn.com/v4/letter/m/94ad74/32.png) [@mtt\_losd2](https://forum.kirupa.com/u/mtt_losd2)\
**Post date:** [March 7, 2007, 12:52pm UTC](https://forum.kirupa.com/t/problems-setting-up-handlers-for-dynamically-created-movie-clips/218388/1 "2007-03-07T12:52:29Z")

</div>

I am setting up a portfolio gallery that I have multiple images being loaded with the flash MovieClipLoader and that is working fine. The problem I am encountering is the following when all the images are done being loaded I call function setupHandlers(); which sets up each clip with onMouseUp events. But when I click on a mc it runs the event on all the the movie clips not the specific on I clicked on. Can somebody help me.

var THUMBW:Number = 74; // width of each thumbnail  
var THUMBH:Number = 50; // height  
var MARGIN:Number = 10; // margin between thumbnails  
var PICPATH:String = “flash\_pics/”;  
var myLoaded:Number;  
var myTotal:Number;  
var myPercent:Number;

// set up loader, an instance of MovieClipLoader  
var loader:MovieClipLoader = new MovieClipLoader();  
//timeline to listen to and respond to loader’s broadcast events  
loader.addListener(this);

function onLoadProgress(\_mc:MovieClip, loaded:Number, totalloaded:Number) {  
}

function grow() {  
trace(this);  
/\*  
this.onEnterFrame = function() {  
if (this.\_width \< THUMBW \* 1.2) {  
this.\_x -= this.\_width \* .025;  
this.\_y -= this.\_height \* .025;  
this.\_width \*= 1.05;  
this.\_height \*= 1.05;  
} else {  
delete this.onEnterFrame;  
}  
} \*/  
}

// thumbnail rollout handler

function shrink() {  
trace(this);  
/\*  
this.onEnterFrame = function() {  
if (this.\_width \> THUMBW) {  
this.\_width /= 1.05;  
this.\_height /= 1.05;  
this.\_x += this.\_width \* .025;  
this.\_y += this.\_height \* .025;  
} else delete this.onEnterFrame;  
}\*/  
}

function setupHandlers() {  
for (var i:Number = 0; i \< rvs.length; i++) {  
thumbs\_mc[“mc”+i].onMouseUp = grow;  
//trace(thumbs\_mc[“mc”+i]);  
}  
}

function onLoadInit(\_mc:MovieClip) {  
// this gets done when the jpg is completely loaded:  
\_mc.\_width = THUMBW;  
\_mc.\_height = THUMBH;  
\_mc.\_alpha = 100;

// give the movieclip a property to remind it who it is  
// (used by openPic to know which big picture to open)  
\_mc.i = ipic;

// now load the next one (if there are more) or set up handlers if done  
ipic++;  
if (ipic == rvs.length) {  
setupHandlers();  
} else {  
loader.loadClip(PICPATH + rvs[ipic].logo, thumbs\_mc[“mc”+ipic]);  
}  
}

function init() {  
var yMove:Number = MARGIN;  
var xMove:Number;  
var counter:Number = 0;  
createEmptyMovieClip(“thumbs\_mc”, 2);  
thumbs\_mc.\_x = 0;  
thumbs\_mc.\_y = 0;

```
// make empty movieclips in holder_mc for each pic to go into
for (var i:Number = 0; i &lt; rvs.length; i++) {       
  var mc:MovieClip = thumbs_mc.createEmptyMovieClip("mc"+i, i+1);

```

// var name:String = “thumb\_mc”+i;  
// thumb\_mc.duplicateMovieClip(name, i+1);  
// thumb\_mc.\_visible = false;

```
    if(i%7 == 0 && i != 0){
        yMove = i * yMove;
        counter = 0;
    }
    xMove = counter * (MARGIN + THUMBW);
    mc._x = xMove;
    mc._y = yMove;
    counter++;
}

```

// set the pointer to the first jpg in the array picnames  
ipic = 0;

// start loading jpgs  
loader.loadClip(PICPATH + rvs[ipic].logo, thumbs\_mc[“mc”+ipic]);  
}

//parses xml into array  
var rvs = new Array();  
var rvs\_xml:XML = new XML();  
rvs\_xml.ignoreWhite = true;  
rvs\_xml.onLoad = function(success){  
if(success){  
parseFile(rvs\_xml);  
init();  
}  
}

function AccessPoint(lineTitle,logo, image, blurb, website, websiteTitle) {  
this.lineTitle = lineTitle;  
this.logo = logo;  
this.image = image;  
this.blurb = blurb;  
this.website = website;  
this.websiteTitle = websiteTitle;  
}  
function parseFile(rvs\_xml) {  
temp = new Array();  
for (var a = 0; a\<rvs\_xml.firstChild.childNodes.length; a++) {  
for (var b = 0; b\<rvs\_xml.firstChild.firstChild.childNodes.length; b++) {  
if(b != 4){ //if not on last node  
temp\*\* = rvs\_xml.firstChild.childNodes[a].childNodes\*\*.firstChild.nodeValue;  
}else{  
temp\*\* = rvs\_xml.firstChild.childNodes[a].childNodes\*\*.firstChild.nodeValue; //node website url  
temp[b+1] = rvs\_xml.firstChild.childNodes[a].childNodes\*\*.attributes.vtitle; //last node website title  
}  
}  
n = new AccessPoint(temp[0], temp[1], temp[2], temp[3], temp[4], temp[5]);  
rvs.push(n);  
}  
}

rvs\_xml.load(“xmldocs/recVehicles.xml”);
