Declaring a variable in a function: either the function or the eventListener I'm using doesn't work

Can anyone help me with this?
I have a set of Cue Points in an FLV I'm playing. It's an interactive quiz, so the idea is that flash will change a variable, theAnswer, to a different letter depending on which question it is. The answer to question 1 is B, question 2 is D, etc.
Either the cue point event listener isn't working, or else it is working and Flash isn't declaring the variables. Can someone help?
The error message I get is:
1120: Access of undefined property theAnswer.
I literally can't find a single problem with my code. I have an almost identical Event Listener further down which works.
var theAnswer;
vid.addEventListener(MetadataEvent.CUE_POINT, cueAnswers);
function cueAnswers(e:MetadataEvent):void{
var cuePointNames = e.info.name;
if (cuePointNames =="start")
theAnswer = "C";
else if (cuePointNames =="q2")
theAnswer = "A";
else if (cuePointNames =="q3")
theAnswer = "C";
else if (cuePointNames =="q4")
theAnswer = "A";
else if (cuePointNames =="q5")
theAnswer = "D";
else if (cuePointNames =="q6")
theAnswer = "C";
else if (cuePointNames =="q7")
theAnswer = "A";
else if (cuePointNames =="q8")
theAnswer = "D";
else if (cuePointNames =="q9")
theAnswer ="B"
else if (cuePointNames =="q10")
theAnswer ="B";
The function is called by this later:
function nkAinfo(e:MouseEvent):void {
if (theAnswer=="C")
trace("You clicked right");
else
trace("You clicked wrong");
What's going on? Is the function not being called or are my variable declarations wrong?

Probably not the answer to your question, but it could help anyways....
First there is another command that, to me at least, is much easier to read that a bunch of nested if/if elses. And that is the switch.
switch (e.info.name){
case "start":
theAnswer="C";
break;
case "q2":
theAnswer="A"
break;
//and so on
To me that is easier to maintain and read. But I don't think that is really what you need here. So just file that one away for the future.
In this case, what I think you need is an array.
var currentAnswer:String;
var correctAnswers:Array=new Array();
correctAnswers["start"]="C"
correctAnswers["q2"]="A"
// and so on.
Then your cuepoint handler function becomes something like this:
function cueAnswers(e:MetadataEvent):void{
     currentAnswer=correctAnswers[e.info.name];
And I'm a little confused by your mouse click handler. It would seem to suggest that the answer is always "C"? But I"m guessing that it is supposed to compare what the user clicked on to what the cuePoint has told it is the correct answer? Well if that is the case then it would probably look something like:
function nkAinfo(e:MouseEvent):void {
if(e.currentTarget.clickedProperty==currentAnswer){
     trace("Correct");
} else {
     trace("Incorrect");
With the way you are currently doing this I'm guessing that you have a bunch of repeated functions for each time there is a mouse click and that your code is a lot more complicated that it needs to be. And that somewhere hiding in all those lines there is an error that would be simple to fix if you could see it.
What the error is telling you is that somewhere your are trying to assign or retrieve theAnswer and it hasn't been defined yet.

Similar Messages

Maybe you are looking for

  • Mac pages 5.5.1 iCloud problem

    Hi I have a mid 2011 Mac running the latest Yosemite. My pages is 5.5.1. I can't seem to open any pages documents direct from iCloud Drive. Logging out of then back in to iCloud drive doesn't work. the only thing that works is me dragging the file fr

  • ABC Analysis from transaction MC40 - Qty field

    Hi All, I recently got to know about MC40 and i dont understand some areas of it. After executing MC40, i will get the list of materials sorted already for A, B , and C. However, when i click on double line, it then shows me Qty field as well. Now wh

  • To see the error

    Hi, I want to see the error by Jdev 11.1.1.2.0. Can you pls look at this http://www.4shared.com/document/nWy1yG9a/t61.html Regards, huamin

  • Cant change color on visited sites without changing background /foreground colors that hide options on the sitec

    I want to change the color of visited sites, but am forced to set background and foreground colors which don't properly show all of the colors for controls etc on many websites. I have to uncheck the button to Allow pages to choose their own colors..

  • Make a script for build table

    Hi everyone How to make a script for build table: col width 25mm align decimal align on close paren Thanks Teetan