Dual function button - onPress and onRelease combination - code breaks on 2nd visit
Hi all,
I am creating a simulation of a 'smart' shower screen which has various modules - "duringShowering", "create Profile", "temperature and" "outlet" and "flow"
When a user arrives "create Profile" module if he clicks the main button once (onRelease) he skips onto and selects the next module which in this case is "outlet" module where he can change from shower to drench. The modules are assigned to different frame labels on the timeline.
However if he presses and holds the main button for 5 seconds the user is taken to another frame
where he can program a new profile and setup the water temperature, flow and timer etc.
In essence the code below allows me to do this just fine but only ONCE as i click through the five modules.
However if i click through all the modules again (loop) for the 2nd or 3rd time
then the code seems to break and the button loses the "dual" functionality.
Mostly the onPress functionality continues to work BUT the onRelease seems to fail and when i click i cannot skip to the "outlet" module.
This happens when i revisit the same code as i click through the modules on a 2nd or 3rd
loop around the animation. Pretty frustrating as need to give a demo this Friday!
I would be grateful if someone could have a look at the code below
and possibly identify if there are any fixes that i can apply to make it more stable,
and so that it can loop without breaking.
I have a suspicion that "clearInterval(intervalID)" might have a lot to do with it.
Many thanks
Guy
stop();
var miniTime = 0;
var intervalID:Number;
joggleAnimation.button01.onPress = function() {
function callback() {
miniTime = getTimer();
}
intervalID = setInterval(callback, 500);
};
joggleAnimation.button01.onRelease = function() {
if (miniTime<500) {
gotoAndPlay("outlet");
trace("outlet1");
Try attaching your *.fla as it makes it far easier to see it rather than to try and copy your file from guessing.
Do you actually know what getTimer() is?
It is basically a timer that starts when you open the flash file and continues until you close the file and don't think it can be reset.
Trty not to put the fubnction inside of the button press, put it externally so can be called from anywhere or just make it part of the button press/release
Last edited by fruitbeard; 07-13-2016 at 02:46 AM.
The frame in question is 311.
The layer with the code is called "main button" inside a folder called "as".
The layers with the button movie clips are located in a folder called "base".
Here is the requested FLA - i couldn't upload before as i didnt realise there was a 300kb file size limit.
The frame in question is 311. Your code has now been put in place and functions without errors.
My code has been commented (greyed out) above.
The layer with the code is called "main button" inside a folder called "as".
The layers with the button movie clips are located in a folder called "base".
Basically if you press down the "joggleAnimation.button01" for 3 or 5 seconds you should be taken to the Create Profile section.
If you just quickly click (onRelease) you should skip through to Outlet which is a red screen.
For it to work as intended you should be able to click through all the modules over and over again and retain the same functionality. But previously the code only worked ONCE before breaking on revisiting the code(frame).
I hope it makes sense now, sorry for delay in getting FLA to you.
The errors were coming from the code not being formatted properly ???
this should fix the rrros although I still have no idea if it works for you, you will need to play with it as I have no idea whats going on with how you work it or whats its doing.
PHP Code:
stop();
var miniTime:Number = 0;
var intervalID:Number;
var started:Boolean = false;