Skip to main content
Dan Boccabella
Participant
August 12, 2019
Question

How do I trigger an event in Adobe Animate based on the current time?

  • August 12, 2019
  • 3 replies
  • 488 views

In short, I have a movie clip on the stage that has 12 frames (all with actionscript set to stop on each frame)

I would like a button to Get the Hour of the current time, and then go to that frame number.

ie, if it's 3,30, I want the movie clip to go to frame 3, i it's 11.00, I want themovie clip to go to frame 11 etc.

I can make events occur on 'direct information' I write in my code, but I can't work out how to set an event to occur as the result of a 'trace' - that being the 'get hour'.

Your help would be greatly appreciated as I am in the process of creating a 'time telling' game for my nephew.

Cheers

This topic has been closed for replies.

3 replies

Community Expert
August 12, 2019

I am not exactly sure what your trying to do, but try this tutorial. It's a timer and shows you how to trigger an event.

Timer Class in AS3

JoãoCésar17023019
Community Expert
Community Expert
August 12, 2019

Hi.

If I understood correctly what you want, your code could be something like this:

import flash.events.MouseEvent;

function hourToFrame(e:MouseEvent):void

{

    var date:Date = new Date();

    var hour:uint = date.hours; // 'date.hours' is an integer from 0 to 23

  

    // here we limit the value to the 12-hour clock format

    if (hour > 11)

        hour = hour - 12;

  

    numbers.gotoAndStop(hour); // 'numbers' is the 12 frames Movie Clip instance

}

button.addEventListener(MouseEvent.CLICK, hourToFrame);

Regards,

JC

jane-e
Community Expert
Community Expert
August 12, 2019

Hi

I moved your query from Adobe Creative Cloud to Adobe Animate where you will get a better response.

~ Jane