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

getting an error and been trying to fix it.

New Here ,
Feb 14, 2013 Feb 14, 2013

Ive been trying to find whats wrong and that but no luck at all. Can anyone help me out..

Thank you

TypeError: Error #1009: Cannot access a property or method of a null object reference.

  at mygame_fla::MainTimeline/talk()

import com.choices.*;

// hold all questions

var allQuestions:Array = new Array();

function setupChoices(){

          var tempQuestion:question;

          tempQuestion = new question( 1 , "What are you doing here?" , 0xFF000 );

          var tempAnswer:answer;

          tempAnswer = new answer( "I'd like a café latté please." , trace , "EVERYTHING IS WORKING..." );

          tempQuestion.addAnswer( tempAnswer );

          tempAnswer = new answer( "Shut up." , doQuestion , 2 );

          tempQuestion.addAnswer( tempAnswer );

          // add finished question to list of all...

          allQuestions.push( tempQuestion );

          // question 2

          tempQuestion = new question( 2 , "What's it all about?" , 0xFF000 );

          tempAnswer = new answer( "It's about nothing." , trace , "Question two has been answered." );

          tempQuestion.addAnswer( tempAnswer );

          tempAnswer = new answer( "What did you ask me a second ago?" , doQuestion , 1 );

          tempQuestion.addAnswer( tempAnswer );

          // add finished question to list of all...

          allQuestions.push( tempQuestion );

          trace( allQuestions.length );

}

setupChoices();

function getQuestionByID( idARG:int ):question{

          var i:int;

          var lim:int = Math.max( 0 , allQuestions.length );

          var item:question;

          findloop:for( i=0; i<lim; i++ ){

                    item = allQuestions; // access array element

                    if( idARG == item.id ){

                              // found it!

                              break findloop;

                    } // end if

          }// close forloop

          return( item );

} // close function

var selectAnswerBOOL:Boolean = true;

var currentQuestion:question;

currentQuestion = getQuestionByID( 1 );

showQuestion( currentQuestion );

import flash.events.KeyboardEvent;

import flash.ui.Keyboard;

stage.addEventListener(KeyboardEvent.KEY_DOWN , talk );

stage.addEventListener(KeyboardEvent.KEY_DOWN , keyDownList );

stage.addEventListener(KeyboardEvent.KEY_UP , keyUPList );

charMC.addEventListener(Event.ENTER_FRAME , movementchar);

//addEventListener(Event.ENTER_FRAME , npcTalk);

var leftKeyDown:Boolean = false;

var rightKeyDown:Boolean = false;

var upKeyDown:Boolean = false;

var downKeyDown:Boolean = false;

var talkNPC:Boolean = false;

var charSpeed:Number = 7; // Character Speed

function talk( ke:KeyboardEvent):void{

                    if( selectAnswerBOOL == true ){

                              trace(selectAnswerBOOL);

                              var chosenAnswer:answer;

                              switch( ke.keyCode ){

                                        case 49: // number 1 key

                                                  // select answer number 1

                                                  trace("1 key is pressed");

                                                  // set it

                                                  chosenAnswer = currentQuestion.answersList[0];

                                        break;

                                        case 50: // number 2 key

                                                  // set it

                                                  chosenAnswer = currentQuestion.answersList[1];

                                        break;

                                        default:

                                                  trace( ke.keyCode );

                                        break;

                              } // close switch

                              // use selected answer to establish next function and provide argument

                              chosenAnswer.nextFunction(chosenAnswer.argument);

                              trace(chosenAnswer);

                    } // if close (selectAnswerBOOL)

} // close talk

//char movements

function keyDownList(ke:KeyboardEvent):void{

          if(ke.keyCode == 81){

                    leftKeyDown = true;

          }

          if(ke.keyCode == 68){

                    rightKeyDown = true;

          }

          if(ke.keyCode == 87){

                    upKeyDown = true;

          }

          if(ke.keyCode == 83){

                    downKeyDown = true;

          }

          if(ke.keyCode == 84){

                    talkNPC = true;

          }

}

function keyUPList(ke:KeyboardEvent):void{

          if(ke.keyCode == 81){

                    leftKeyDown = false;

          }

          if(ke.keyCode == 68){

                    rightKeyDown = false;

          }

          if(ke.keyCode == 87){

                    upKeyDown = false;

          }

          if(ke.keyCode == 83){

                    downKeyDown = false;

          }

          if(ke.keyCode == 84){

                    talkNPC = false;

          }

}

function movementchar(event:Event):void{

          if(leftKeyDown){

                    charMC.x -= charSpeed;

          }

          if(rightKeyDown){

                    charMC.x += charSpeed;

          }

          if(upKeyDown){

                    charMC.y -= charSpeed;

          }

          if(downKeyDown){

                    charMC.y += charSpeed;

          }

}

