Assigning actions to buttons added dynamically.
hello,
here problem, adding buttons stage run-time , life of can't actions in them them work. when click button nothing happens. missing something??
here problem, adding buttons stage run-time , life of can't actions in them them work. when click button nothing happens. missing something??
well seems found reason why. starters dropped whole listener thing.
what trying accomplish select image associated button number "image_1" has "button_1". wanted when clicked "button_1" send number showimage() function.
note: found out after few hours not add x variable function in...
this.adbutton.onrelease = function()
{
showadimage(x);
}
... because recall current value of x end being somenum. fyi, calling events call current values of variables.
so solution...
the way got around calling buttons name "this" , turning string variable. split using split() , grabbed number.
once done worked fine.
this final code.
...
for (x=0; x < somenum; x++) {
// name , create button...
btnname = "adbutton_" + x;
this.attachmovie("btn", btnname, this.getnexthighestdepth());
// button...
adbutton = eval(btnname);
// position button...
this.adbutton._x = someposx;
this.adbutton._y = someposy;
this.adbutton._width = somewidth;
// set , add actions button...
this.adbutton.onrelease = function() {
imthis = + "";
= imthis.split("_level0.adbutton_");
showadimage(i[1]);
}
}
...
what trying accomplish select image associated button number "image_1" has "button_1". wanted when clicked "button_1" send number showimage() function.
note: found out after few hours not add x variable function in...
this.adbutton.onrelease = function()
{
showadimage(x);
}
... because recall current value of x end being somenum. fyi, calling events call current values of variables.
so solution...
the way got around calling buttons name "this" , turning string variable. split using split() , grabbed number.
once done worked fine.
this final code.
...
for (x=0; x < somenum; x++) {
// name , create button...
btnname = "adbutton_" + x;
this.attachmovie("btn", btnname, this.getnexthighestdepth());
// button...
adbutton = eval(btnname);
// position button...
this.adbutton._x = someposx;
this.adbutton._y = someposy;
this.adbutton._width = somewidth;
// set , add actions button...
this.adbutton.onrelease = function() {
imthis = + "";
= imthis.split("_level0.adbutton_");
showadimage(i[1]);
}
}
...
More discussions in ActionScript 1 and 2
adobe
Comments
Post a Comment