Copy link to clipboard
Copied
I know AS2 and am finally converting to AS3 now by following a book. My code is exactly the way it is in the book and everything in my library (the buttons, movieclips) are linked correctly, but I keep getting the same error 1010 that a term is undefined or has no properties. I want to know if I'm being dumb (I hope not), or if the book is outdated. Hopefully someone can help. I put in a picture of what my assets look like, as well as the code below it.
package {
import flash.display.MovieClip;
import flash.events.MouseEvent;
public class Main extends MovieClip{
var startPage:StartPage;
var hillPage:HillPage;
var pondPage:PondPage;
public function Main() {
startPage = new StartPage();
hillPage = new HillPage();
pondPage = new PondPage();
addChild(startPage);
startPage.HillButton.addEventListener(MouseEvent.CLICK, onHillButtonClick);
startPage.PondButton.addEventListener(MouseEvent.CLICK, onPondButtonClick);
}
function onHillButtonClick(event:MouseEvent):void{
addChild(hillPage);
removeChild(startPage);
}
function onPondButtonClick(event:MouseEvent):void{
addChild(pondPage);
removeChild(startPage);
}
}
}
You should go into your Flash Publish Settings and select the option to Permit Debugging. That can enhance your error messages to include line numbers for the offending code.
From what I see I suspect you are miscoding the names of the buttons inside the StartPage instance. The names HillButton and PondButton are the class names based on what your library image shows, they are not the instance names... at least hopefully they are not.
Copy link to clipboard
Copied
You should go into your Flash Publish Settings and select the option to Permit Debugging. That can enhance your error messages to include line numbers for the offending code.
From what I see I suspect you are miscoding the names of the buttons inside the StartPage instance. The names HillButton and PondButton are the class names based on what your library image shows, they are not the instance names... at least hopefully they are not.
Copy link to clipboard
Copied
I did the Permit Debugging thing and the output error code became:
TypeError: Error #1010: A term is undefined and has no properties.
at Main()
Which I can only assume means whats wrong is with line 19 (which would be the HillButton event listener line), but the problem isn't really obvious to me just by looking.
Also, when I tried adding instance names, it gave me this compiler error for both buttons.
Symbol 'StageOne' | 1046: Type was not found or was not a compile-time constant: HillButton. |
I'm sure its just something really dumb on my part. I'm probably gonna keep trying out different little things to fix it but I'm not really sure whats wrong. Thanks for the help so far though!
Copy link to clipboard
Copied
I already indicated what the problem is with that line (and the one after it). HillButton is the name you assigned as the class name... look at your library to see that. You cannot use a class name as an instance name. You will need to use maybe something like "hillButton"... so that it does not spell the same as the class name "HillButton", and you target it using the instance name, not the class name.
Copy link to clipboard
Copied
OH! You know now that I'm rereading your original post I definitely feel dumb haha. Ive been trying a bit and I've just been kind of frustrated with it so sorry for that. I'll let you know if it worked when I get home, but that sounds like the issue. Thanks!
Copy link to clipboard
Copied
Thank you so much! I was about to go insane! Haha. thats gonna be a lot of help!
Find more inspiration, events, and resources on the new Adobe Community
Explore Now