actionscript - How to remove MovieClip by selecting a row and pressing a delete button? -


i have datagrid, rows added. whenever row added, movie clip added stage. added button remove row in datagrid if row , button clicked, , of works well.

however, when try remove movie clip relating row in datagrid, not work.

my code is:

function removeloaditem(event:mouseevent) { datagrid.removeitemat(datagrid.selectedindex); removechild(movieclip(datagrid.selectedindex); } 

removechild(movieclip(datagrid.selectedindex); 

you need understand line of code trying do.

datagrid.selectedindex 

this variable number. so, trying cast number movieclip.

movieclip(1) 

that not work. need reference actual movieclip object. wherever creating movieclip object, need store reference object. can have plain object store of references.

var objectlist:object = {}; 

and then, wherever creating movieclip, add line:

objectlist["reference_" + datagrid.selectedindex] = "movieclip variable"; 

replace "movieclip variable" reference movieclip object. after that, replace current removechild line these 2 lines:

var movieclip = objectlist["reference_" + datagrid.selectedindex] moveclip.parent.removechild(movieclip); 

Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -