« Speed control widgets for Captivate | Main | Captivate 3 Quizzes marking "failed" when quiz is not completed »

March 05, 2008

Randomizing Captivate Quizzes

Captivate quizzes are easy to create, but they lack some often-requested features. Even using version 2, it is difficult, if not impossible, to randomize questions within Captivate. The following method will alter the html wrapper generated when you publish a Captivate project so that it chooses from a bank of alternate Captivate SWF files when the page opens.

Download example HTML wrapper file

When you publish to Flash (SWF) in Captivate, Captivate creates an HTML wrapper which contains the SWF file in an object tag. (Usually titled "ProjectTitle.htm") There is a variable, "strURLFile ," which determines which Captivate file is launched. In the unaltered file, this variable is set to the project title you set when you published.

To randomize the quizzes, you need to replace this hard-coded value with a function. So, around line 8 of the HTML file, insert the following lines:

	//********begin randomization function	
	       	 var strURLFile 
			function chooseSwf() {
			var number = 0;
			var swf = new Array()
	//********add your alternate SWF file names into this array
			swf[number++] = "TestQuiz01.swf"
			swf[number++] = "TestQuiz02.swf"
			swf[number++] = "TestQuiz03.swf"
			swf[number++] = "TestQuiz04.swf" 	
	//****** end of array
			var increment = Math.floor(Math.random() * number);
			strURLFile= swf[increment];
			return strURLFile;		 
			}
           strURLFile = chooseSwf();
 //********end randomization function
Be sure to add all the SWF names into the array where indicated.

Around line 25, be sure to comment out the original variable definition:

	// var strURLFile = "TestQuiz03.swf";		// Name of the flash file

That is all you have to do. Of course, the more alternate SWF's you create, the less likely someone will see the same one twice in a row. Create several alternate versions, output them all in the same format, and drop the alternate SWF's into the same folder as the custom HTML wrapper and the first SWF.


Posted by emeiselm at March 5, 2008 06:42 PM

Comments

Login to leave a comment. Create a new account.