/**
* SCOBot
* This is meant to be used as a Flash->JavaScript communication class to take advantage
* of the SCOBot API used with SCORM 1.2/2004.
* @author Mark Statkus <
[email protected]>
* @usage
* import com.cybercussion.SCOBot;
* var SB:SCOBot = new SCOBot();
* @constructor
*/
package com.cybercussion {
import flash.external.ExternalInterface;
public class SCOBot {
public var mode:String = 'normal'; // make static's ?
private var JSCall:Function = ExternalInterface.call; // shortcut
public function SCOBot() {
// Check for ExternalInterface
if (ExternalInterface.available) {
mode = JSCall("scorm.getvalue", "cmi.mode");
//debug(mode)
} else {
// Throw error?
}
}
/**
* Debug
* Setting up a private way to push to the browser console
* @param msg {String}
*/
private function debug(msg:String) {
JSCall("SB.debug", msg);
}
/**
* Set Totals
* This will take in total objectives, interactions, score max and score min to aid
* in the calculation of a score rollup.
* @param data {Object}
* {
* totalInteractions: '0',
* totalObjectives: '0',
* scoreMin: '0',
* scoreMax: '0'
* }
* @returns {String} 'true' or 'false'
*/
public function setTotals(obj:Object):String {
return JSCall("SB.setTotals", obj);
}
/**
* Start Timer
* This will begin the timer based on the time provided by max_time_allowed. This depends on the time_limit_action.
*/
public function startTimer() {
JSCall("SB.startTimer");
}
/**
* Get Value
* Long hand short cut to get 1:1 SCORM values that don't have an API Wrapper.
* This is handy in situations where you just need to make a direct call.
* @param val {String}
* @returns {String} 'true' or 'false'
*/
public function getvalue(val:String):String {
return JSCall("SB.getvalue", val);
}
/**
* Set Value
* Long hand short cut to get 1:1 SCORM values that don't have an API Wrapper.
* This is handy in situations where you just need to make a direct call.
* @param ns {String} Namespace 'cmi.exit' etc ...
* @param val {String} Value 'normal' etc ...
* @returns {String} 'true' or 'false'
*/
public function setvalue(ns:String, val:String):String {
return JSCall("SB.setvalue", ns, val);
}
/**
* Get Mode
* Returns 'browse', 'normal', or 'review' so you may handle how the
* content behaves, based on how the student / teacher entered the SCO.
* returns {String}
*/
public function getMode():String {
return JSCall("SB.getMode");
}
/**
* Get Entry
* This will return the type ('ab-initio', 'resume' or '')
* Based on if the student is here for the first time, or returning.
* @returns {String}
*/
public function getEntry():String {
return JSCall("SB.getEntry");
}
/**
* Get Bookmark
* This will return the local snapshot, but will stay in sync with sets of cmi.location
* @returns {String} Bookmark (100 chars 1.2 and 1000 chars in 2004
*/
public function getBookmark():String {
return JSCall("SB.getBookmark");
}
/**
* Progress
* Hooks to Private method used possibly elsewhere in this API
* cmi.score.scaled,
* cmi.success_status,
* cmi.completion_status,
* cmi.progress_measure
* @returns {Object}
*/
public function progress():Object {
return JSCall("progress");
}
/**
* Set Suspend Data By Page ID
* This will set the suspend data by id (could be a page ID as long as its unique)
* Suspend data is a 64,000 character string. In this case it will be a JSON Object that
* freely converts to a JSON String or Object.
* Now you could require that the end user have a id in their data object, or in this case keep it
* separate for search ability. Either way you'll have to verify they are passing a id.
* I've opted to make them pass the ID. I'm also opting to keep this as a object instead of
* just a page array. You may want to add more things to suspend data than just pages.
* Example structure of this:
* {
* sco_id: '12345',
* name: 'value',
* pages: [
* {
* id: 1,
* title: 'Presentation',
* data: {data object for a page}
* },
* {
* id: 2,
* title: 'Match Game',
* data: {data object for a page}
* }
* ]
* };
* Calling commit will still be needed to truly save it.
* @param id {*}
* @param title {String}
* @param data {Object}
* @returns {String}
*/
public function setSuspendDataByPageID(id, title:String, data:Object):String {
return JSCall("SB.setSuspendDataByPageID", id, title, data);
}
/**
* Get Suspend Data By Page ID
* This will get the suspend data by id
* @param id {*}
* @returns {*} object, but false if empty.
*/
public function getSuspendDataByPageID(id) {
return JSCall("SB.getSuspendDataByPageID", id);
}
/**
* Set Interaction
* This will set an interaction based on Journaling or State.
* Parameter for choosing a version is located in the defaults.
* Note: If you are recording Journaling make sure its something the LMS
* supports or plans to support, or your just blimping out your interactions array
* for no reason.
* You may ask what is "real(10,7)". This is a binary floating point with a precision up to 7 characters to the right of the decimal.
* Example Data Object:
* {
* id: '1', // 4000 chars
* type: 'true-false', // (true-false, choice, fill-in, long-fill-in, matching, performance, sequencing, likert, numeric, other)
* objectives: [
* {
* id: '12'
* }
* ],
* timestamp: 'expects date object when interaction starts', // second(10,0) Pass a date object
* correct_responses: [
* {
* pattern: '' // depends on interaction type
* }
* ],
* weighting: '1',
* learner_response: 'true',
* result: 'correct', // (correct, incorrect, unanticipated, neutral, real (10,7) )
* latency: 'expects date object after interaction is done', // second(10,2)
* description: "The question commonly" // 250 chars
* }
* @param data {Object} Interaction Object from SCORM
* @returns {String} 'true' or 'false'
*/
public function setInteraction(obj:Object):String {
return ExternalInterface.call("SB.setInteraction", obj);
}
/**
* Get Interaction
* Returns the full Interaction object
* @param id {String}
* @returns {*} object or string 'false'
* {
* id: '1', // 4000 chars
* type: 'true-false', // (true-false, choice, fill-in, long-fill-in, matching, performance, sequencing, likert, numeric, other)
* objectives: [
* {
* id: '12'
* }
* ],
* timestamp: 'expects date object when interaction starts', // second(10,0) Pass a date object
* correct_responses: [
* {
* pattern: '' // depends on interaction type
* }
* ],
* weighting: '1',
* learner_response: 'true',
* result: 'correct', // (correct, incorrect, unanticipated, neutral, real (10,7) )
* latency: 'expects date object after interaction is done', // second(10,2)
* description: "The question commonly" // 250 chars
* }
* or
* 'false'
*/
public function getInteraction(id:String) {
return JSCall("SB.getInteraction", id);
}
/**
* Set Objective
* Sets the data for the scorm objective. ID's have to be set first and must be unique.
* Example data object
* {
* id: '1', // 4000 chars
* score: {
* scaled: '0', // real(10,7) *
* raw: '0',
* min: '0',
* max: '0'
* }
* success_status: 'failed', // (passed, failed, unknown)
* completion_status: 'incomplete', // (completed, incomplete, not attempted, unknown)
* progress_measure: '0', // real(10,7)
* description: 'This is the objective' // 250 Chars
* }
* @param data {Object} Objective object from SCORM
* @returns {String} 'true' or 'false'
*/
public function setObjective(obj:Object):String {
return JSCall("SB.setObjective", obj);
}
/**
* Get Objective
* Returns the Objective object by ID
* @param id {String}
* @returns {*} object or string 'false'
* {
* id: '1', // 4000 chars
* score: {
* scaled: '0', // real(10,7) *
* raw: '0',
* min: '0',
* max: '0'
* }
* success_status: 'failed', // (passed, failed, unknown)
* completion_status: 'incomplete', // (completed, incomplete, not attempted, unknown)
* progress_measure: '0', // real(10,7)
* description: 'This is the objective' // 250 Chars
* }
* or
* 'false'
*/
public function getObjective(id:String) {
return JSCall("SB.getObjective", id);
}
/**
* Set Comment From Learner
* This will set the comment, location and time the student made a comment
* @param msg {String} comment
* @param loc {String} location
* @param date {Object} New Date object (for timestamp)
* @return {String}
*/
public function setCommentFromLearner(msg:String, loc:String, date:Object) {
return JSCall("SB.setCommentFromLearner", msg, loc, date);
}
/**
* Grade It
* This method will set cmi.score.scaled, cmi.success_status, and cmi.completion_status. This is for situations
* where you are doing simple scoring, with NO objectives or interactions.
* Prereq for this would be to have passed in scaled_passing_score and completion_threshold in to SCOBot
* If none are provided it will default to 'passed' and 'completed'
* Special Note: If you are using Objectives, Interactions and set the totals, you do not need to use this method.
* For setting the student to 100% Score, and passed, see happyEnding
* @return {String} 'true' or 'false'
*/
public function gradeIt():String {
return JSCall("SB.gradeIt");
}
/**
* Happy Ending
* This will auto-score the student to passed, completed, and scored
* @return {String}
*/
public function happyEnding():String {
return JSCall("SB.happyEnding");
}
/**
* Commit
* This will commit the data stored at the LMS Level to the backend. Please use sparingly.
* @returns {String} 'true' or 'false'
*/
public function commit():String {
return JSCall("SB.commit");
}
/**
* Suspend
* This will suspend the SCO and ends with terminating. No data can be saved after this.
* Student desires to return to this later.
* @returns {String} 'true' or 'false'
*/
public function suspend():String {
return JSCall("SB.suspend");
}
/**
* Finish
* This will set success status, exit and completion. No data can be saved after this.
* This is like turning in your homework.
* @returns {String} 'true' or 'false'
*/
public function finish():String {
return JSCall("SB.finish");
}
/**
* Timeout
* This will set success status, exit and completion. No data can be saved after this.
* Used in a situation where max_time_allowed may end the session.
* @returns {String} 'true' or 'false'
*/
public function timeout():String {
return JSCall("SB.timeout");
}
}
}
0 commit comments