-
undefined var error
I have been taking scripting I am familiar with from AS2 and making adjustments to AS3, just very simple files. Of course, I run into problems and through research, I have managed to solve most them, but I have a problem that has me absolutely stumped.
I created a file with a simple timer that when it reaches a certain time moves to a different frame:
stop();
var startTime:Number= 0;
stage.addEventListener(MouseEvent.CLICK, reset);
function reset(myevent:MouseEvent):void {
startTime = getTimer();
}
stage.addEventListener(Event.ENTER_FRAME, showTime);
function showTime(myevent:Event):void {
var currentTime = getTimer();
var elapsedTime = (currentTime - startTime) / 1000;
myDisplay_txt.text = elapsedTime;
if (elapsedTime >= 5){
gotoAndStop(2);
}
}
All is well and good, but when I try to combine it with a file with has score buttons, I get an error.
stop();
var currentScore = 0;
score.text = "0";
function scorept(myevent:MouseEvent):void {
score.text = currentScore+=1;
}
scoreOne_btn.addEventListener(MouseEvent.MOUSE_DOW N, scorept);
function scoreFivept(myevent:MouseEvent):void {
score.text = currentScore+=5;
}
scoreFive_btn.addEventListener(MouseEvent.MOUSE_DO WN, scoreFivept);
function scoreMinusFivept(myevent:MouseEvent):void {
score.text = currentScore-=5;
}
scoreMinusFive_btn.addEventListener(MouseEvent.MOU SE_DOWN, scoreMinusFivept);
function scoreMinusOnept(myevent:MouseEvent):void {
score.text = currentScore-=1;
}
scoreMinusOne_btn.addEventListener(MouseEvent.MOUS E_DOWN, scoreMinusOnept);
var startTime:Number= 0;
startTime = getTimer();
stage.addEventListener(Event.ENTER_FRAME, showTime);
function showTime(myevent:Event):void{
var currentTime = getTimer();
var elapsedTime = (currentTime - startTime) / 1000;
tme_txt.text = elapsedTime;
if (elaspsedTime >= 5){
gotoAndStop(3);
}
}
stage.addEventListener(Event.ENTER_FRAME, winGame);
function winGame(myevent:Event):void {
if (currentScore >=20) {
gotoAndStop(4);
}
}
Now I get a compiler error:
1120: Access of undefined property elaspsedTime.
WTF? If I turn off the compiler strict mode, it will render, the score part works, but the timer just go on forever. The var for elapsedTime is RIGHT THERE!!
What the heck am I missing????
-
It's just a typo. 'elaspsedTime' vs 'elapsedTime'.
-
LOL, what a duck head i am. I truely cannot believe i missed that. Can you believe i have been spending hours shifting the script around trying to find the answer?
Thank you for your patience and time.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|