Is there a way of storing somehow the initia position of a mc, so that if it is dragged when you release the button it goes bact to its initial position??
I tryed to put something like
[COLOR=blue]
onClipEvent (load){
this._x = posicionx;
this._y = posiciony;
}[/COLOR]
and afte call to this variables.But is doesn’t work.
:-\
thanks!
this is exactly what i was trying to do. Dirung the time you answered i came up with this, similar but not the same (for sure your code is much better) . This code i came up with doesn’t work propperly, because the mc goes bac to the point, but not always exactly where it should. Any idea Why??? (well, as you will see it does soething else when reaching a point, but this works fine)
[COLOR=blue]
onClipEvent (enterFrame){
function coger(){
startDrag (this,true);
if (this.hitTest (_root.pantalla)){
trace (“hola”);
this._alpha = 50;
}
}
function soltar(){
stopDrag ();
[/COLOR] [COLOR=indigo]//this ifs should put it back where it belonged!! right??[/COLOR][COLOR=blue]
if (this._x >247) this._x-=10;
if (this._x <247) this._x+=10;
if (this._y>36) this._y -=10;
if (this._y<36) this._y +=10;
}
this.onPress = function(){
this.onEnterFrame = coger;
}
this.onRelease = function(){
this.onEnterFrame = soltar;
}
}
[/COLOR]
Anyway, your code is perfect. But i still wonder if there is a way to put the initial position “by default”, i mean, the position of the mc when it loads, so you don’t have to put the x and y coordinates in each mc.
=)
EDIT: is it because i’m not telling the position is in the _root???
Actually I changed the fla because the code should have been more neater - the initial x and y should have been in load not enter frame - there’s no need to keep telling it every frame what the old x and y were
Also don’t define functions in enterFrame - you only need to do it once. You can do it in on load, or in the main time line in a layer called functions if you like. Just make sure you define it before calling it and use the right target path - there is a thread here about functions.
Check the actions for the button inside the mc. I haven’t set the initial value of go1 anywhere, I just declare it and set at the same time in the button.
oh… i see…
i didn’t thought there was a button. I thought there was only a mc. i should work the same right???
oh, and which is the difference in using this._x and _x inside the actions of a mc? all actions are refered to it, aren’t they?
EDIT: And i don’t understand the coding inside the button. I’m a bit slow today, sorry …
It seemed to be that the mcs were looking at the same variables, because once you dragged one mc - the other’s were disabled - and if do dragged the 2nd it would go to the x and y of the 1st.
You also had the functions in onEnterFrame which you didn’t need - and I think the onPress and onRelease would have been better on a button.
But anyway when the button (so that means also the mc) is dragged ie on (press) _root.go1 becomes false. That means that
if (_root.go1) {
_x += (old_x-_x)/speed; // this line won’t run
_y += (old_y-_y)/speed; // nor will this
}
because the if statement checks if _root.go1 is true, so the disk won’t return to their original position, as _root.go1 is false.
But when you release, on (release), then _root.go1 becomes true, allowing the two lines I commented above to run, in other words, the disk will return back to it’s original position.