View Full Version : Removing/turning off startDrag
c_knights
03-10-2005, 01:10 PM
I'm making a game where people have to drop one movie clip onto the correct target clip.
How do I make it so that once the clip is dropped on the correct target the user is no longer able to drag the clip around? In other words, how do I turn off startDrag?
hi and welcome to As.Org
set a variable to true when dropped on the correct target
check the variable if it's true don't drag :)
or
remove the draging function when dropped on the correct target
depends how you set it up
if this doesn't help
i will need to see your code to by more specific
c_knights
03-10-2005, 02:23 PM
Trouble is, I don't know how to remove the dragging function.
Here's the code attached to one of my tiles. It basically checks to see if the tile is over the correct target when dropped. If it's not, it snaps back to its original position. If it is dropped in the right place, it snaps to the target and adds one to the score.
on(press)
{startDrag(this, false);
}
on(release)
{
stopDrag();
if(this.hitTest(_root.q2x2))
{
this._x=_root.q2x2._x;
this._y=_root.q2x2._y;
_root.$score++;
if(_root.$score>=3)
{_root.gotoAndPlay(5);
}
}
else
{
this._x=_root.a4_xcoord;
this._y=_root.a4_ycoord;
}
}
add, this.onTarget. set it to false.
on press, if onTarget is false, the start drag.
on release if the tile is at the correct location, the this.onTarget needs to be set to true. that way it cannot be dragged off target.
c_knights
03-18-2005, 08:09 AM
Thanks. After messing around with this for a bit, finally got it to work!
goodwikl
03-21-2005, 02:36 PM
hi c knights
Can you please post the code showing how you fixed your problem. I am following the Drag and Drop tutorial at http://www.tableau.com.au/tutorials/drag_drop_tut/ and having problems stopping the drag once the objects have been dropped on their correct target.
Also, I want to put a 'replay' button in that will send the draggable objects back to their original position once the task has been completed. Can someone please let me know how to do this, based on the code in the above tutorial link?
Apologies I am very unfamiliar with ActionScript and have looked around at many forum posts but don't seem to be getting anywhere - any help much appreciated.
Thanks.
Gibberish
03-21-2005, 05:37 PM
I believe you would do the same thing goodwikl.
circle_mc.onPress = function() {
if(this.onTarget == true){
// if clicked send back to starting position
circle_mc.onEnterFrame = function() {
this._x -= (this._x - this.myHomeX)/5;
this._y -= (this._y - this.myHomeY)/5;
trace('hello');
if(this._x == this.myHomeX){
delete this.onEnterFrame;
}
}
this.onTarget = false;
}else{
startDrag(this);
}
};
goodwikl
03-24-2005, 03:01 AM
thanks gibberish will give it a go and see how it works
Cheers
vBulletin® v3.7.1, Copyright ©2000-2009, Jelsoft Enterprises Ltd.