Reputation: 39
This might be a silly question. But how can I call a function (to execute) from a class to the timeline.
For example, I have the class "Test" and I want to execute the function "Next" on the timline (which it is only a function to show next slide).
Hope you understand what I'm trying to do.
Thank you!
Upvotes: 0
Views: 36
Reputation: 5255
The best practice for communication (in this scenario!) is to use Event
s.
Test
and registers an
event listener.Test
dispatch an Event
.Event
will be executed.Please take a look at this question that wants to send additional information to the main timeline. In your case, you do not need a custom Event
, because you do not want to send any information along. You only want to communicate the occurrence of the event. You can put that information into the type of the event. an example for a dispatch could look like this:
dispatchEvent(new Event("next"));
Creating a custom class allows you to put that String
literal that describes the type into a constant, which prevents errors caused by accidentally misspelling the type. That might be a reason to create a custom Event
class anyway, even only for the sake of a place to put those constants.
dispatchEvent(new PresentationEvent(PresentationEvent.NEXT));
Again, this would do the same as the previous line. this is also covered in the other question and the answer to it. Please take a look.
Upvotes: 1