A Flash Developer Resource Site

Results 1 to 10 of 10

Thread: Dual function button - onPress and onRelease combination - code breaks on 2nd visit

  1. #1
    Junior Member
    Join Date
    Jul 2016
    Posts
    11

    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");

    } else {
    gotoAndPlay("createProfile");
    trace("createProfile1");

    }
    clearInterval(intervalID);
    miniTime = 0;
    };

  2. #2
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    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.

  3. #3
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    Without seeing your file or anything else, maybe this might be more to the mark, I am guessing of course.

    I need to go out for a fair few hours so somebody else might step in.

    PHP Code:
    stop();

    var 
    miniTime:Number;
    var 
    intervalID:Number;

    var 
    started:Boolean false;

    joggleAnimation.button01.onPress = function()
    {
        if (
    started == false)
        {
            
    miniTime 0;
            
    intervalID setInterval(callback500);
            
    started true;
        }
    };

    function 
    callBack()
    {
        
    miniTime += 10;
    }

    joggleAnimation.button01.onRelease = function()
    {
        if (
    miniTime 500)
        {
            
    gotoAndPlay("outlet");
            
    trace("outlet1");
        }
        else
        {
            
    clearInterval(intervalID);
            
    miniTime 0;
            
    started false;
            
    gotoAndPlay("createProfile");
            
    trace("createProfile1");
        }
    }; 

  4. #4
    Junior Member
    Join Date
    Jul 2016
    Posts
    11
    Hi Fruitbeard,

    Many thanks for coming to my assistance so quickly - again!

    The job is NDA so do you have a personal email i could send it to?
    In the meantime I will try the code you just posted.

    Many thanks,
    Guy

  5. #5
    Junior Member
    Join Date
    Jul 2016
    Posts
    11
    Hi Fruitbeard,

    I just replaced with your code but on publish i am getting a "Compile error"
    "Line 3 identifier expected"

    best regards,

    Guy

  6. #6
    Junior Member
    Join Date
    Jul 2016
    Posts
    11
    Hi Fruitbeard,


    Here is the 'unbranded' editable *fla file.
    https://we.tl/JBbvXAKhXa

    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".

    I hope that helps.

    Thanks once again.

    cheers

  7. #7
    Junior Member
    Join Date
    Jul 2016
    Posts
    11
    Can anyone help with or add to the above. it would be great if i could find a 'fix' in the next 24 hours?

    many thanks

  8. #8
    Junior Member
    Join Date
    Jul 2016
    Posts
    11

    Here is the requested FLA

    Morning Fruitbeard,

    thanks again for your help.

    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.

    Many thanks in advance.
    Attached Files Attached Files

  9. #9
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    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;

    joggleAnimation.button01.onPress = function()
    {
        if (
    started == false)
        {
            
    miniTime 0;
            
    intervalID setInterval(callBack500);
            
    started true;
        }
    };

    function 
    callBack()
    {
        
    miniTime += 10;
    }

    joggleAnimation.button01.onRelease = function()
    {
        if (
    miniTime 500)
        {
            
    gotoAndPlay("outlet");
            
    trace("outlet");
        }
        else
        {
            
    clearInterval(intervalID);
            
    miniTime 0;
            
    started false;
            
    gotoAndPlay("createProfile");
            
    trace("createProfile1");
        }
    }; 

  10. #10
    Junior Member
    Join Date
    Jul 2016
    Posts
    11
    Hi,

    Thanks for your reply.

    Yes the code does not seem to throw up any errors now, although it doesn't seem to do what i want it to do.

    Did you get a chance to look at the FLA file attachment with the AS on frame 311?

    Best,
    Guy

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center