getting an error and been trying to fix it.
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 );
}