Hello! Wrote the code for the quiz. Everything works, questions are asked randomly, but at some point the application stops and the following error is displayed: "TypeError: Error # 1009: Cannot call a property or method with reference to the object" null ".at Main / asking () at Main / onClick ( ) ". I tried to eliminate it, applied tracing, but did not find a bug. In addition, an error occurs every time in a new place: it may appear after the first question, or after the tenth or any other. I fight the second day, I did not find the answer in the search engine. Here is the code itself:

package { import flash.display.*; import flash.events.*; import flash.net.*; import flash.text.*; import TfFormat; public class Main extends Sprite { var externalXML:XML;//Π·Π°Π³Ρ€ΡƒΠΆΠ΅Π½Π½Ρ‹ΠΉ XML var numOfQuestion:Number;//число вопросов var currentXML:XML=new XML;//XML Ρ‚Π΅ΠΊΡƒΡ‰Π΅Π³ΠΎ вопрсоа var currentElementText:String='';//Ρ‚Π΅ΠΊΡƒΡ‰ΠΈΠΉ Π²Π°Ρ€ΠΈΠ°Π½Ρ‚ ΠΎΡ‚Π²Π΅Ρ‚Π° var i;// Π½ΠΎΠΌΠ΅Ρ€ Ρ‚Π΅ΠΊΡƒΡ‰Π΅Π³ΠΎ вопроса var massiv:Array=[];// массив с ΠΎΡ‚Π²Π΅Ρ‚Π°ΠΌΠΈ var loader:URLLoader = new URLLoader(); var request:URLRequest=new URLRequest("super.xml"); var textF:TfFormat = new TfFormat; var rnd:RND; //экзСмпляр Π³Π΅Π½Π΅Ρ€Π°Ρ‚ΠΎΡ€Π° Π½ΠΎΠΌΠ΅Ρ€Π° вопроса public function Main() { loader.load(request); loader.addEventListener(Event.COMPLETE, preOnComplete); } /* Ѐункция Π·Π°Π³Ρ€ΡƒΠ·ΠΊΠΈ XML-Ρ„Π°ΠΉΠ»Π° */ function preOnComplete(event:Event):void { var tf:TextField = new TextField; tf.text = 'Π’ΠΈΠΊΡ‚ΠΎΡ€ΠΈΠ½Π°' tf.setTextFormat(textF); var goStart:AnswerBut = new AnswerBut('запуск Π²ΠΈΠΊΡ‚ΠΎΡ€ΠΈΠ½Ρ‹'); tf.x =30; tf.y =30; tf.width = 300; tf.height = 40; goStart.x = 50; goStart.y = 50; addChild(tf); addChild(goStart); goStart.addEventListener(MouseEvent.CLICK, onComplete); } function onComplete(event:Event):void { if (this.numChildren>1) { while (this.numChildren > 1) { this.removeChildAt(1); } } if (loader!=null) { externalXML=new XML(loader.data); numOfQuestion = externalXML.quest.length(); asking(externalXML.quest.length()+1); //запускаСм ΠΏΠ΅Ρ€Π²Ρ‹ΠΉ вопрос } } 

The function asking (numOff) is responsible for the task process of a specific question. The parameter of the function is passed the number of the previous question, which should not be set again. When you first start the function, this number is longer than the length of the array of questions. /

  function asking(numOff):void { var currentRandom:Number = numOff; //присваиваСм Ρ‚Π΅ΠΊΡƒΡ‰Π΅ΠΌΡƒ Π½ΠΎΠΌΠ΅Ρ€Ρƒ //вопроса ΠΏΡ€Π΅Π΄Ρ‹Π΄ΡƒΡ‰ΠΈΠΉ Π½ΠΎΠΌΠ΅Ρ€ вопроса while(currentRandom == numOff) { currentRandom = Math.round(Math.random()*numOfQuestion); //создаСм Π½ΠΎΠΌΠ΅Ρ€ вопроса, Π½Π΅ Ρ€Π°Π²Π½Ρ‹ΠΉ //ΠΏΡ€Π΅Π΄Ρ‹Π΄ΡƒΡ‰Π΅ΠΌΡƒ Π½ΠΎΠΌΠ΅Ρ€Ρƒ } currentXML=externalXML.quest[currentRandom]; //Ρ‚Π΅ΠΊΡƒΡ‰ΠΈΠΉ вопрос Π² Π²ΠΈΠ΄Π΅ XML var tf:TextField = new TextField; tf.text = currentXML.@text.toString(); tf.setTextFormat(textF); tf.width = 400; tf.height = 40; tf.x = 20; tf.y = 70; tf.wordWrap = true; addChild(tf); var numMassiv:Array = []; for (var i=0; i<currentXML.answer.length(); i++) { numMassiv[i] = i } var answerMassiv:Array = []; var answerNum = numMassiv.length; for (var k=0; k<answerNum; k++) { var kk = Math.round(Math.random()*(numMassiv.length-1)); answerMassiv[k]=new AnswerBut(currentXML.answer[numMassiv[kk]]); if (numMassiv[kk] == 0) answerMassiv[k].correct = true; answerMassiv[k].num = currentRandom; trace(currentRandom); numMassiv.splice(kk,1); answerMassiv[k].x=30; answerMassiv[k].y=k*20+120; addChild(answerMassiv[k]); answerMassiv[k].addEventListener(MouseEvent.CLICK, onClick); } } function onClick(e:MouseEvent):void { var prev = new Number(e.target.num); //удаляСм всСх ΠΏΠΎΡ‚ΠΎΠΌΠΊΠΎΠ² класса if (this.numChildren>1) { while (this.numChildren > 1) { this.removeChildAt(1); } } asking(prev); } } 

}

  • And in which line does the error occur? - ShockWave
  • @ShockWave, in the Output section, there is no string listed. The string is usually indicated in "Bugs and Compilations". - FlasherPro
  • And what's the development environment? In FlashDevelop, the Locals tab, you can see the status of fields and variables. - ShockWave

0