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:

  1. Get the StudentID from the LMS.
  2. Get the StudentName from the LMS.
  3. Manually call SetStatus("completed"); to pass a completion to the LMS on the last page of the course.
139 Replies
Adam Trosper

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
}
}
Chris Pim

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

Adam Trosper

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.

Chris Pim

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

Adam Trosper

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);
}
Chris Pim

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

Adam Trosper

James - My guess is that the variable lmsAPI isn't equal to parent, but rather parent.parent, or something like that.  If you use the findLMSAPI function (as I helped Chris with earlier in this thread), that might work.  I don't personally work with Moodle, but Chris was having a similar problem with Moodle.

Let us know if that works!