Skip to main content
August 1, 2013
Question

HELP WITH AS3 Removing Movie Clip

  • August 1, 2013
  • 1 reply
  • 603 views

every code i try in the action script to remove a movie clip off of the stage does not work. HELPPPP.

This topic has been closed for replies.

1 reply

kglad
Community Expert
Community Expert
August 1, 2013

use:

function removeF(dobj:DisplayObject):void{

if(dobj && dobj.stage){

dobj.parent.removeChild(dobj);

}

}

p.s.  if you want your movieclip to be gc'd you probably need to take additional steps.

August 3, 2013

well this is my code to bring it onto the stage

import flash.events.MouseEvent;

pills.addEventListener(MouseEvent.CLICK, arrest)

function arrest(pEvent:MouseEvent):void{

          if(pEvent.target==pills){

                    var carimage: policecar= new policecar();

                    carimage.x=0;

                    carimage.y=0;

                    this.addChild(carimage);

          }

}

and the remove is under a different clip

stop();

bars1.addEventListener(MouseEvent.ROLL_OVER, barsout)

function barsout(pEvent:MouseEvent):void{

          if(pEvent.target==bars1){

                    this.removeChild(carimage);

          }

}

even when i add the latter code into the origininal code above it tells me access of undefined property (carimage)

kglad
Community Expert
Community Expert
August 3, 2013

1. you didn't use the code i suggested.

2. no suggestion can help you unless you have a correct object reference.

if you understand scope, what's the relationship between the scope where you are trying to use carimage and the scope where it's defined?

if you don't understand scope, what timeline (relative to the main swf's main timeline or relative to the timeline where you're trying to remove carimage) contains carimage?