Everybody! This is important. In a few days, these forums will be moving over to using the totally sweet Discourse platform. To ensure this migration happens smoothly with no loss of content, these forums are currently in a read-only mode. I do apologize for the inconvenience.

There is never a good time to turn the forums off for an extended period of time, but I promise the new forums will be a billion times better. I'm pretty sure of it.

See you all on the other side in a few days, and if you have any (non-technical) questions, please e-mail me at kirupa@kirupa.com. For technical questions, try to find a tutorial that corresponds to what you are looking for and post in the comments section of that page.

Cheers,
Kirupa

Results 1 to 3 of 3

Thread: Flash and XML character issues

  1. #1

    Flash and XML character issues

    Hi all,

    I'm using XML to dynamically import text into a flash quiz.

    The problem I'm having is any punctuation is coming in as weird characters. So I did some research on CDATA and I'm still not able to get it to come in correctly. Can somebody let me know if there is something wrong with my XML code?

    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <data>
    	<question correct="2" label="1) Let's say an Investor says to you: 'I'm very interested in your property.  Could you give me the name and number of the seller?  I'd like to make sure there aren't any problems with the foundation.'  How should you respond?"><!-- the correct can be: 0, 1, 2, or 3 -->
    		<option><![CDATA[A - Give him the name and number. \n He can get that information at the county assessor's office anyhow.]]></option>
    		<option><![CDATA[B - Set him up with a meeting but be there yourself as well]]></option>
    		<option><![CDATA[C - Don't give him the information, and risk losing the deal]]></option>
    		<option><![CDATA[D - Don't give him the information but offer to<br/> pay for an inspection of the house.]]></option>
    		<answer><![CDATA[Try again!]]></answer>
    		<answer><![CDATA[Try again!]]></answer>
    		<answer><![CDATA[C - It's riskier to give the investor direct contact with your seller - he may try to cut you out of your own deal.]]></answer>
    		<answer><![CDATA[Try again!]]></answer>
    	</question>
    </data>
    and then the AS2 code if necessary:
    Code:
    //This arrays save the questions
    var questions_array:Array = new Array();
    var answers_array:Array = new Array();
    var corrects_array:Array = new Array();
    var labels_array:Array = new Array();
    
    //turn off the results
    correct_mc._visible = false;
    incorrect_mc._visible = false;
    
    /* XML PARSER
    Here we take the questions of the XML
    */
    questions_xml = new XML();
    questions_xml.ignoreWhite = true;
    
    questions_xml.onLoad = function(succes) {
    	for (var i = 0; i<this.firstChild.childNodes.length; i++) {
    		labels = this.firstChild.childNodes[i].attributes.label;
    		correct = this.firstChild.childNodes[i].attributes.correct;
    		option1 = this.firstChild.childNodes[i].childNodes[0].firstChild;
    		option2 = this.firstChild.childNodes[i].childNodes[1].firstChild;
    		option3 = this.firstChild.childNodes[i].childNodes[2].firstChild;
    		option4 = this.firstChild.childNodes[i].childNodes[3].firstChild;
    		answer1 = this.firstChild.childNodes[i].childNodes[4].firstChild;
    		answer2 = this.firstChild.childNodes[i].childNodes[5].firstChild;
    		answer3 = this.firstChild.childNodes[i].childNodes[6].firstChild;
    		answer4 = this.firstChild.childNodes[i].childNodes[7].firstChild;
    
    		questions_array.push([[option1], [option2], [option3], [option4]]);
    		answers_array.push([[answer1], [answer2], [answer3], [answer4]]);
    		corrects_array.push(Number(correct));
    		labels_array.push(labels);
    	}
    };
    
    //the XML URL
    xml = "modules/m1-fQuestion.xml";
    questions_xml.load(xml);
    
    //Ini the vars
    var actualQuest:Number;
    var actualCorrect:Number;
    
    //This function set the question
    function setQuestion(id:Number) {
    	//Turn off the results...again
    	correct_mc._visible = false;
    	incorrect_mc._visible = false;
    
    	//enable=true to the radios
    	radio1.enabled = true;
    	radio2.enabled = true;
    	radio3.enabled = true;
    	radio4.enabled = true;
    	
    	radio1.selected = false;
    	radio2.selected = false;
    	radio3.selected = false;
    	radio4.selected = false;
    
    	//set the vars and take the tesxts
    	actualQuest = id;
    	actualCorrect = corrects_array[id];
    
    	label_txt.text = labels_array[id];
    
    	//set the radio labels
    	radio1.label = questions_array[id][0];
    	radio2.label = questions_array[id][1];
    	radio3.label = questions_array[id][2];
    	radio4.label = questions_array[id][3];
    
    	//turn off the close button
    	close_btn._visible = false;
    }
    
    //This show the result
    function setAnswer(option:Number) {
    	selectedRadio = option + 1;
    	this["radio"+selectedRadio].selected = true;
    	// If is correct
    	if (option == actualCorrect) {
    		correct_mc.text_txt.htmlText = "Correct!<br>"+answers_array[actualQuest][option];
    		correct_mc._visible = true;
    		incorrect_mc._visible = false;
    
    		//enabled=false to the radios
    		radio1.enabled = false;
    		radio2.enabled = false;
    		radio3.enabled = false;
    		radio4.enabled = false;
    
    		//close button ON
    		close_btn._visible = true;
    
    	} else {
    		//If is incorrect
    		incorrect_mc.text_txt.htmlText = "Incorrect!<br>"+answers_array[actualQuest][option];
    		incorrect_mc._visible = true;
    		correct_mc._visible = false;
    	}
    }
    
    function closeQuest() {
    	//here you can put a call to an animation, function, etc, etc
    	// ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !
    	//This is the method to close the interactives
    	close_btn._visible = false;
    	_parent.closeInteractive();
    }
    
    
    
    close_btn.onRelease = function() {
    	closeQuest();
    };
    
    radio1.onPress = function() {
    	setAnswer(0);
    };
    
    radio2.onPress = function() {
    	setAnswer(1);
    };
    
    radio3.onPress = function() {
    	setAnswer(2);
    };
    
    radio4.onPress = function() {
    	setAnswer(3);
    };

  2. #2
    This is not server-side related, can someone move this?

    You can never underestimate the stupidity of the general public.

  3. #3

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012