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.
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
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
Post a Comment