-
[RESOLVED] Error 1010 - Interactive Storybook
Hi guys, I'm receiving the following error while coding my storybook.
TypeError: Error #1010: A term is undefined and has no properties.
at Main()[M:\Documents\InteractiveStorybook\Main.as:22]
I am working from "Foundation Games Design with Flash". My code is below.
Code:
public function Main()
{
startPage = new StartPage();
hillPage = new HillPage();
pondPage = new PondPage();
addChild(startPage);
//Add event listeners
startPage.hillButton.addEventListener(MouseEvent.CLICK,onHillButtonClick);
startPage.pondButton.addEventListener(MouseEvent.CLICK,onPondButtonClick);
hillPage.startButton.addEventListener(MouseEvent.CLICK,onStartButtonClickHill);
pondPage.startButton.addEventListener(MouseEvent.CLICK,onStartButtonClickPond);
}
//Event handlers
function onHillButtonClick(event:MouseEvent):void
{
addChild(hillPage);
removeChild(startPage);
}
function onPondButtonClick(event:MouseEvent):void
{
addChild(pondPage);
removeChild(startPage);
}
function onStartButtonClickHill(event:MouseEvent):void
{
addChild(startPage);
removeChild(hillPage);
}
function onStartButtonClickPond(event:MouseEvent):void
{
addChild(startPage);
removeChild(pondPage);
}
In particular, it is these 2 lines of code that are causing the problems (after a few rounds of debugging.
Code:
hillPage.startButton.addEventListener(MouseEvent.CLICK,onStartButtonClickHill);
pondPage.startButton.addEventListener(MouseEvent.CLICK,onStartButtonClickPond);
-
The debugger shows you the exact line that causes the problem, it's 22. Find line 22 in your code and trace everything that might cause the problem there
-
Caseyryan, I've traced it down to the 2 lines. Those 2 lines of code were found to be the bad ones after a set of debugging.
Code:
hillPage.startButton.addEventListener(MouseEvent.CLICK,onStartButtonClickHill);
pondPage.startButton.addEventListener(MouseEvent.CLICK,onStartButtonClickPond);
How do I get them to work?
-
All I can say by this code, is that whether hillPage, or pondPage or startButton is null.
Upload your project here, and I'll tell you exactly what the problem is
-
Interestingly, the buttons on the startPage are working correctly, it's the buttons from the hillPage/pondPage to the startPage that are not working.
-
I'm sure it's a very simple problem, but you'll have to find it yourself, since you didn't upload your file here
-
FLA file
ActionScript file
The AS file wasn't accepted by the forums, and the FLA file was too big... plus it also seemed the SWF wouldn't work...
-
hehe, that's a very obvious mistake that all novices do.
If you open your PondPage or HillPage symbol, and select the button, you'll see that it has no instance name.
Add and instance name of "startButton" to each of them and it will all work just fine
-
Where's the "Thanks" button when you need it? LOL. Thanks though, didn't realise I'd made such a novice mistake, called both instances startButton and it's working fine. I have also edited the ActionScript code slightly so as to follow the conventions in the book, and all is fine still.
You sir, are a genius.
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
|