LAV.ru
27.03.2012, 17:05
Пишет ошибку: синтаксическая ошибка:rightbrace перед end of program
делал по уроку http://www.graphicmania.net/how-to-build-a-xml-driven-quiz-application-in-flash/
Дошел до пункта 6 пункта,все было норм,теперь даже xml не подгружается.
import fl.controls.RadioButton;
import fl.controls.RadioButtonGroup;
var url:URLRequest = new URLRequest("quiz.xml"); // url of xml file
var xmlLoader:URLLoader = new URLLoader(url); // xml file loader
//When xml file is completely loaded call ‘onXMLLoad’ function
xmlLoader.addEventListener(Event.COMPLETE, onXMLLoad);
//Create XML document and have access to its children
var xml:XML;
var xmlList:XMLList;
var xmlChildren;
var totalQuestions:Number;
function generateQuestion (): void {
Question_TF.text = xmlChildren[currentQuestion].QText;
//get total number of questions
totalQuestions = xmlChildren.length();
generateOptions();
}
function onXMLLoad(e:Event):void {
xml = new XML(xmlLoader.data); //create XML document
xmlList = new XMLList(xml); //create XML List of XML nodes
xmlChildren = xmlList.children(); //Get number of child nodes
var currentQuestion:Number = 0; // reference to index number of question (XML file)
function nextQuestion(e:MouseEvent):void{
Question_TF.text = "";
result_TF.text = "";
//remove previous options
for (var i:int = 0; i < totalOptions; i++){
radioButtonContainer.removeChild(radioButtonArray[i]);
}
//check if current question is last question
if(currentQuestion < totalQuestions-1){
//next question index
currentQuestion++;
vPadding = 0;
totalOptions = 0;
radioButtonArray = [];
// This function extracts question from XML.
generateQuestion ();
}
}
var totalOptions:Number;
var radioButton:RadioButton;
var radioButtonGroup:RadioButtonGroup;
var vPadding:uint = 0;
var vSpacing:uint = 50;
var isCorrect:Number;
var correctAnswerIndex:Number;
var radioButtonArray:Array;
var radioButtonContainer:MovieClip = new MovieClip();
addChild(radioButtonContainer);
function generateOptions (): void {
radioButtonArray= new Array(); //Store radio buttons for reference
totalOptions = xmlChildren[currentQuestion].Option.length();
radioButtonGroup = new RadioButtonGroup("options");
for (var i:int = 0; i < totalOptions; i++) {
radioButton = new RadioButton(); // create radio button
radioButton.selected = false;
//Previous addChild(radioButton) statement is replaced by following
radioButtonContainer.addChild(radioButton);
radioButton.x = Question_TF.x + 30; // adjust ‘x’ position
//Adjust ‘y’ position of radio buttons
radioButton.y = (vPadding + vSpacing) + (Question_TF.y + Question_TF.height);
vPadding += vSpacing;
radioButton.label = xmlChildren[currentQuestion].Option[i];
radioButton.width = 300;
radioButton.width = stage.stageWidth; // for proper display of options
radioButton.group = radioButtonGroup; //grouping radio buttons
//Get the index of correct option(‘correct’ attribute) from xml file
isCorrect = xmlChildren[currentQuestion].Option[i].@correct;
if(isCorrect == 1){
correctAnswerIndex = i; //this is the index no. of correct option
}
radioButton.addEventListener(MouseEvent.CLICK, checkAnswer);
//push radio buttons into array for reference to removeChild()
radioButtonArray.push(radioButton);
}
}
nextButton.visible = false;
var currentRadioButton;
var currentSelection:Number;
var resultStr:String;
var resultStrColor;
var result_TF:TextField = new TextField (); //to display result for current question
result_TF.defaultTextFormat = globalTextFormat;
result_TF.width = 250; //for proper text display
addChild (result_TF); //add it to the stage
function checkAnswer(e:MouseEvent):void {
currentRadioButton = e.currentTarget; // store selected radio button
//Get an index number of selected radio button
currentSelection = (radioButtonGroup.getRadioButtonIndex(currentRadioButton));
//Check and store answer
resultStr = (currentSelection == correctAnswerIndex) ? "Correct" : "Incorrect";
//Display a result
result_TF.text = resultStr;
resultStrColor = (resultStr == "Correct") ? 0x009900 : 0xFF0000;
result_TF.textColor = resultStrColor;
//Positioning the result textfield
result_TF.x = radioButton.x + 30; //’x’ position
result_TF.y = (vPadding + vSpacing)+50; //’y’ position
//For correct answer ready to display next question
if(resultStr == "Correct"){
//check if current question is last question
if(currentQuestion < totalQuestions-1){
nextButton.visible = true;
nextButton.addEventListener(MouseEvent.CLICK, nextQuestion);
//next button position
nextButton.x = result_TF.x + result_TF.width + 40;
nextButton.y = result_TF.y;
}else{
result_TF.text = resultStr + " —> Quiz Complete";
}
}else{
nextButton.visible = false;
nextButton.removeEventListener(MouseEvent.CLICK, nextQuestion);
}
}
XML
<?xml version="1.0" encoding="UTF-8"?>
<Quiz>
<Question>
<QText> Q1. Где ошибка в этом коде? </QText>
<Option correct ="1"> Неправильно написан </Option>
<Option> Фиг его знает </Option>
<Option> Что-то пропустил</Option>
</Question>
<Question>
<QText> Q2. Ответят мне сегодня? </QText>
<Option> Нет </Option>
<Option correct ="1"> Кто его знает </Option>
<Option> Да </Option>
<Option> Не сегодня </Option>
</Question>
<Question>
<QText> Q3. Рабочий код у автора урока? </QText>
<Option> Не рабочий </Option>
<Option correct ="1"> Рабочий </Option>
</Question>
</Quiz
делал по уроку http://www.graphicmania.net/how-to-build-a-xml-driven-quiz-application-in-flash/
Дошел до пункта 6 пункта,все было норм,теперь даже xml не подгружается.
import fl.controls.RadioButton;
import fl.controls.RadioButtonGroup;
var url:URLRequest = new URLRequest("quiz.xml"); // url of xml file
var xmlLoader:URLLoader = new URLLoader(url); // xml file loader
//When xml file is completely loaded call ‘onXMLLoad’ function
xmlLoader.addEventListener(Event.COMPLETE, onXMLLoad);
//Create XML document and have access to its children
var xml:XML;
var xmlList:XMLList;
var xmlChildren;
var totalQuestions:Number;
function generateQuestion (): void {
Question_TF.text = xmlChildren[currentQuestion].QText;
//get total number of questions
totalQuestions = xmlChildren.length();
generateOptions();
}
function onXMLLoad(e:Event):void {
xml = new XML(xmlLoader.data); //create XML document
xmlList = new XMLList(xml); //create XML List of XML nodes
xmlChildren = xmlList.children(); //Get number of child nodes
var currentQuestion:Number = 0; // reference to index number of question (XML file)
function nextQuestion(e:MouseEvent):void{
Question_TF.text = "";
result_TF.text = "";
//remove previous options
for (var i:int = 0; i < totalOptions; i++){
radioButtonContainer.removeChild(radioButtonArray[i]);
}
//check if current question is last question
if(currentQuestion < totalQuestions-1){
//next question index
currentQuestion++;
vPadding = 0;
totalOptions = 0;
radioButtonArray = [];
// This function extracts question from XML.
generateQuestion ();
}
}
var totalOptions:Number;
var radioButton:RadioButton;
var radioButtonGroup:RadioButtonGroup;
var vPadding:uint = 0;
var vSpacing:uint = 50;
var isCorrect:Number;
var correctAnswerIndex:Number;
var radioButtonArray:Array;
var radioButtonContainer:MovieClip = new MovieClip();
addChild(radioButtonContainer);
function generateOptions (): void {
radioButtonArray= new Array(); //Store radio buttons for reference
totalOptions = xmlChildren[currentQuestion].Option.length();
radioButtonGroup = new RadioButtonGroup("options");
for (var i:int = 0; i < totalOptions; i++) {
radioButton = new RadioButton(); // create radio button
radioButton.selected = false;
//Previous addChild(radioButton) statement is replaced by following
radioButtonContainer.addChild(radioButton);
radioButton.x = Question_TF.x + 30; // adjust ‘x’ position
//Adjust ‘y’ position of radio buttons
radioButton.y = (vPadding + vSpacing) + (Question_TF.y + Question_TF.height);
vPadding += vSpacing;
radioButton.label = xmlChildren[currentQuestion].Option[i];
radioButton.width = 300;
radioButton.width = stage.stageWidth; // for proper display of options
radioButton.group = radioButtonGroup; //grouping radio buttons
//Get the index of correct option(‘correct’ attribute) from xml file
isCorrect = xmlChildren[currentQuestion].Option[i].@correct;
if(isCorrect == 1){
correctAnswerIndex = i; //this is the index no. of correct option
}
radioButton.addEventListener(MouseEvent.CLICK, checkAnswer);
//push radio buttons into array for reference to removeChild()
radioButtonArray.push(radioButton);
}
}
nextButton.visible = false;
var currentRadioButton;
var currentSelection:Number;
var resultStr:String;
var resultStrColor;
var result_TF:TextField = new TextField (); //to display result for current question
result_TF.defaultTextFormat = globalTextFormat;
result_TF.width = 250; //for proper text display
addChild (result_TF); //add it to the stage
function checkAnswer(e:MouseEvent):void {
currentRadioButton = e.currentTarget; // store selected radio button
//Get an index number of selected radio button
currentSelection = (radioButtonGroup.getRadioButtonIndex(currentRadioButton));
//Check and store answer
resultStr = (currentSelection == correctAnswerIndex) ? "Correct" : "Incorrect";
//Display a result
result_TF.text = resultStr;
resultStrColor = (resultStr == "Correct") ? 0x009900 : 0xFF0000;
result_TF.textColor = resultStrColor;
//Positioning the result textfield
result_TF.x = radioButton.x + 30; //’x’ position
result_TF.y = (vPadding + vSpacing)+50; //’y’ position
//For correct answer ready to display next question
if(resultStr == "Correct"){
//check if current question is last question
if(currentQuestion < totalQuestions-1){
nextButton.visible = true;
nextButton.addEventListener(MouseEvent.CLICK, nextQuestion);
//next button position
nextButton.x = result_TF.x + result_TF.width + 40;
nextButton.y = result_TF.y;
}else{
result_TF.text = resultStr + " —> Quiz Complete";
}
}else{
nextButton.visible = false;
nextButton.removeEventListener(MouseEvent.CLICK, nextQuestion);
}
}
XML
<?xml version="1.0" encoding="UTF-8"?>
<Quiz>
<Question>
<QText> Q1. Где ошибка в этом коде? </QText>
<Option correct ="1"> Неправильно написан </Option>
<Option> Фиг его знает </Option>
<Option> Что-то пропустил</Option>
</Question>
<Question>
<QText> Q2. Ответят мне сегодня? </QText>
<Option> Нет </Option>
<Option correct ="1"> Кто его знает </Option>
<Option> Да </Option>
<Option> Не сегодня </Option>
</Question>
<Question>
<QText> Q3. Рабочий код у автора урока? </QText>
<Option> Не рабочий </Option>
<Option correct ="1"> Рабочий </Option>
</Question>
</Quiz