Skip to main content
locomolito
Participant
February 27, 2017
Question

How to make Quiz that gets questions from XML during runtime?

  • February 27, 2017
  • 6 replies
  • 1389 views

I want to be able to have a dynamic quiz and whenever I edit the XML it will reflect in the quiz when I run it and no need to republish my project.

This topic has been closed for replies.

6 replies

locomolito
Participant
March 17, 2017

Hi TLCMediaDesign, I have tried this and it worked though it does not do  I want it to do.

It seems that it is not dynamic enough when I want to add a response or a question. When I add a response, I have to go back to captivate and create another variable and when I add a question, i have to do the same thing which means I have to republish my captivate to be able to do that.

TLCMediaDesign
Inspiring
March 17, 2017

What you need then is to create HTML pages the build dynamically from the JSON.

It's the nature of the beast that Captivate is not dynamically creating the response smartshapes, the script is just populating what is there.

If you are tracking the quiz with SCORM through Captivate, it would be a little difficult to use CP's SCORM. but not impossible. The HTML pages would need to make the SCORM calls for the quiz points.

locomolito
Participant
March 10, 2017

Great! Does that also apply to the number of questions? I see that they are also stored in an array. So If i want to add have 5 or 30 questions, I don't have to republish my captivate project.

TLCMediaDesign
Inspiring
March 10, 2017

The question number is held in  e.Data.qs. It parses that to get the question from the JSON.

It doesn't matter haw many questions, it will work. You just need to create a ton of variables in Captivate for the script to populate.

TLCMediaDesign
Inspiring
March 1, 2017

This script will do what you want without XML.

You need to create variables:

stem_1

response_1_0

response_1_1

stem_2

response_2_0

response_2_1

and so on.

populate your questions with the variables, like $$stem_1$$

Include or add the script in the head of the index.html:

var questions = [
{
  stem: "This is the stem of Question 1",
  responses:
  [
   "This is response A for Question 1",
   "This is response B for Question 1"
  ]
},
{
  stem: "This is the stem of Question 2",
  responses:
  [
   "This is response A for Question 2",
   "This is response B for Question 2"
  ]
}
]

var interfaceObj, eventEmitterObj;

window.addEventListener( 'moduleReadyEvent', function ( e )
{
interfaceObj = e.Data;
eventEmitterObj = interfaceObj.getEventEmitter();
initializeEventListeners();
});

function initializeEventListeners()

if ( interfaceObj )
{
  if ( eventEmitterObj )
  {
   eventEmitterObj.addEventListener( 'CPAPI_SLIDEENTER', enterSlide, false );
  }
}
}

function enterSlide( e )
{
if ( e.Data.st == 'Question Slide' )
{
  idx = e.Data.qs.split( 'q' )[ 1 ];
 
  window[ 'stem_' + e.Data.slideNumber ] =  questions[ idx ].stem;
 
  for ( var i = 0; i < questions[ idx ].responses.length; i++ )
  {
   window[ 'response_' + e.Data.slideNumber + '_' + i ] = questions[ idx ].responses[ i ];
  }
}
}

Inspiring
March 1, 2017

@TLCMediaDesign

1. Can you explain what these lines of code in the slideEnter function do?

    Does the first line put all the course's "question slides" into an array? And the second line match the CP "stem" variables in a slide with the stem in the var "questions" array?

  idx = e.Data.qs.split( 'q' )[ 1 ];

 

  window[ 'stem_' + e.Data.slideNumber ] =  questions[ idx ].stem;

2. How would i modify the lines below if i was creating custom questions (i.e. not using CPs question slides)?

    (I'm assuming that the "window[..." line would be the same.)

if ( e.Data.st == 'Question Slide' )

{

  idx = e.Data.qs.split( 'q' )[ 1 ];

 

  window[ 'stem_' + e.Data.slideNumber ] =  questions[ idx ].stem;

3. If i was putting the CP variables ($$..$$) in "text caption / smartshapes", is there a way to autsize them using Javascript / CSS depending on how much text is in the stem and 7 or responses.

Thanks,

Donal.

TLCMediaDesign
Inspiring
March 1, 2017

The variable idx get the question number from the qs property.

The e.Data.qs is a string like this: Slide5232q0

If you are not using Captivates Quiz slide, something would need to actually be scored for the e.Data.st to return "Question Slide"

The window[ "stem..  part is just referencing and populating the variable, so it would be the same.

I have scripts and CSS that do resized and position text in dynamically create divs for drag and drop models. I have never tried to do it with Captivate. Captivate creates those elements with canvas, so I think you would need to create your own canvas element, possible as a clone of the original and then hide the original and redraw the clone with the new properties.

Participating Frequently
February 28, 2017

This is completely possible using a javascript loader.  It would be easier if rather than XML,  the questions were formed as JSON, but still very doable.  It is a unique enough requirement that a complete solution for a deployable application it is not likely "off the shelf" and would require a concentrated development.

Inspiring
February 28, 2017

The only thing i have seen is a video that shows how to click tabs to load XML data.

Common JavaScript Interface in Adobe Captivate 8

The sample project used in the video is downloadable at the bottom of this page.

Learn about the Common JavaScript interface for Adobe Captivate.

Barb Binder
Community Expert
Community Expert
February 27, 2017

Hi! You posted in the non-technical Lounge forum. What application are you using? Let us know and we will move your question to the appropriate forum so that you can get an answer.

~Barb at Rocky Mountain Training
locomolito
Participant
February 28, 2017

ohh sorry, I am using Adobe Captivate. Yes please move my question to the right forum. Thanks.