Forum Discussion
lmsAPI Functionality in HTML5 Output
Hey all,
I've been searching through the forums and haven't been able to find anything solid. I'm using Storyline 360, outputting to both HTML5 and Flash to cover my bases, since the audience doesn't have dedicated machines that they are taking this from.
I'm relying heavily on external Javascript that I wrote, which I have tested thoroughly in the Flash version, and it works fine. But when it comes to the HTML5 version, it stops working. I've proven that I'm able to get into the Javascript functions, like I would expect, but it appears that lmsAPI is no longer available to the course.
Are there any similar functions to those of the lmsAPI functions in the HTML5 output?
Specifically, I'm looking for a way to do the following in HTML5:
- Get the StudentID from the LMS.
- Get the StudentName from the LMS.
- Manually call SetStatus("completed"); to pass a completion to the LMS on the last page of the course.
- PaulSchneiderCommunity Member
For #1 and #2 - I thought those are system variables built into Storyline - so no javascript is needed - but I could be wrong.
- AdamTrosperCommunity Member
For #1 and #2, I originally thought the same thing. For example, you should just be able to call
lmsAPI.GetStudentID()
to get the Student ID. However, this wasn't working when launching from HTML5 for some reason.After lots of testing and guessing, I found a solution. Turns out the reason why it wasn't working was because lmsAPI wasn't actually set up as a variable like it is when you use the Flash version. (Still not sure why this is, honestly.) But, you can use the following line to get the same functionality from lmsAPI, providedyou are actually launching from an LMS:
var lmsAPI = parent;
I actually ended up creating a function for myself to use, to error-check a little bit:
function findLMSAPI(win) {
// look in this window
if (win.hasOwnProperty("GetStudentID")) return win;
// all done if no parent
else if (win.parent == win) return null;
// climb up to parent window & look there
else return findLMSAPI(win.parent);
}
function someOtherFunc(){
var lmsAPI = findLMSAPI(this);
if(lmsAPI != null){
//do stuff
}
}- SteveGCommunity Member
Just found this post and it helped me solve an issue I was having after stripping the Flash from a Storyline 2 published course.
Many thanks
- ChrisPimCommunity Member
Hi,
I am using Moodle and Storyline 360
I have this code which works for Flash - get username. This populates a field in Storyline with variable %newName%
-----------------------
var player = GetPlayer();
var myName = lmsAPI.GetStudentName();
var array = myName.split(',');
var newName = array[1] + ' ' + array[0];player.SetVar("newName", newName);
--------------------------------
It used to work in Storlyine 2 for HTML5 but does not anymore with Storyline 360
How would I use your workaround with var lmsAPI = parent;
...in my code above so it works in HTML5 and Flash on Moodle?
Any help greatly appreciated.
Chris
- AdamTrosperCommunity Member
I would try updating it like this:
var player = GetPlayer();
var lmsAPI = parent;
var myName = lmsAPI.GetStudentName();
...This is going to work 99% of the time.
- ChrisPimCommunity Member
OK I tried this...
var player = GetPlayer();
var lmsAPI = parent;
var myName = lmsAPI.GetStudentName();
var array = myName.split(',');
var newName = array[1] + ' ' + array[0];
player.SetVar("newName", newName);With no success in Moodle. Any suggestions?
Chris
- AdamTrosperCommunity Member
I don't have much experience with Moodle, so I'm not sure what the problem would be. Are you publishing to SCORM or AICC? I've only tested my code with those tracking types.
The only other thing I could think of is that the lmsAPI is not the 'parent' object, but is instead up a parent level or two. That's when I would include the findLMSAPI function I wrote in the comment above instead, since it recursively looks up one level at a time, trying to find the lmsAPI. In which case, you would replace:
var lmsAPI = parent;
with:
var lmsAPI = findLMSAPI(this);
---
If this still isn't working, I would start using Developer Tools to determine the root of the problem.
- ChrisPimCommunity Member
Yes SCORM 1.2 HTML ouitput only
I tried:
-------------------
var player = GetPlayer();
var lmsAPI = findLMSAPI(this);
var myName = lmsAPI.GetStudentName();
var array = myName.split(',');
var newName = array[1] + ' ' + array[0];
player.SetVar("newName", newName);---------
Sadly still not working. Thanks for trying.
I know nothing abot Moodle really. What would I need to ask my Moodle developers to check and find out? This would be very helpful for the next step.
Chris
- AdamTrosperCommunity Member
In the code you tried, did you include the function from my previous post?
function findLMSAPI(win) {
// look in this window
if (win.hasOwnProperty("GetStudentID")) return win;
// all done if no parent
else if (win.parent == win) return null;
// climb up to parent window & look there
else return findLMSAPI(win.parent);
} - ChrisPimCommunity Member
OK so I tried this
---------------------
var player = GetPlayer();
function findLMSAPI(win) {
// look in this window
if (win.hasOwnProperty("GetStudentID")) return win;// all done if no parent
else if (win.parent == win) return null;// climb up to parent window & look there
else return findLMSAPI(win.parent);
}
var lmsAPI = findLMSAPI(this);
var myName = lmsAPI.GetStudentName();
var array = myName.split(',');
var newName = array[1] + ' ' + array[0];
player.SetVar("newName", newName);-----------------------------
And it works!
Thanks so much
Chris
- stephaniekalinkCommunity Member
Hi Chris, I try to do the same thing but I don't know where to define the variable newName...
i put a trigger to execute the js in the begining of my page
i put the variable in the list of variable and decide is a text variable
i put a text field il my page with the variable insidei published in html5
i have sl 360
and i tried in my lms and it doesn't work...could you help me ?
- AdamTrosperCommunity Member
Glad to hear that works! No problem!