actionscript 3 - Trying to remove all children, receiving error #1009 -
the idea setup have input text field , 3 separate buttons on stage. when type in text field , press input button, text inside field added array.
when press display button contents of array displayed on screen (each value of array displayed underneath last value).
the final button supposed remove current values on array, , clear displayed values on screen. cannot code work intended, since receive,
typeerror: error #1009: cannot access property or method of null object reference.
with block of code:
import flash.text.textfield; import flash.events.mouseevent; var myarray:array = new array (""); var tf:tf; btninput.addeventlistener(mouseevent.click, txtinput); function txtinput(event:mouseevent):void {myarray.push(txtinput.text);} btndisplay.addeventlistener(mouseevent.click, txtdisplay); function txtdisplay(event:mouseevent):void {for (var i:int = 0; < myarray.length; i++) {var tf:tf = new tf(); tf.txt.text = myarray[i]; tf.y = 280 + (i * 25); tf.x = 265; addchild(tf); tf.name="test";} } btnclear.addeventlistener (mouseevent.click, txtclear); function txtclear(event:event){ myarray.splice(1); if (tf.numchildren != 0){ removechild(getchildbyname("test"));} }
alternatively, when add
var tf:tf = new tf;
it removes 1 displayed value on screen. might add, "tf" movie clip in library contains dynamic text field that's instance name txt. problem last button, or should change else well? don't know how make work want to. i'm pretty new coding tips or appreciated. in advance!
in condition if(tf.numchildren != 0)
tf
object null
since never created it. that's why you're getting #1009
error.
on other hand, in order delete items should replace if (tf.numchildren != 0)
while (tf.numchildren != 0)
.
Comments
Post a Comment