Forum Discussion
SL3 Javascript GetPlayer() function not defined in HTML5 output
It seems like there's two different issues going on.
1) GetPlayer() does not exist yet at the point you're trying to use it
Where you use the GetPlayer() can cause issues. There's a difference between putting the code inside a trigger in Storyline vs. directly in user.js or an external file. This may or may not apply to your issue but:
user.js is loaded early (this is a change from SL2) in the story_html5.html file (around line 105), meanwhile the app.min.js is loaded at the bottom of the file.
This was a change from SL2. Not sure why this change was introduced but it causes issues.
That means if you put GetPlayer() directly in user.js (even if you're using jQuery and wait until the document loaded), you can get an error because GetPlayer() does not exist yet at that point. Since the file loads earlier than the player is created, it returns an error.
You can test the difference by opening the story_html5.html file and move this line to the bottom.
<script SRC="story_content/user.js" TYPE="text/javascript"></script>
However, this is a manual effort after each publish. If you put the code inside a trigger in SL, it would run. If that's the case, you know the problem was calling it too early.
2. The iframe discussion
The only time I used parent.GetPlayer() when my JS code was inside a webobject and I had to access the player from an iframe.
You can check if GetPlayer is a function by using:
if (typeof GetPlayer === 'function') {...}
if (typeof parent.GetPlayer === 'function') {...}
Related Content
- 6 months ago