Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

TypeError: Error #1009

Guest
Jan 03, 2013 Jan 03, 2013

Hello,

For a quiz I am building an application.

I am almost done, but I keep getting the following error:

TypeError: Error #1009: Kan geen eigenschap of methode benaderen via een verwijzing naar een object dat null is.

          at QuizApp_fla::MainTimeline/generateAnswers()

          at QuizApp_fla::MainTimeline/generateQuestion()

          at QuizApp_fla::MainTimeline/LoadXML()

          at flash.events::EventDispatcher/dispatchEventFunction()

          at flash.events::EventDispatcher/dispatchEvent()

          at flash.net::URLLoader/onComplete()

Below is my code, I am hoping someone can help me..:

//import flash.external.ExternalInterface;

import fl.controls.RadioButton;

import fl.controls.RadioButtonGroup;

var xmlLoader:URLLoader = new URLLoader();

var xmlData:XML = new XML();

var xml:XML;

var xmlList:XMLList;

var xmlChildren;

var totalQuestions:Number;

var totalAnswers: Number;

var radioButton:RadioButton;//a radio button

var radioButtonGroup:RadioButtonGroup;

var vPadding:uint = 0;//control the distance between radio buttons

var vSpacing:uint = 50;//provide equal space between radio buttons

var isCorrect:Number;

var correctAnswerIndex:Number;

var radioButtonArray:Array;

var radioButtonContainer:MovieClip = new MovieClip();

nextButton.visible = false;

var currentRadioButton;

var currentSelection;

var resultStr:String;

var result_TF:TextField = new TextField (); //to display result for current question

var currentQuestion:Number = 0;

//ExternalInterface.addCallback("nextQuestion", null, nextQuestion);

xmlLoader.addEventListener(Event.COMPLETE, LoadXML);

xmlLoader.load(new URLRequest("quiz.xml"));

addChild(radioButtonContainer);

function LoadXML(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

     generateQuestion (); // This function extracts question from XML

          }

function generateAnswers (): void {

          totalAnswers = xmlChildren[currentQuestion].answer.length();

          radioButtonGroup = new RadioButtonGroup("answers");

 

          for (var i:int = 0; i < totalAnswers; i++) {

                    radioButton = new RadioButton(); // create radio button

                    radioButton.selected = false;

                    //Previous addChild(radioButton) statement is replaced by following

                    radioButtonContainer.addChild(radioButton);

                    addChild(radioButton); //add it to the stage

                    radioButton.x = Question_TF.x + 30; // adjust ‘x’ position

                    radioButton.y = (vPadding + vSpacing) + (Question_TF.y + Question_TF.height);

                    vPadding += vSpacing;

                    radioButton.label = xmlChildren[currentQuestion].answer;

                    radioButton.width = 300; // for proper display of options

                    radioButton.group = radioButtonGroup; //grouping radio buttons

                    isCorrect = xmlChildren[currentQuestion].answer.@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);

     }

function generateQuestion (): void {

          Question_TF.text = xmlChildren[currentQuestion].questionText;

          totalQuestions = xmlChildren.length();

          generateAnswers();

          radioButtonArray= new Array();

     }

function checkAnswer(e:MouseEvent):void {

          currentRadioButton = e.currentTarget; // store selected radio button

          currentSelection = radioButtonGroup.getRadioButtonIndex(currentRadioButton)();

          resultStr = (currentSelection == correctAnswerIndex) ? "Correct" : "Incorrect";

          result_TF.text = resultStr;

          result_TF.x = radioButton.x + 30; //’x’ position

          result_TF.y = (vPadding + vSpacing)+50; //’y’ position

 

          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);

                    }

          }

 

          result_TF.width = 250; //for proper text display

          addChild (result_TF); //add it to the stage

//——– Go to next question ————————–

function nextQuestion(e:MouseEvent):void{

          Question_TF.text = "";

          result_TF.text = "";

          for (var i:int = 0; i < totalAnswers; i++){

                    radioButtonContainer.removeChild(radioButtonArray);

                    }

          if(currentQuestion < totalQuestions-1){

                    currentQuestion++;

                    vPadding = 0;

                    totalAnswers = 0;

                    radioButtonArray = [];

                    generateQuestion();

                    }

          }

