PDA

View Full Version : if x > 300 and y > 300 then remove child


pbryd
07-12-2009, 06:04 PM
Hello Guys

I've got various movie clips on my stage and a small graphic of a waste bin in the bottom right hand corner.

I can drag the movie clips around the stage with...

function mouseDownHandler(evt:MouseEvent):void {
var object = evt.target;
object.startDrag();
}

I'd like to drag the movieclips to the bin and have them removed from the stage.

The bin is at the bottom corner of the stage so I'm thinking along the lines of

if x > 300 and y > 300 then remove child.

Can someone advise me on this?

Phil

lemoncurds
07-12-2009, 06:29 PM
Try this

function main(event:Event) {
if (yourmovieclip.x > 300 && yourmovieclip.y > 300) {
removeChild(yourmovieclip);
}
}

stage.addEventListener(Event.ENTER_FRAME, main);

lemoncurds
07-12-2009, 06:32 PM
Or alternatively you could test to see if your movie clip had hit the bin using hitTestObject. There's a basic tutorial on collision detection (http://actionscript3tuts.blogspot.com/2009/07/basic-collision-detection.html) here

pbryd
07-12-2009, 07:14 PM
Try this

function main(event:Event) {
if (yourmovieclip.x > 300 && yourmovieclip.y > 300) {
removeChild(yourmovieclip);
}
}

stage.addEventListener(Event.ENTER_FRAME, main);

Thanks

I've used part of the code you supplied but added it to the function that listens for the mouse button to be released

Here's the code I have for it now.

function mouseUpHandler(evt:MouseEvent):void {
var obj = evt.target;
obj.stopDrag();
if (obj.x > 300 && obj.y > 320) {
removeChild(obj);
}
}

That's working fine

Here it is in action..

http://tynesidegraphics.co.uk/pizzamaker/pizzamaker5.html

Thanks very much for this.

Phil

pbryd
07-12-2009, 07:21 PM
Or alternatively you could test to see if your movie clip had hit the bin using hitTestObject. There's a basic tutorial on collision detection (http://actionscript3tuts.blogspot.com/2009/07/basic-collision-detection.html) here

Thanks for the link, I'll have a look at it a bit later and see if it's useable.

Appreciated

Phil