Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Drag, Drop and delete 1

Status
Not open for further replies.

tziviak

Technical User
Oct 10, 2002
128
US
I have a few objects -which I want the user to drag, drop on the grid and also have the ability to delete it-if they click on the delete key-but because I have a few objects (circles) how can they choose which one to delete (the onclick action I used for the dragging) also-how can I show if a circle is selected?
here's the code for on circle:
onClipEvent (load) {
_root.circle2.onPress = function() {
_root.circle2.startDrag();
};
_root.circle2.onRelease = function() {
_root.circle2.stopDrag();
};
_root.circle2.onEnterFrame = function() {
if (Key.isDown(Key.DELETEKEY)) {
_root.circle2.unloadMovie();
}
}

}

thank you
 
cant see an easy way out

you could always add the objects to a listbox or combo and stick that somewhere off to one side. and then have the item selected deleted.

_______________________________________
You know you're old if you can remember when bacon, eggs and sunshine were good for you
 
I'd set it up so that the onPress function sets a flag variable identifying the clip that has been clicked on. Then the delete function can be set to only delete that clip.

Code:
_root.circle2.onPress = function() {
	_root.selected = circle2;
	_root.circle2.startDrag();
};
_root.circle2.onRelease = function() {
	_root.circle2.stopDrag();
};
_root.onEnterFrame = function() {
	if (Key.isDown(Key.DELETEKEY)) {
		var clip = _root.selected;
		clip.unloadMovie();
	}
};

 
The unload movie() isn't working-it's not getting deleted any ideas?
also how come I had to put in the line of:
_root.circle2.onEnterFrame = function()-that's the only way that the delete worked before. I'm a beginner so I'd appreciate any help.
Thank you
 
sounds good-but how do I do it?
also, what I want to do that there should be a few images on the bottom-and a grid on top-and if the user doesn't put the image on the grid-then it should snap back to the bottom. so I guess if they want to delete-we can either have the garbage can idea-or let them drag it off the grid-I just don't know how to do it-so would appreciate step-by-step help
 
Here's an example that should do what you want:


The .fla is there too


The code is trimmed down to this:

Code:
circle1.onPress = circle2.onPress=circle3.onPress=function () {
	selected = this;
	this.startDrag();
};
this.onMouseUp = function() {
	stopDrag();
};
this.onEnterFrame = function() {
	if (Key.isDown(Key.DELETEKEY)) {
		selected.unloadMovie();
	}
};
 
thank you for your help-but my problem is that they are both getting deleted-could it be because I have the code-for each of them in their own action?
ex
action for circle 2:
onClipEvent (load) {
_root.circle2.onPress = function() {
selected2 = _root.circle2;
_root.circle2.startDrag();
};
_root.circle2.onRelease = function() {
_root.circle2.stopDrag();
};
_root.circle2.onEnterFrame = function() {
if (Key.isDown(Key.DELETEKEY)) {

selected2.unloadMovie();

}
}

}


and the action for circle3:
onClipEvent (load) {
_root.circle3.onPress = function() {
selected=_root.circle3;
_root.circle3.startDrag();

_root.circle3.onRelease = function() {
_root.circle3.stopDrag();
};
};

_root.circle3.onEnterFrame = function() {
if (Key.isDown(Key.DELETEKEY)) {

selected.unloadMovie();

}
}
}



I thought that maybe-they are both getting deleted because they both have the variable selected-so I named one selected2 but they still got deleted together-because it's not getting released-by your code "this" got replaced-but over here-they are both still selected.(that's what I think is wrong)
 
Using a mixture or MX events and Flash 5 clipevents is causing some conflicts here which is where the problems are coming from. If you go with the code I posted it'll get round all of this, just place it in the first frame of the main timeline and name your clips circle1, circle 2 etc.

It's all in the .fla
 
THANK YOU-IT WORKS GR-8

is there a way to make sure the user puts the item on the grid-and if not-it should sort of snap back to where it came from?
 
Easiest way to do that is to check the x/y coordinates of the circles when they're dropped.

So if your grid's at the top of the screen and starts at say 50 pixels in from the top you could run this code:

Code:
circle1.onPress = circle2.onPress=circle3.onPress=function () {
	selected = this;
	//store original position of circle
        origX = this._x;
	origY = this._y;
	this.startDrag();
};
circle1.onRelease = circle2.onRelease=circle3.onRelease=function () {
	this.stopDrag();
	if (this._y>grid) {
                //check position
		this._x = origX;
		this._y = origY;
	}
};
this.onEnterFrame = function() {
	if (Key.isDown(Key.DELETEKEY)) {
		selected.unloadMovie();
	}
};
_global.grid = 50;//set this value to where your grid starts
_global.selected;
_global.origX;
_global.origY;
 
excellent-works great. now I decided-that if it snaps back-why should I delete it-when the user presses 'delete' I might as well snap it back-but because I have a few different type of shapes-circle, triangle, square and each one has a different starting point-which I defined already-is there a way to test what the 'selected' image is-then I'll do an if statment-ex. if triangle-then i'll snap it back to the triangl's place
so how can I tell-which on is selected?
 
I actually figured it out-so thanks a lot for all your help (I think I'll submit a new thread for my next question-since this one got too long)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top