scorm.get("cmi.location") help

342 views
Skip to first unread message

baldTrainer

unread,
Nov 10, 2009, 10:03:31 AM11/10/09
to eLearning Technology and Development
So, I'm working on bookmarking our courses and have come a long way.
Everything is working great in that the pages get 'set' as they ought;
however, upon reentry into a course, it breaks...and I can't figure
this one out for the life of me. Here's the basic setup:

var page:String = the current SWF being viewed
cmi.location is set to the page variable (works like a charm)

In layman's terms, what I'm trying to do (in AS3) is...

if (cmi.location is true...get.cmi location)
{
find 'page' (i.e. the proper SWF in the XML document)
load that page
}

The current result upon reentry into the course is a blank canvas.
When I debug the lesson, it shows that everything is being 'set'
correctly. Anybody out there done something like this in AS3? If so,
can you help??

Many thanks!!

Ryan Meyer

unread,
Nov 11, 2009, 10:24:25 AM11/11/09
to elearning-technolo...@googlegroups.com
It would probably be more helpful if you could post actual code snippets instead of the pseudo-code you have here. The devil is in the details! For example the value for cmi.location will never be true, as it's a string property not a boolean. Also, when you debug are you seeing that you're able to read the cmi.location property correctly? Maybe your code for checking and reading the property is correct, but the error is in your code that loads in the appropriate swf.

-Ryan

Ryan Wale

unread,
Nov 11, 2009, 3:22:59 PM11/11/09
to elearning-technolo...@googlegroups.com
Here's the code with some notes that explains what's going on...
 
Setting the location seems to work perfectly; however, the call to load the ‘set’ file is breaking on me.  It starts back at page 1 rather than at the ‘set’ spot.
 

//Next Button function

mc_nextBtn.addEventListener (MouseEvent.CLICK, goForward);

function goForward (e:MouseEvent):void

{

                page = xmlData.contentItem[currentContentItem + 1].toString();//this line stores the external swf in the page variable (var page:String)

                scorm.set ("cmi.location", page);//setting the external swf (appears in SCORM debugger as ‘swfs/xyz.swf’)

}

 

function xmlLoaded (e:Event):void

{

                xmlData = XML(e.target.data);

                bookmark = scorm.get("cmi.location");

                if (bookmark == "true")//if there is a stored value, do the following

                {

                                coursePages = new URLRequest(xmlData.contentItem[page].toString());//calling to the page variable (incorrectly obviously) in hopes to load it…instead, page 1 appears.

                                coursePageLoader.load(coursePages);

                                coursePageLoader.x = 0;

                                coursePageLoader.y = 75;

                                totalPages.text = "Page " + pageNumber + " of " + xmlData.contentItem.length();

                }

                else//load it from page 1

                {

                                loadCoursePage ();

                                trace ("bookmark is false");

                }

}

 

//this is the typical load command in which it starts at page 1

function loadCoursePage ():void

{

                coursePages = new URLRequest(xmlData.contentItem[currentContentItem].toString());

                coursePageLoader.load (coursePages);

                coursePageLoader.x = 0;

                coursePageLoader.y = 75;

                totalPages.text = "Page " + pageNumber + " of " + xmlData.contentItem.length();

}



Ryan Meyer

unread,
Nov 11, 2009, 3:36:47 PM11/11/09
to elearning-technolo...@googlegroups.com
The bookmark variable that you get from calling scorm.get("cmi.location") is going to be the same thing that you passed in to scorm.set("cmi.location"). You're not passing in the value "true". You're passing in the value "swfs/xyz.swf" so that's what you're going to get back.

Change the code in your xmlLoaded() function to look more like this:

