Assign current timeline name to a variable


#1

Hello, I’m building a menu with relative timelines and I need a variable to track some of the timelines. I’m not very familiar with JavaScript.

How can I assign the current timeline name to a variable ? I’ve tried something like this :

var nowTime = “hypeDocument.currentTimelineName()”;

But it’s clearly not working…

Any suggestions ? Thanks !


(stephen) #2

The variable needs to have global scope if you want to access it in another function. Something like this should work:

window.nowTime = hypeDocument.currentTimelineName();

#3

Thanks for the fast reply !

The solution doesn’t seems to work for now.

Does the API “hypeDocument.currentTimelineName()” really exist ? It was kind of a guess, deduced from the other API I found in the Hype Documentation.

For the global variable, does I have to declare it before it’s first use (on Scene load) ? Should I write :

var window.nowTime = hypeDocument.currentTimelineName();

Thanks


(Warren Adams-Ockrassa) #4

You’ll want to declare the name yourself. You can do that in the ‘Timeline Actions’ bit of the main window, running a JavaScript you create. You’ll have to define a new JS for each timeline you want to name.

General form would be something like:

function whateverYouWantToCallIt(hypeDocument, element, event) {
  window.currentTimeLine = 'Whatever you want to call it';
}

What this does is populate a global variable, by omitting the ‘var’ keyword prior to the declaration. (The term ‘window’ specifies that the scope of this variable is across the current browser window that contains the Hype document.) This variable will then be accessible from anywhere within your current Hype document.

To find out what that variable contains, you’d access it from anywhere else in your document, maybe with a button action first just to be sure; assign something like this to an onClick event:

function whereAmI(hypeDocument, element, event) {
  alert( currentTimeLine );
}

What you’re wanting to do - determine what the current timeline’s name is through JavaScript - is not something Hype allows, as far as I know. You have to put that information into a variable first.


(stephen) #5

Ha, wow, I was focused on the Global Variable part and didn’t pay attention to the Hype API part. There is a similar api for Scenes (hypeDocument.currentSceneName()), but there is no hypeDocument.currentTimelineName(). Hype supports playing multiple timelines at the same time, so the best we could do is return the list of timelines currently playing (but we don’t).

@warrenao’s solution is your best bet or you could loop through all possible timelines checking hypeDocument.isPlayingTimelineNamed(‘timelineName’).