Thanks!

TOPICS
ActionScript
1.5K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Enthusiast , Jan 03, 2013 Jan 03, 2013

Perfect !!

radioButtonArray is null

try

function generateQuestion (): void {

          Question_TF.text = xmlChildren[currentQuestion].questionText;

          totalQuestions = xmlChildren.length();

          radioButtonArray= new Array();  // <---------------- First

          generateAnswers();                      // <---------------- Second

     }

Translate
Enthusiast ,
Jan 03, 2013 Jan 03, 2013

You have a not defined object

Try using trace and tell me the last trace after run it

function generateAnswers (): void {

     trace(0);

          totalAnswers = xmlChildren[currentQuestion].answer.length();

    trace(1);

          radioButtonGroup = new RadioButtonGroup("answers");

    trace(3);

          for (var i:int = 0; i < totalAnswers; i++) {

    trace(i,0);

                    radioButton = new RadioButton(); // create radio button

                    radioButton.selected = false;

                    //Previous addChild(radioButton) statement is replaced by following

trace(i,1);

                    radioButtonContainer.addChild(radioButton);

                    addChild(radioButton); //add it to the stage

trace(i,2);

                    radioButton.x = Question_TF.x + 30; // adjust ‘x’ position

trace(i,3);

                    radioButton.y = (vPadding + vSpacing) + (Question_TF.y + Question_TF.height);

trace(i,4);

                    vPadding += vSpacing;

trace(i,5);

                    radioButton.label = xmlChildren[currentQuestion].answer;

trace(i,6);

                    radioButton.width = 300; // for proper display of options

trace(i,7);

                    radioButton.group = radioButtonGroup; //grouping radio buttons

trace(i,8);

                    isCorrect = xmlChildren[currentQuestion].answer.@correct;

trace(i,9);

                    if(isCorrect == 1){

                             correctAnswerIndex = i; //this is the index no. of correct option

trace("correct");

                              }

                    }

          radioButton.addEventListener(MouseEvent.CLICK, checkAnswer);

trace(4);

          //push radio buttons into array for reference to removeChild()

          radioButtonArray.push(radioButton);

trace(5);

     }

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 03, 2013 Jan 03, 2013

If you go into Publish settings for the swf there is a "Permit debugging" box. If you tick that box your 1009 error will tell you which line has the error.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jan 03, 2013 Jan 03, 2013

The permit debugging doesn't work.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 03, 2013 Jan 03, 2013
LATEST

What do you mean it doesn't work? It is telling you that the problem is in line 106 of the code on frame 1 and gives you the stack to back-track what has called what in which order.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jan 03, 2013 Jan 03, 2013

This is what I get back:

0

1

3

0 0

0 1

0 2

0 3

0 4

0 5

0 6

0 7

0 8

0 9

correct

1 0

1 1

1 2

1 3

1 4

1 5

1 6

1 7

1 8

1 9

2 0

2 1

2 2

2 3

2 4

2 5

2 6

2 7

2 8

2 9

3 0

3 1

3 2

3 3

3 4

3 5

3 6

3 7

3 8

3 9

4

TypeError: Error #1009: Kan geen eigenschap of methode benaderen via een verwijzing naar een object dat null is.

          at QuizApp_fla::MainTimeline/generateAnswers()[QuizApp_fla.MainTimeline::frame1:106]

          at QuizApp_fla::MainTimeline/generateQuestion()[QuizApp_fla.MainTimeline::frame1:153]

          at QuizApp_fla::MainTimeline/LoadXML()[QuizApp_fla.MainTimeline::frame1:118]

          at flash.events::EventDispatcher/dispatchEventFunction()

          at flash.events::EventDispatcher/dispatchEvent()

          at flash.net::URLLoader/onComplete()

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jan 03, 2013 Jan 03, 2013

Perfect !!

radioButtonArray is null

try

function generateQuestion (): void {

          Question_TF.text = xmlChildren[currentQuestion].questionText;

          totalQuestions = xmlChildren.length();

          radioButtonArray= new Array();  // <---------------- First

          generateAnswers();                      // <---------------- Second

     }

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jan 03, 2013 Jan 03, 2013

Thanks very much!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jan 03, 2013 Jan 03, 2013

you're welcome

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines