Note that there are some explanatory texts on larger screens.

plurals
  1. POTrying to remove all children, receiving error #1009
    primarykey
    data
    text
    <p>The idea with my setup is that I have an input text field and three separate buttons on stage. When you type something in the text field and press the input button, the text inside the field is added to an array. </p> <p>When you press the display button the contents of the array are displayed on screen (each value of the array is displayed underneath the last value). </p> <p>The final button is supposed to remove all the current values on the array, and clear all displayed values on screen. But I cannot get my code to work as intended, since I receive, </p> <p><code>TypeError: Error #1009: Cannot access a property or method of a null object reference.</code> </p> <p>With this block of code:</p> <pre><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; i &lt; 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"));} } </code></pre> <p>Alternatively, when I add</p> <pre><code>var tf:TF = new TF; </code></pre> <p>It removes only one displayed value on screen. Also I might add, that "TF" is a movie clip in the library that contains a dynamic text field that's instance name is txt. Is the problem only with the last button, or should I change something else as well? I don't know how to make this work as I want it to. I'm pretty new to coding so any tips or help would be much appreciated. Thanks in advance!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload