Javascript& Moodle中的Scorm 1.2

时间:2011-03-10 11:55:49

标签: javascript api scorm

我从flash发布了html,这是flash + scorm 1.2  我的html包含.swf作为播放器 .swf播放器将有来自此SWF的菜单和学生导航页面,因此当学生到达最后一页时,应该完成课程的状态,,,但是我发生了什么? 当第一次学生访问课程并关闭它时>>课程的状态是不完整的,这是正确的,,,,但是第二次打开课程时状态变为完成,第三次更改为不完整。第4次更改完成,我无法理解究竟发生了什么是我使用的JavaScript函数::

var g_nFindAPITries = 0;
var g_objAPI = null;
var g_bInitDone = false;
var g_bFinishDone = false;
var g_bSCOBrowse = false;
var g_dtmInitialized = new Date(); // will be adjusted after initialize
var g_bMasteryScoreInitialized = false;
function AlertUserOfAPIError(strText) {
    if (g_bShowApiErrors) {
        var s = strText + "\n\n" + g_strDisableErrorMsgs;
        if (!confirm(s)){
            g_bShowApiErrors = false
        }
    }
}

function ExpandString(s){
    var re = new RegExp("%","g")
    for (i = arguments.length-1; i > 0; i--){
        s2 = "%" + i;
        if (s.indexOf(s2) > -1){
            re.compile(s2,"g")
            s = s.replace(re, arguments[i]);
        }
    }
    return s
}
function FindAPI(win) {
    while ((win.API == null) && (win.parent != null) && (win.parent != win)) {
        g_nFindAPITries ++;
        if (g_nFindAPITries > 500) {
            AlertUserOfAPIError(g_strAPITooDeep);
            return null;
        }
        win = win.parent;
    }
    return win.API;
}
function APIOK() {
    return ((typeof(g_objAPI)!= "undefined") && (g_objAPI != null))
}
function SCOInitialize() {
var err = true;
    if (!g_bInitDone) 
        {


        if ((window.parent) && (window.parent != window)){
            g_objAPI = FindAPI(window.parent)
        }
        if ((g_objAPI == null) && (window.opener != null))  {
            g_objAPI = FindAPI(window.opener)
        }
        if (!APIOK()) {
            AlertUserOfAPIError(g_strAPINotFound);
            err = false
        } 
                else
                {
            err = g_objAPI.LMSInitialize("");
            if (err == "true") 
                         {
                g_bSCOBrowse = (g_objAPI.LMSGetValue("cmi.core.lesson_mode") == "browse");
                if (!g_bSCOBrowse)
                                   {
                    if (g_objAPI.LMSGetValue("cmi.core.lesson_status") == "not attempted")
                                           {
                        err = g_objAPI.LMSSetValue("cmi.core.lesson_status","incomplete")
                       }
                   }
            }
                        else 
                        {
                AlertUserOfAPIError(g_strAPIInitFailed)
            }
        }
          if (typeof(SCOInitData) != "undefined") 
                   {
            // The SCOInitData function can be defined in another script of the SCO
            SCOInitData()
           }
        g_dtmInitialized = new Date();
    }
    g_bInitDone = true;

    return (err + "") // Force type to string
}
function SCOFinish() {
    if ((APIOK()) && (g_bFinishDone == false)) {
        SCOReportSessionTime()
        if (g_bSetCompletedAutomatically){
            SCOSetStatusCompleted();
        }
        if (typeof(SCOSaveData) != "undefined"){
            // The SCOSaveData function can be defined in another script of the SCO
            SCOSaveData();
        }
        g_bFinishDone = (g_objAPI.LMSFinish("") == "true");
    }
    return (g_bFinishDone + "" ) // Force type to string
}
// Call these catcher functions rather than trying to call the API adapter directly
function SCOGetValue(nam)           {return ((APIOK())?g_objAPI.LMSGetValue(nam.toString()):"")}
function SCOCommit()                    {return ((APIOK())?g_objAPI.LMSCommit(""):"false")}
function SCOGetLastError()      {return ((APIOK())?g_objAPI.LMSGetLastError():"-1")}
function SCOGetErrorString(n)   {return ((APIOK())?g_objAPI.LMSGetErrorString(n):"No API")}
function SCOGetDiagnostic(p)    {return ((APIOK())?g_objAPI.LMSGetDiagnostic(p):"No API")}
//LMSSetValue is implemented with more complex data management logic below
var g_bMinScoreAcquired = false;
var g_bMaxScoreAcquired = false;
// Special logic begins here
function SCOSetValue(nam,val){
    var err = "";
    if (!APIOK()){
            AlertUserOfAPIError(g_strAPISetError + "\n" + nam + "\n" + val);
            err = "false"
    } else if (nam == "cmi.core.score.raw") err = privReportRawScore(val)
    if (err == ""){
            err = g_objAPI.LMSSetValue(nam,val.toString() + "");
            if (err != "true") return err
    }
    if (nam == "cmi.core.score.min"){
        g_bMinScoreAcquired = true;
        g_nSCO_ScoreMin = val
    }
    else if (nam == "cmi.core.score.max"){
        g_bMaxScoreAcquired = true;
        g_nSCO_ScoreMax = val
    }
    return err
}

,这是在正文html

<body bgcolor="#ffffff" onload="SCOInitialize()" onunload="SCOFinish()" onbeforeunload="SCOFinish()" >

所以为什么它的交换时间不完整和完成,我试着设置值 cmi.core.lesson_status但它不起作用

1 个答案:

答案 0 :(得分:0)

我会围绕g_bSetCompletedAutomatically变量集中调试。在其上设置一个监视,并在退出课程时查看代码是否正在调用SCOSetStatusCompleted()。另外,如果没有看到您提供的示例中g_bSetCompletedAutomatically的原始值或SCOSetStatusCompleted()的代码,那么很难再向您提供方向。但是,这显示您将lesson_status设置为已完成,因为我没有看到任何其他代码将其设置为完成代码中的任何其他位置。

对于课程完成时的问题,您可能想要查看的另一件事是SCOInitialize(),因为这是我看到您的代码设置lesson_status的唯一地方。您需要查看lesson_mode是否正在返回浏览,而lesson_status正在返回未尝试,以查看该段代码是否正在将课程设置为不完整。此外,当课程处于浏览模式时,RTE和LMS应该忽略和SetValue调用。

g_bSCOBrowse = (g_objAPI.LMSGetValue("cmi.core.lesson_mode") == "browse");
if (!g_bSCOBrowse)
    {
        if (g_objAPI.LMSGetValue("cmi.core.lesson_status") == "not attempted")
        {
            err = g_objAPI.LMSSetValue("cmi.core.lesson_status","incomplete")
        }
    }