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
-
i have a late 2011 macbook pro and i don't have the airplay icon on my menu. Everything is on the same network and i have a black mini apple Tv. it is either 2nd or 3rd generation. The airplay icon comes up in itunes it doesn't works with video just music. I want to mirror it on my apple tv. Will you please help me?
That's why, you will need to upgrade to 10.8
-
I lost an Iphone 5 and got a new one on the next day by mail but it still doesn't work, what I need to do to activate the phone?
Let's ensure we get this new device up and running, 123Vika. I know the importance of having a functional device. I have some great news you can activate the device directly from My Verizon. Take a look; http://vz.to/1gdvahs
YosefT_VZW
Follow us on Twitter @VZWSupport -
Trying to load a downloaded version of illustrator 6cs onto new mac and the old activation code for my illustrator cs doesn't work with it. Do I need a new code or am I missing something? Same goes for my Photoshop cs.
you need your serial number.
if you purchased from or registered with adobe check your account, https://www.adobe.com/account.html -
I can't seem to get my iMac (late 2009 model) into automatic sleep mode. If I manually put it into sleep I don't have any issues.
I used to solve the issue by running "PleaseSleep" application but that doesn't work anymore since Lion. I now want to fix the underlying problem.
I'm not running any weird background processes and in my energy saver settings I've tagged "put the hard disk to sleep when possible:, "allow power button to put computer to sleep" and "automatically reduce brigthness". All pretty standard.
Is there anyone who can give me some pointers ?Today I solved the same problem for my iMac running Snow Leopard. See https://discussions.apple.com/thread/3008791#15947706. The method may help you, too.
For me it was the DynDNS Updater preventing my iMac from automatically entering sleep mode.
To my knowledge the cause of this sleep problem can only be a peripheral device or a process. So I suggest to first unplug all peripherals and test whether that's the cause. If not, I suggest to terminate one process after another and to test automatic entering of sleep mode after each. Start with user processes; continue with system process if necessary.
At least that's the way I found the offending process. Fortunately, I was able to change the configuration of that process to allow again automatic entering of sleep mode.
Good luck! -
I cannot access my old email address anymore, however I have used it for my apple ID and now I want to delete it because the account has never been verified in the first place so my password for it doesn't work. So when I want to download apps I have to sign in with apple id but I can't so I made a new one, However I can't seem to be able to delete the old one. What do I do?
You can't merge Apple IDs. You also can't cancel (delete) and existing ID, you can only choose to stop using it.
If your old ID was compromised and you can no longer access it, you'll have to contact Apple for assistance. Go to https://expresslane.apple.com ; click 'See all products and services' at the bottom of the page. In the next page click 'More Products and Services, then 'Apple ID'. In the next page select 'Other Apple ID Topics' then then 'Apple ID account Security’. -
The screen of my iphone is broken and doesn't work anymore. Is there a way to type in my passcode on the computer/itunes?
No, get the screen fixed.
-
When I connect my iPod touch it tells me that I need a new version of Apple Mobile Device Support and to uninstall iTunes and then re-install it, I've done that twice with the newest version of iTunes and it still doesn't work?
Try:
Removing and reinstalling iTunes, QuickTime, and other software components for Windows Vista or Windows 7 -
I just updated to ios 7 on my iPhone 4 how do you turn the apps off when your not using them? The old way of double clicking and then pressing the app until a red minus button comes doesn't work it opens it back up!?
Double click home button, then swipe up on app picture (not the icon itself)
-
When I open a file it normally opens in 12.5% stated on the header. For some reason, it now opens with 100+% on the header and is much smaller in size. How do I go back to the first option I noted? I use AP to work on blueprints for measuring so the accuracy matters. Any direction would be greatly appreciated. Thank you.
Are the image all the same size the % files open into a document seems to vary with the number of pixels the image being opened has. Check the Image size.
-
I changed the card and i want to know how make to change the data from itunes. I tried and doesn't work. Please, Help Me!
No. That's not what I said. You can get an out of warranty replacement, which will be exactly the same model, color, and will be locked in exactly the same way the original is. If you want an iPhone 5, get the 4S replaced, sell it, and use the money to put toward a new phone.
-
Keep getting a pop up saying the Safari browser version we are currently using doesn't support the community tool bar whenever we try to get on a site supported by Safari.
safari "community toolbar" site:discussions.apple.com - Google Search
-
The speed key of imovie 10.0.5 doesn't work at all
the speed key of imovie 10.0.5 doesn't work at all
Have you enabled it on the iPhone/iPod Touch and iTunes
Once you have done this you need to ensure they are on the same WIFI network, If you have less than 50% power on the device then plug it into the mains.
You can then force the first sync in the settings>general>iTunes Wi-Fi Sync menu
lt me know if you get anywhere -
The key of on/off my iphone 5 doesn't work
THe key of on/off my iphone 5 doesn't work
<https://www.apple.com/support/iphone5-sleepwakebutton/>
-
The Audio playback device HDA Intel (ALC268 Analog) doesn't work.
Every time I login to KDE through KDM, the notification gives me this message: "The Audio playback device HDA Intel (ALC268 Analog) doesn't work. Falling back to default"
Everytime I try to play an audio file, the notification gives me the same message.
But everything else such as system sound, online video work.
What can I do to make it work?
thank you for your helpI have the same problem under the same conditions the original poster described. However, under System Settings -> Multimedia -> Device Preference I don't have default as device listed. The devices I can pick are:
-Esound (ESD)
-HDA Intel (STAC92xx Analog)
-HDA Intel, NVIDIA HDMI (HDMI Audio Output)
-Jack Audio COnnection Kit.
I can also pick HDA Intel (NVIDIA HDMI) when I check 'Show advanced devices'
When I use Esound I have sound for a while, until after a random time it falls back to the underlying device, which makes sound disappear. When I use HDA Intel (STAC92xx Analog), it falls back immediately on logging in and the other choices do never fall back, but when I use them, I have no sound at all. After I loose sound when Esound falls back to another device, sometimes writing sudo /etc/rc.d/alsa restart gives sound back, but mostly I need to relog/restart the X-Server to get sound back.
Is my issue related to the original poster his problem? And how can I fix it?
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
-
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
-
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..
-
Hi everyone How to make a script for build table: col width 25mm align decimal align on close paren Thanks Teetan