Note that there are some explanatory texts on larger screens.

plurals
  1. POI need to remove an image from the stage when I drop it onto the trash can image in AS3
    text
    copied!<p>I need to remove the image from the stage whenever I drag and drop "into" the trash can. I have been looking at this forever and really cant seem to find a solution.</p> <pre><code>&lt;fx:Declarations&gt; &lt;!-- Place non-visual elements (e.g., services, value objects) here --&gt; &lt;/fx:Declarations&gt; &lt;fx:Script&gt; &lt;![CDATA[ import mx.controls.Image; //array of movies public var myArray:Array = ["batman.jpg","cabin.jpg","christmasVacation.jpg"]; //init function public function init():void{ var trashImage:Image = new Image(); //set trash img trashImage.source = "asset/trash.jpg"; //adds img to stage trashGrp.addElement(trashImage); //loops 4 times for(var i:Number = 0; i &lt; myArray.length; i++){ var arrayEntry:String = myArray[i]; //makes new image var newImage:Image = new Image(); //sets the image source for each image newImage.source = "asset/" + arrayEntry; //adds the image to the stage grpMovies.addElement(newImage); //set drag/drop newImage.addEventListener(MouseEvent.MOUSE_DOWN, dragMe); newImage.addEventListener(MouseEvent.MOUSE_UP, dropMe); } } //dragMe function public function dragMe(e:MouseEvent):void { // Get the Image that saw the mouse-down. var img:Image = Image(e.currentTarget); // Use the built-in method to start dragging. img.startDrag(); } //dropMe function public function dropMe(e:MouseEvent):void { // Get the Image that saw the mouse-up. var img:Image = Image(e.currentTarget); // Use the built-in method to stop dragging. img.stopDrag(); -**this is where my issue is. I cant get it to remove it when the image is hit** if (trashGrp.hitTestObject(img)) { grpMovies.removeElement(img); } } ]]&gt; &lt;/fx:Script&gt; &lt;s:TileGroup id="grpMovies" columnWidth="225" rowHeight="225" requestedRowCount="1" paddingTop="20"/&gt; &lt;s:HGroup id= "trashGrp" x="950" y="20"/&gt; &lt;/s:Application&gt; </code></pre>
 

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