0
votes

yes i know this question gets asked all the time, but my inexperience has prevented me from finding the answer. I'm simply trying to remove an object from the screen if a button is clicked -

    public function but1click(evtObj:MouseEvent)
    {
        trace("button one clicked");
        if (gracestate == "grace")
        {
            removeChild(grace);
        trace("grace removed");
                }
    }

I traced the parent of the object (grace) and it came back as null. This is driving me nuts, and help would be much appreciated!

1

1 Answers

0
votes

The question is unclear though the most likely problem seems to be you're storing a value into grace that is being garbage collected/deleted.

If you create a variable inside a function but no reference to that variable exists outside the function it will be GC'd. Basically anything that isn't referred to by something else is deleted, the only object this isn't true for is the timeline. This stops the flash player lagging and avoids errors when the RAM becomes full. Thus:

    function createGrace () {
      var grace = new Object();
      addChild(grace);
    }
    trace (grace); // returns null

    var grace:Object;
    function createGrace () {
      grace = new Object();
      addChild(grace);
    }
    trace (grace); // returns [Object]