|
-
stop onEnterFrame
Dear all, I have this code that allows a clock hand to rotate around a clock.
Code:
onClipEvent(load){
secondTime = 2560;
startTime = getTimer();
}
onClipEvent(enterFrame){
if(getTimer()-startTime>=2560){
elapsed = (getTimer() - startTime) % secondTime;
this._rotation = 360 * (elapsed/secondTime);
}
}
I would that the hand rotation stops on a keyboard or mouse event, remaining in the position of the last frame. So, I need to stop the onEnterFrame event, but I don't know how.
Can anybody help me, please? Sorry, but I'm not an actionscript programmer...
Thanks in advance.
-
Prid - Outing
Well, hi again, it's me, Prid :P
Actionscript Code:
onClipEvent(load){ secondTime = 2560; startTime = getTimer(); spacebar_pressed = false; }
onClipEvent(enterFrame){ if(Key.isDown(Key.SPACE)){ spacebar_pressed = true; } if(getTimer()-startTime>=2560 && spacebar_pressed == false){ elapsed = (getTimer() - startTime) % secondTime; this._rotation = 360 * (elapsed/secondTime); } }
I am back, guys ... and finally 18 :P
BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS
-
Hi Prid! I would not disturb you again but it was not. Anyway, thanks again. It does works and I've modified the code for mouse button press.
Now the next step for me is to stop the hand in a random time (in range 1500-2500 ms) after the mouse press. I've to use setinterval()?
Here my modified code:
Code:
onClipEvent(load){
secondTime = 2560;
startTime = getTimer();
mouse_pressed = false;
}
onClipEvent(mouseDown){
mouse_pressed = true;
}
onClipEvent(enterFrame){
if(getTimer()-startTime>=2560 && mouse_pressed == false){
elapsed = (getTimer() - startTime) % secondTime;
this._rotation = 360 * (elapsed/secondTime);
}
}
I'm making a little progress with actionscript, but it's still not enough.
-
Prid - Outing
No, you juse let Flash generate a random number, and then make it stop when the milliseconds are exceeding that number:
Actionscript Code:
onClipEvent(load){ secondTime = 2560; startTime = getTimer(); mouse_pressed = false; random_num = (Math.random()*1000)+1500; }
onClipEvent(enterFrame){ if(getTimer()-startTime>=2560){ time2 = (getTimer()-startTime)-2560; if(time2 < random_num){ elapsed = (getTimer() - startTime) % secondTime; this._rotation = 360 * (elapsed/secondTime); } } }
I am back, guys ... and finally 18 :P
BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS
-
I tried this method but it doesn't work always. From the begin of the clip, if I click before 3840 ms it works, that is the hand rotates for a random time and then it stops. But if I click after 3840 ms (more or less) the hand stops immediately.
This is because the formula
Code:
time2 = (getTimer()-startTime)-2560
gives values greater than the random number after a certain time. I've tried various other formulas but none make that I need. I post my updated code, so you can see if I mistaken anything.
Code:
onClipEvent(load){
secondTime = 2560;
startTime = getTimer();
mouse_pressed = false;
random_num = (Math.random()*1000)+1500;
}
onClipEvent(mouseDown){
mouse_pressed = true;
}
onClipEvent(enterFrame){
if(getTimer()-startTime>=2560 && mouse_pressed == false){
elapsed = (getTimer() - startTime) % secondTime;
this._rotation = 360 * (elapsed/secondTime);
}
else {
if(getTimer()-startTime>=2560){
time2 = (getTimer()-startTime)-2560;
if(time2 < random_num){
elapsed = (getTimer() - startTime) % secondTime;
this._rotation = 360 * (elapsed/secondTime);
}
}
}
}
-
I resolved by inserting a click_point variable in the onClipEventMouse handler which record the timer at the click. Then, time2 = getTimer-startTime-click_point. So, it works now, but I would have never done it whithout your help.
I haven't other questions for now, but I don't exclude that I may disturb you again in future. :P
Last edited by psychologist; 10-24-2011 at 12:26 PM.
-
Prid - Outing
Good to hear that it's fixed 
I haven't other questions for now, but I don't exclude that I may disturb you again in future. :P
I won't
I am back, guys ... and finally 18 :P
BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|