Skip to main content
Inspiring
July 9, 2018
Answered

Timer to go back to frame 1 and play

  • July 9, 2018
  • 1 reply
  • 924 views

Hi,

I have already posted a similar question to this one but wasn't able to solve my problem yet.

I have a few applications for museum kiosks that I want to restart after a few time without any touch.

I was using an AS3 that isn't working. It looks like it's working but after a few minutes it goes wierd and goes back to frame 1 even if there is someone touching the screen.

The AS3 I was using is:

var myTimer:Timer = new Timer(30000, 1);

myTimer.addEventListener(TimerEvent.TIMER, timerHandler);

myTimer.start();

 

stage.addEventListener(MouseEvent.MOUSE_MOVE, moveMouse);

 

function moveMouse(evt:MouseEvent):void {

    myTimer.reset();

    myTimer.start();

}

 

function timerHandler(evt:TimerEvent):void {

    gotoAndPlay(1);

}

Thank you all

AB

    This topic has been closed for replies.
    Correct answer JoãoCésar17023019

    Thank you for your help,

    Here is the original file, probably with many errors, maybe you can find what I am doing wrong .

    [link removed by a moderator]

    Thank you

    AB


    Hi again!

    Thanks for sharing your FLA.

    I think the problem happens because everytime the timeline is sent to frame 1, another timer is set, started and a mouse listener is added to the stage.

    In this way, things get executed more than once.

    What you can do is to run the timer intialization code only when the app is launched.

    Like this:

    stage.displayState = StageDisplayState.FULL_SCREEN;

    if (!this.hasBegun)

    {

        var myTimer:Timer = new Timer(30000, 1);

        myTimer.addEventListener(TimerEvent.TIMER, timerHandler);

        myTimer.start();

        stage.addEventListener(MouseEvent.MOUSE_MOVE, moveMouse);

        this.hasBegun = true;

    }

    function moveMouse(evt:MouseEvent):void

    {

        myTimer.reset();

        myTimer.start();

    }

    function timerHandler(evt:TimerEvent):void

    {

        gotoAndPlay(1);

    }

    Please test and see if this works.

    P.S.: Probably is a good idea to remove the link to your app. Is up to you.

    Regards,

    JC

    1 reply

    JoãoCésar17023019
    Community Expert
    Community Expert
    July 9, 2018

    Hi.

    Can you share your FLA? There's no problem if you have to use placeholders and/or just part of the content.

    Regards,

    JC

    ATGBAuthor
    Inspiring
    July 16, 2018

    Hi,

    I didn’t note this answer

    Are you still available to help me? How can I share my file with you?

    Thank you

    Ana

    JoãoCésar17023019
    Community Expert
    Community Expert
    August 6, 2018

    Thank you. That makes sense

    I will try just now and let you know if it is working.

    AB

    PS -  I already deleted the linked folder, is there a way of delete the link from the forum?... Thank you again.


    Nice!

    And I removed the link for you.