Hello,
Just looking to see if someone could give this a fresh look. It’s an external AS file that I just converted from AS2 to AS3 and am getting this error -
ReferenceError: Error #1065: Variable root is not defined.
at LMS/getlasterrorLMS()
at LMS/initializeLMS()
Here’s the Script. Thanks!!!
package{
import flash.system.fscommand;
public class LMS{
public var m_bInit:Boolean;
public var m_bValues:Boolean;
public var m_strStudentName:String;
public var m_strStudentId:String;
public var m_strCredit:String;
public var m_strComments:String;
public var m_nScore:Number;
public var m_nSession:Number;
public var m_nLastError:Number;
public function LMS(){
m_bInit = false;
m_bValues = false;
m_strStudentName = "<No Name>";
//m_strStudentName = "";
m_strStudentId = "<No ID>";
m_strCredit = "<No Credit>";
m_strComments = "<No Comment>";
m_nScore = 0;
m_nSession = 0;
m_nLastError = 0;
trace("LMS function ran");
}
public function initializeLMS(){
if (!m_bInit){
fscommand("LMSInitialize");
trace("LMSInitialize() returned: "+ getlasterrorLMS() + "
");
m_bInit = true;
trace("LMS Initialize function run");
}
}
public function finishLMS(){
if (m_bInit){
fscommand("LMSFinish");
trace("LMSFinish() returned: "+ getlasterrorLMS() + "
");
m_bInit = false;
}
}
public function getlasterrorLMS() : Number{
var args = "cmi," + "get_error";
fscommand("LMSGetLastError", args);
return root.get_error;
}
public function setBrowsed(){
if (m_bInit){
var args = "cmi.core.lesson_status," + "browsed";
fscommand("LMSSetValue", args);
trace("LMSSetValue(cmi.core.lesson_status) returned: "+ getlasterrorLMS() + "
");
}
else
{
trace("
ERROR: LMS not Initialized!!!
");
}
}
public function setScoreLMS(score:Number){
if (m_bInit)
{
//score = root.quiz.Player1Stats.m_nCat1Correct
var args = "cmi.core.score.raw," + score;
fscommand("LMSSetValue",args);
trace("LMSSetValue(cmi.core.score.raw) returned: "+ getlasterrorLMS() + "
");
}
else
{
trace("
ERROR: LMS not Initialized!!!
");
}
}
public function setSessionLMS(session:Number){
if (m_bInit)
{
//score = root.quiz.Player1Stats.m_nCat1Correct
var args = "cmi.core.session_time," + session;
fscommand("LMSSetValue",args);
trace("LMSSetValue(cmi.core.score.raw) returned: "+ getlasterrorLMS() + "
");
}
else
{
trace("
ERROR: LMS not Initialized!!!
");
}
}
public function setCompleteLMS() {
if (m_bInit)
{
fscommand("LMSSetValue","cmi.core.lesson_status,completed");
trace("LMSSetValue(cmi.core.lesson_status) returned: "+ getlasterrorLMS() + "
");
}
else
{
trace("
ERROR: LMS not Initialized!!!(via complete button)
");
}
}
public function setIncompleteLMS()
{
if (m_bInit)
{
fscommand("LMSSetValue","cmi.core.lesson_status,incomplete");
trace("LMSSetValue(cmi.core.lesson_status) returned: "+ getlasterrorLMS() + "
");
}
else
{
trace("
ERROR: LMS not Initialized!!!(via incomplete button)
");
}
}
public function getvaluesLMS() {
if (m_bInit)
{
var args = "cmi.core.student_name," + "get_name";
fscommand("LMSGetValue", args);
trace("LMSGetValue(cmi.core.student_name) returned: "+ getlasterrorLMS() + "
");
m_strStudentName = root.get_name;
args = "cmi.core.student_id," + "get_id";
fscommand("LMSGetValue", args);
trace("LMSGetValue(cmi.core.student_id) returned: "+ getlasterrorLMS() + "
");
m_strStudentId = root.get_id;
args = "cmi.core.credit," + "get_credit";
fscommand("LMSGetValue", args);
m_strCredit = root.get_credit;
trace("LMSGetValue(cmi.core.credit) returned: "+ getlasterrorLMS() + "
");
args = "cmi.comments_from_lms," + "get_comment";
fscommand("LMSGetValue", args);
trace("LMSGetValue(cmi.comments_from_lms) returned: "+ getlasterrorLMS() + "
");
m_strComments = root.get_comment;
// Try 2 to make the score work
args = "cmi.core.score.raw," + "get_score";
fscommand("LMSGetValue", args);
trace("LMSGetValue(cmi.core.score.raw) returned: "+ getlasterrorLMS() + "
");
m_nScore = root.get_score;
args = "cmi.core.session_time" + "get_session";
fscommand("LMSGetValue", args);
trace("LMSGetValue(cmi.core.session_time) returned: "+ getlasterrorLMS() + "
");
m_nSession = root.get_session;
m_bValues = true;
}
else
{
trace("
ERROR: LMS not Initialized!!!
");
}
}
public function getStudentNameLMS() : String{
if (!m_bValues)
getvaluesLMS();
return m_strStudentName;
}
public function getStudentIdLMS() : String{
if (!m_bValues)
getvaluesLMS();
return m_strStudentId;
}
function getCreditLMS() : String{
if (!m_bValues)
getvaluesLMS();
return m_strCredit;
}
function getScoreLMS() : Number{
if (!m_bValues)
getvaluesLMS();
return m_nScore;
}
function getSessionLMS() : Number{
if (!m_bValues)
getvaluesLMS();
return m_nSession;
}
function getCommentsLMS() : String{
if (!m_bValues)
getvaluesLMS();
return m_strComments;
}
}
}