/*function npcTalk (ev:Event):void{

          if(charMC.hitTestObject(npc)){

                    trace("talk");

          }

}*/

function showQuestion( q:question ){

          //if(talkNPC == true){

                    //if(charMC.hitTestObject(npc)){

                              dynTF.text="";

                              dynTF.appendText( q.questionText );

                              dynTF.appendText( "\n1. " + q.answersList[0].answerText );

                              dynTF.appendText( "\n2. " + q.answersList[1].answerText );

                    //}

          //}

}

function doQuestion( idnoARG:int ){

          currentQuestion = getQuestionByID( idnoARG );

          showQuestion( currentQuestion );

}

TOPICS
ActionScript
909
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
New Here ,
Feb 14, 2013 Feb 14, 2013

Ahh might just reply to this than editing it.

I forgot to mention that it only shows error when i press other keys like the movement function. but when pressing 1 or 2 to answer the question it doens;t show any 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
LEGEND ,
Feb 14, 2013 Feb 14, 2013

The 1009 error indicates that one of the objects being targeted by your code is out of scope.  This could mean that the object....

 

- is declared but not instantiated

- doesn't have an instance name (or the instance name is mispelled)

- does not exist in the frame where that code is trying to talk to it

- is animated into place but is not assigned instance names in every keyframe for it

- is one of two or more consecutive keyframes of the same objects with no name assigned in the preceding frame(s).

 

If you go into your Publish Settings Flash section and select the option to Permit debugging, your error message should have a line number following the frame number which will help you isolate which object is involved.

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
New Here ,
Feb 14, 2013 Feb 14, 2013

yeah i worked it out now..

Now im trying to trigger when "T" is pressed it should show the question/answer, it doesn't show anything when i collide to npc and press T.

function showQuestion( event:question ){

          if(talkNPC == true){

                    if(charMC.hitTestObject(npc)){

                              dynTF.text="";

                              dynTF.appendText( event.questionText );

                              dynTF.appendText( "\n1. " + event.answersList[0].answerText );

                              dynTF.appendText( "\n2. " + event.answersList[1].answerText );

                    }

          }

}

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 ,
Feb 14, 2013 Feb 14, 2013

Use the trace() function to determine if the function is being called, and if so, why whatever inside that function is failing to execute.  Also, if necessary, use it to track backwards in the processing to see where things are not executing as you expect if the function is performing correctly for what it is processing.

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
New Here ,
Feb 14, 2013 Feb 14, 2013

Yeah there is no collision even though i put hitTestObject(npc). Do I need to put addEventListener to that to function or something? just double checking.

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
New Here ,
Feb 16, 2013 Feb 16, 2013

function showQuestion( event:question ){

          //if(talkNPC == true){

                    if(charMC.hitTestObject(npc)){

                              dynTF.text="";

                              dynTF.appendText( event.questionText );

                              dynTF.appendText( "\n1. " + event.answersList[0].answerText );

                              dynTF.appendText( "\n2. " + event.answersList[1].answerText );

                    }

        // }

}

if I comment out the if(talkNPC) it works, but when pressing the answer button, not the actual question key to trigger it.

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 ,
Feb 16, 2013 Feb 16, 2013

YOur code is difficult to follow due to it being planted in a scrolling format like it is.  I don't (readily) see anywhere in it where you do anything to alter the value of talkNPC.  Instead of commenting the line out you should first understand why it is there and then determine why it is not indicating a true value if it should be.

One minor thing to note:  When you are testing boolean values ina conditional it is unnecessary to check if they == true.  A conditional evaluates the true/false value of whatever the condfition is, so you can just use

if(talkNPC){

just like you do with the hit test

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
New Here ,
Feb 16, 2013 Feb 16, 2013
LATEST

Now the collision works. Sorry is there any other way of posting a long code lines here?

I added this line.

if(ke.keyCode == 84){

                    talkNPC = true;

                    showQuestion( currentQuestion ); // this line

          }

but now when I pressed T the question appears but i have to press 1 or 2 (answer keys) then press T to actually answer the question.

this is the answer keys.

case 49: // number 1 key

                                                  // select answer number 1

                                                  trace("1 key is pressed");

                                                  // set it

                                                  chosenAnswer = currentQuestion.answersList[0];

 

                                        // use selected answer to establish next function and provide argument

                                                  chosenAnswer.nextFunction(chosenAnswer.argument);

                                                            trace(chosenAnswer);

 

                                        break;

 

                                        case 50: // number 2 key

                                                  // set it

                                                  chosenAnswer = currentQuestion.answersList[1];

 

                                        // use selected answer to establish next function and provide argument

                                                  chosenAnswer.nextFunction(chosenAnswer.argument);

                                                            trace(chosenAnswer);

                                        break;

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