Note that there are some explanatory texts on larger screens.

plurals
  1. PONoob AS3 question regarding using event handlers to remove MovieClip object from stage
    primarykey
    data
    text
    <p>I'm an AS3 noob just trying to get more comfortable working with event handlers in Flash and build interactivity into my application. </p> <p>In the code below, I have created an instance of the DrawLineChart class called LineChart1. When I test the movie, it shows up on the stage just fine and when I click on it, I can use a trace command to get a string statement written to the output window. </p> <p>However, now I want to be able to click on LineChart1 on the stage and have it be removed. When I do that, I get an error message 1120: Access of undefined property LineChart1.</p> <p>Could someone please explain to me why I'm unable to refer to my instance LineChart1 and what I need to do so that I can refer to it and remove it when it gets clicked? Also, I'd love to know why the trace statement works when I click on LineChart1 during runtime, but not the removechild command.</p> <p>I'm sorry if this question is too simple, but thank you all for your help in advance. I really appreciate it. </p> <pre><code>package{ import flash.display.*; import flash.events.*; public class Main extends MovieClip{ var recWidth:Number = 250; var recHeight:Number = 550; var recX:Number = 50; var recY:Number = 50; var recScaleY:Number = 30; public function Main(){ var LineChart1 = new DrawLineChart(recX, recY, recWidth, recHeight, recScaleY); LineChart1.addEventListener(MouseEvent.CLICK, onClickHandler); addChild(LineChart1); } function onClickHandler(e:Event):void{ trace("hello"); // This works. When I click on the LineChart1 MovieClip on the stage during runtime, I get "hello" as an output. removeChild(LineChart1); // throws an error 1120: Access of undefined property LineChart1. Why? } } } </code></pre>
    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.
    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