Groups | Blog | Home
all groups > flash actionscript > february 2004 >

flash actionscript : onRelease function on a movieclip that is dynamically generated


GSB
2/27/2004 6:57:30 PM
I am dynamically generating movieclips.

j = 5;
for (var i = 1; i<j; i++) {
_root.attachMovie("mcInfo", "mc_info"+i, i);
_root["mc_info"+i]._y = yposition;
_root["mc_info"+i]._x = 670;
yposition = yposition+25;
}

This part of the code works fine.
I am now trying to add onRealease function to the dynamically generated
movieclips, but it is not recognizing the event.

for (var i = 1; i<j; i++) {
_root["mc_info"+i].onRelease = function() - Also tried
eval("mc_info"+i).OnRelease for this line
{
trace("On Release Event");
}
}

What am I doing wrong here?

-S

stwingy
2/28/2004 9:08:23 AM
try something like this
j = 5;
for (var i = 1; i<j; i++) {
myClip = _root.attachMovie("mcInfo", "mc_info"+i, i);
_root["mc_info"+i]._y = yposition;
_root["mc_info"+i]._x = 670;
yposition = yposition+25;
myClip.onRelease = function() {
trace("On Release Event");
};
}
GSB
2/28/2004 1:08:19 PM


[quoted text, click to view]


If I do that then myClip is the last movieclip and only the last movieclip
is activated as a button. The rest of it is not.

-S

stwingy
2/28/2004 6:59:44 PM
Not sure what you mean,
try this

j = 5;
for (var i = 1; i<j; i++) {
myClip = _root.attachMovie("mcInfo", "mc_info"+i, i);
_root["mc_info"+i].ivar = i;
_root["mc_info"+i]._y = yposition;
_root["mc_info"+i]._x = 670;
yposition = yposition+25;
myClip.onRelease = function() {
trace(this.ivar);
};
}
AddThis Social Bookmark Button