Scoping variables aarghh

for (var i = 2; i<=maxvalue; i++)
{duplicateMovieClip(“clip”, “clip”+i, i);


and so on

so you see I want to duplicate a movieclip here as much as ‘maxvalue’ times. It works fine. But inside the duplicated movieclips is another movieclip/button and its (unique) behaviour is controlled by the following script: (I also placed this in the “for”-loop (?))

clipnumber = eval(“clip”+i);
clipnumber.submovie.onRelease = function() {
getURL(“detailpage”+i,“target”);
};

but this i variable is not reachable from within the function. I suppose I am making very fundamental mistakes, but can somebody help me out and show me the right way to do this?

thanks guys
Stanley

Maybe try adding your button code after the duplicate movie clip code

Just change it to look like _root.mainClip.yourButton.onRelease

Maybe that will help.

I had the same problem a couple of days ago :slight_smile:
You have to define the i variable for each movie (especially because it’s in a loop)

for (var i = 2; i<=maxvalue; i++) 
{
      mc=duplicateMovieClip("clip", "clip"+i, i);
      // you don't need clipnumber, you manipulate mc 
      mc.i=i;
      mc.submovie.onRelease = function()
      {
            getURL("detailpage"+_parent.i,"target");
      }
};

Something like that.

pom :asian:

Mhhh…
This looks like a good solution. I’ll give it a try…
thanks man :slight_smile:

I’m not quite there yet. In other words, I don’t get this thing to work…
Could you explain your code a little more, pom?

Stan

Sure.

for (var i = 2; i<=maxvalue; i++) 
{
      mc=duplicateMovieClip("clip", "clip"+i, i);
      // in fact, mc=this["clip"+i]
      mc.i=i;
      // we define the i variable of this particular movie clip
      mc.submovie.onRelease = function()
      // submovie should be a clip that already exist in clip
      {
            // I put _parent because you have to go one level up in
            // the hierarchy. If this doesn't work, you could try to put
            // mc.i instead
            getURL("detailpage"+_parent.i,"target");
      }
};

Otherwise post your code or your fla.

pom :asian: