当前位置: 动力学知识库 > 问答 > 编程问答 >

flash - TypeError: Error #1010: A term is undefined and has no properties

问题描述:

I was trying to program an interactive storybook. after adding the event listener and event handler, I tried to test the project and had this error. I tried my best to do away with this error but couldn't. TypeError: Error #1010: A term is undefined and has no properties.

at Main()

below is the code.

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);

//Add event Listeners

startPage.hillButton.addEventListener(MouseEvent.CLICK, onHillButtonClick);

startPage.PondButton.addEventListener(MouseEvent.CLICK, onPondButtonClick);

}

//Event Handlers

function onHillButtonClick(Event:MouseEvent):void

{

addChild(hillPage);

removeChild(startPage);

}

function onPondButtonClick(Event:MouseEvent):void

{

addChild(pondPage);

removeChild(startPage);

}

}

}

网友答案:

suggested traces to narrow down the issue, just paste back the debug

package  {
    import flash.display.MovieClip;
    import flash.events.MouseEvent;

    public class Main extends MovieClip {   trace('Main');
        var startPage:StartPage;        trace(' 0');
        var hillPage:HillPage;          trace(' 1');
        var pondPage:PondPage;          trace(' 2');

        public function Main() {
            trace('# Main');

            startPage = new StartPage();        trace(' a');
            hillPage = new HillPage();          trace(' b');
            pondPage = new PondPage();          trace(' c');
            addChild(startPage);                trace(' d');

            //Add event Listeners
            startPage.hillButton.addEventListener(MouseEvent.CLICK, onHillButtonClick);
            startPage.PondButton.addEventListener(MouseEvent.CLICK, onPondButtonClick);
            trace(' events added');
        }

        //Event Handlers
        function onHillButtonClick(Event:MouseEvent):void {             trace('# onHill clicked');
            addChild(hillPage);             trace(' add');
            removeChild(startPage);         trace(' remove');
        }
        function onPondButtonClick(Event:MouseEvent):void {             trace('# onHill clicked');
            addChild(pondPage);             trace(' add');
            removeChild(startPage);         trace(' remove');
        }
    }
}
分享给朋友:
您可能感兴趣的文章:
随机阅读: