Variable with nested function


i create button in loop, means there button @ each iteration. pass variables create , add function respond when clicked.

here code looks like:
button = _root.attachmovie(...);
button._x = xofs;
button._y = 200;
...

button.onrelease = function() {
trace("button clicked, surl: "+surl);
};

the problem when test movie, give same url no mather wich 1 click. variable surl changing @ each iteration.

the line
trace("button clicked, surl: "+surl);
uses value of 'surl' @ time executed, takes last value assigned 'surl'. have store proper value mc:

button.link = surl;
...
button.onrelease = function() {
trace("button clicked, surl: "+this.link);
};

or pass 'surl' variable value, using function:

function definerelease(mc, url){
mc.onrelease = function(){
trace("url = "+url);
}
}
// in loop:
definerelease(button,surl);

hth,
blemmo


More discussions in ActionScript 1 and 2


adobe

Comments

Popular posts from this blog

Convierte tu Raspberry en un NAS. Firmware fvdw-sl 15.3 - Raspberry Pi Forums

How to format a Get Request

avrdude: verification error, first mismatch at byte 0x0000 0x0c != 0x62