|
|
|
#1 |
|
Member
Join Date: Aug 2002
Posts: 42
|
Hi, the animation that I'm trying to build is probaly very simple, but I can't quite work it out?
What I'm trying to make is a basic drag and drop where the object ('dragt') slowly returns to it's starting point by following the target ('targett') in order to get there. The problem is that the function I'm using to move it there ('movet' = pasted in below) keeps going. So that when you try to click on it again, it's still working and it causes a flickering between the movement it's trying to accomplish and the drag action. I tried including a variable ('ton') to build in a basic on/off state into the function, so that it won't work until 'ton == 0', ton is made equal to 0 as part of the start drag action. However, as said, this only works once as the function is still going when you go back to click again. So the hitest (seen below) registers again and puts 'ton == 1' before the drag can even begin. So... what I need is some way to tell the function to stop doing what it's doing when the movieclip returns to it's original co-ordinates? Hopefully I'm explaining this in some way that makes a degree of sense and somebody can solve this, or has encountered something similar before, thanks loads, -Eoin McD Here's the function: setInterval(movet, 5); // call the catchase function every 5 ms function movet() { // set x, y for cat closer to x, y of mouse if (_root.ton == 0) { _root.dragt._x = _root.dragt._x+(_root.targett._x-_root.dragt._x)/20; _root.dragt._y = _root.dragt._y+(_root.targett._y-_root.dragt._y)/20; } if (_root.dragt.hitTest(_root.targett)) { _root.ton = 1; } if (_root.ton == 1) { gotoAndStop(1); } } updateAfterEvent(); |
|
|
|
|
|
#2 |
|
nobody
Join Date: Aug 2002
Posts: 269
|
You can put a function inside an empty movie clip (then it does not need to be a function anymore), that loops when you play it. When you dont want it, you just stop playing that movie.
|
|
|
|
|
|
#3 |
|
Member
Join Date: Aug 2002
Posts: 42
|
thanks
Thanks loads, I was trying to make life far too complicated.
That works a charm. |
|
|
|
|
|
#4 |
|
Flash Video Moderator
Join Date: Dec 2000
Location: Minneapolis
Posts: 1,589
|
I've had a hard time getting this to work dynamically (using onEnterFrame) but the one sure fire way I've had success with is:
An empty MC inside the object you want to return. Frame 1: xHome=_parent._x; yHome=_parent._y; Frame 2: if(_parent.snapBack) { x = _parent._x; y = _parent._y; if (Math.abs(x-xHome)>1) { x = x+((xHome-x)/8); _parent._x = x; } if (Math.abs(y-yHome)>1) { y = y+((yHome-y)/8); _parent._y = y; } } Frame 3: gotoAndPlay(2); Then in the parent set the snapBack variable with onPress/onRelease. You could add a if(_parent._x == this.x && _parent._y==this.y){ this.stop(); } (not tested) - to end the loop. 5G |
|
|
|
|
|
#5 |
|
Junior Member
Join Date: Aug 2002
Posts: 5
|
To Stop a function from working
In the beginning of the function, insert an if statement that checks a flag variable( ex. if (allowFunction==TRUE)...put code in here and end the if statement. Then all you have to do is set the flag to false in the frame you want it to stop running on. Remember, onClipEvent(load) to set the variable to true if you want the function to initialize to run.
|
|
|
|
![]() |
|
||||||
| Thread Tools | Search this Thread |
| Display Modes | |
|
|