每当我将图像拖放到垃圾桶中时,我都需要从舞台上删除图像。我一直在看这个,似乎真的找不到解决方案。
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
<![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 < 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);
}
}
]]>
</fx:Script>
<s:TileGroup id="grpMovies" columnWidth="225" rowHeight="225" requestedRowCount="1"
paddingTop="20"/>
<s:HGroup id= "trashGrp" x="950" y="20"/>
</s:Application>