if (bookmark != null && bookmark != "")//I'm not sure how your library handles non-set values, either null or empty string

                {

                                coursePages = new URLRequest(bookmark);


I'm also not sure where you're initializing and updating the "currentContentItem" variable that you're using to keep track of the current index, but it would probably make more sense for you to store THAT value in cmi.location. That way you'll be able to re-set it back to the proper index when you come back into the course, rather than trying to reverse engineer what it should be based on the actual URL of the swf. If you do that, then your goForward() function would look like:

function goForward (e:MouseEvent):void

{

                page = xmlData.contentItem[currentContentItem + 1].toString();//this line stores the external swf in the page variable (var page:String)

                scorm.set ("cmi.location", currentContentItem + 1);//setting the external swf (appears in SCORM debugger as ‘swfs/xyz.swf’)

}


Then your xmlLoaded() function would look like:



function xmlLoaded (e:Event):void

{

                xmlData = XML(e.target.data);

                bookmark = scorm.get("cmi.location");

                if (bookmark != null && bookmark != "")//if there is a stored value, do the following

                {

                                coursePages = new URLRequest(xmlData.contentItem[bookmark ].toString());



Hope that helps!
Ryan

Ted Powers

unread,
Nov 11, 2009, 4:13:19 PM11/11/09
to elearning-technolo...@googlegroups.com
Are yo uusing SCORM 1.2 or 2004?
The cmi you are using looks like 2004.
If you are using 1.2 you should be sending
cmi.core.lesson_location

Ryan Wale

unread,
Nov 12, 2009, 8:33:10 AM11/12/09
to elearning-technolo...@googlegroups.com
Thanks so much for the help.  I understand what you're saying in that I ought to use the "currentContentItem" variable within the "cmi.location"; however, that variable is a number, not a string.  Below is the code that might give a better explanation as to why I'm using it. 
 
With the current setup (i.e. coursepages = new URLRequest(bookmark)), the set page loads upon reentry; however, when you press the next button, it goes back to page 1.  I'm assuming that if I setup the "cmi.location" with "currentContentItem", this problem would rectify itself.  Is there a way to use a number variable within "cmi.location"?
 
//Next Button function
mc_nextBtn.addEventListener (MouseEvent.CLICK, goForward);
function goForward (e:MouseEvent):void
{
 page = xmlData.contentItem[currentContentItem + 1].toString();
 scorm.set ("cmi.location", page);
 
 //XML pages loaded when Next button pushed
 SoundMixer.stopAll ();
 currentContentItem = currentContentItem + 1;
 loadCoursePage ();
 mc_backBtn.visible = true;
 //Removes Next button on last page of course
 if (currentContentItem == xmlData.children().length() - 1)
 {
  mc_nextBtn.visible = false;
  mc_backBtn.visible = false;
 }

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "eLearning Technology and Development" group.
To post to this group, send email to elearning-technolo...@googlegroups.com
To unsubscribe from this group, send email to elearning-technology-and...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/elearning-technology-and-development?h...
-~----------~----~----~----~------~----~------~--~---


Nathan Mynarcik

unread,
Nov 12, 2009, 9:01:08 AM11/12/09
to elearning-technolo...@googlegroups.com
You could just cast your number variable as a string into the cmi.location spot. When you check for the bookmark, pull that variable and cast it back from a string to a number.

Nathan Mynarcik
Interactive Web Developer
nat...@mynarcik.com
254.749.2525
www.mynarcik.com


From: Ryan Wale <baldt...@gmail.com>
Date: Thu, 12 Nov 2009 08:33:10 -0500
Subject: Re: [elearning tech & dev] Re: scorm.get("cmi.location") help

--

You received this message because you are subscribed to the Google Groups "eLearning Technology and Development" group.
To post to this group, send email to elearning-technolo...@googlegroups.com.
To unsubscribe from this group, send email to elearning-technology-and...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/elearning-technology-and-development?hl=.

Ryan Wale

unread,
Nov 12, 2009, 9:19:13 AM11/12/09
to elearning-technolo...@googlegroups.com
Forgive my ignorance, but can you give an example as to how you 'cast' it from a number to a string and vice versa?

Nathan Mynarcik

unread,
Nov 12, 2009, 9:32:09 AM11/12/09
to elearning-technolo...@googlegroups.com
Since I am on the train, I will try and show a simple example. When I get to the office, I can send you more detail of how I did this.

Let's say you have your variable that will hold your bookmark...

var courseLoc:Number;
var bookmark:String;

courseLoc = 2; //your user hit page 2
bookmark = String(courseLoc); //this one way of casting
bookmark = courseLoc as String; //this is another way to cast it as a string. Sometimes one works but the other doesn't.

Then send your stuff to scorm to the cmi.location spot as you normally would. When you pull that data from scorm just use the same method as above to cast it back to a number.

Let me know if this helps. I can post more detail once I open my fla when I get in.

Nathan Mynarcik
Interactive Web Developer
nat...@mynarcik.com
254.749.2525
www.mynarcik.com


From: Ryan Wale <baldt...@gmail.com>
Date: Thu, 12 Nov 2009 09:19:13 -0500

Ryan Wale

unread,
Nov 12, 2009, 9:54:46 AM11/12/09
to elearning-technolo...@googlegroups.com
That makes sense; although, I'm using the variable bookmark to access cmi.location as shown below...how can I make bookmark = String(currentContentItem) if it needs to represent cmi.location?
 
var currentContentItem = 0;
function xmlLoaded (e:Event):void
{
 xmlData = XML(e.target.data);
 bookmark = scorm.get("cmi.location");
 if (bookmark != "")

 {
  coursePages = new URLRequest(xmlData.contentItem[bookmark].toString());
  coursePageLoader.load (coursePages);
  coursePageLoader.x = 0;
  coursePageLoader.y = 75;
  totalPages.text = "Page " + pageNumber + " of " + xmlData.contentItem.length();
 }
 else
 {
  loadCoursePage ();
 }
}
//Next Button function
mc_nextBtn.addEventListener (MouseEvent.CLICK, goForward);
function goForward (e:MouseEvent):void
{
 page = xmlData.contentItem[currentContentItem + 1].toString();
 scorm.set ("cmi.location", currentContentItem +1);

Nathan Mynarcik

unread,
Nov 12, 2009, 10:09:26 AM11/12/09
to elearning-technolo...@googlegroups.com
Ok, I hope this helps...

This is what I have right under my scorm.connect() call:

//counter is my variable I use that counts which swf it is dynamically being pulled in
counter = int(scorm.get("cmi.core.lesson_location"));

The above cast's the string value of lesson_location as an INT immediately when I pull it from the database.  This allows me to use it in my code similar to yours.

Now after I load my pages, inside that function is:
scorm.set("cmi.core.lesson_location", String(counter));
scorm.save();

The above casts my INT variable as a STRING back into lesson_location.


Nathan Mynarcik
Interactive Web Developer
nat...@mynarcik.com
254.749.2525
www.mynarcik.com


Ryan Wale

unread,
Nov 12, 2009, 12:08:12 PM11/12/09
to elearning-technolo...@googlegroups.com
That did the trick!  I had no idea you could do that.  Thanks so much for your help, Ryan and Nathan!!
Reply all
Reply to author
Forward
0 new messages