错误1120访问未定义的属性

时间:2013-05-28 03:36:25

标签: actionscript-3

我是动作脚本3的新手,我不断收到两个1120错误。其中一个错误是

C:\Users\Server\Desktop\New folder\InteractiveStoryBook\Main.as, Line 31  1120: Access of undefined property onFrogMouseOver  

,另一个错误是

C:\Users\Server\Desktop\New folder\InteractiveStoryBook\Main.as, Line 32    1120: Access of undefined property onFrogClick. 

我正确添加了所有实例,但仍然出现错误。 以下是错误所在区域的代码:

public function Main()
    {
        hillPage = new HillPage();
        pondPage = new PondPage();
        startPage = new StartPage();
        addChild(pondPage);
        startPage.hillButton.addEventListener(MouseEvent.CLICK, onHillButtonClick);
        startPage.pondButton.addEventListener(MouseEvent.CLICK, onPondButtonClick);
        hillPage.backToStartButton.addEventListener(MouseEvent.CLICK, onBackButtonClick_Hill);
        pondPage.backToStartButton.addEventListener(MouseEvent.CLICK, onBackButtonClick_Pond);
        hillPage.upButton.addEventListener(MouseEvent.CLICK, onUpButtonClick);
        hillPage.downButton.addEventListener(MouseEvent.CLICK, onDownButtonClick);
        hillPage.growButton.addEventListener(MouseEvent.CLICK, onGrowButtonClick);
        hillPage.shrinkButton.addEventListener(MouseEvent.CLICK, onShrinkButtonClick);
        hillPage.visibilityButton.addEventListener(MouseEvent.CLICK, onVisibilityButtonClick);
        hillPage.lookButton.addEventListener(MouseEvent.CLICK, onLookButtonClick);
        hillPage.leftButton.addEventListener(MouseEvent.CLICK, onLeftButtonClick);
        hillPage.rightButton.addEventListener(MouseEvent.CLICK, onRightButtonClick);
        pondPage.frog.addEventListener(MouseEvent.MOUSE_OVER, onFrogMouseOver);
        pondPage.frog.addEventListener(MouseEvent.CLICK, onFrogClick);

        function onHillButtonClick(event:MouseEvent):void
        {
            addChild(hillPage);
            removeChild(startPage);
        }
        function onPondButtonClick(event:MouseEvent):void
        {
            addChild(pondPage);
            removeChild(startPage);
        }
        function onBackButtonClick_Hill(event:MouseEvent):void
        {
            addChild(startPage);
            removeChild(hillPage);

        }
        function onBackButtonClick_Pond(event:MouseEvent):void
        {
            addChild(startPage);
            removeChild(pondPage);
        }
        function onUpButtonClick(event:MouseEvent):void
        {
            hillPage.cat.y -=  15;
            if (hillPage.cat.y < 90)
            {
                hillPage.cat.y = 90;

            }
            trace(hillPage.cat.y);
        }
        function onDownButtonClick(event:MouseEvent):void
        {
            hillPage.cat.y +=  15;
            if (hillPage.cat.y > 238)
            {
                hillPage.cat.y = 238;
            }
            trace(hillPage.cat.y);
        }
        function onGrowButtonClick(event:MouseEvent):void
        {
            hillPage.cat.scaleX +=  0.1;
            hillPage.cat.scaleY +=  0.1;
        }
        function onShrinkButtonClick(event:MouseEvent):void
        {
            hillPage.cat.scaleX -=  0.1;
            hillPage.cat.scaleY -=  0.1;
        }
        function onVisibilityButtonClick(event:MouseEvent):void
        {
            hillPage.cat.visible = ! hillPage.cat.visible;
        }
        function onLookButtonClick(event:MouseEvent):void
        {
            hillPage.cat.leftEye.rotation +=  20;
            hillPage.cat.rightEye.rotation +=  20;
        }
        function onLeftButtonClick(event:MouseEvent):void
        {
            if (hillPage.cat.x >= 240)
            {
                hillPage.cat.x -=  15;
            }
        }
        function onRightButtonClick(event:MouseEvent):void
        {
            if (hillPage.cat.x <= 487)
            {
                hillPage.cat.x +=  15;
            }
            function onFrogMouseOver(event:MouseEvent):void
            {
                pondPage.frog.goToAndStop(2);
                pondPage.frog.removeEventListener(MouseEvent.MOUSE_OVER, onFrogMouseOver);
            }
            function onFrogClick(event:MouseEvent):void
            {
                pondPage.frog.goToAndStop(3);
                pondPage.frog.removeEventListener(MouseEvent.CLICK, onFrogClick);
            }
        }
    }
}
}

之前的一切都只是变量,并扩展了movieclip和所有其他东西。谢谢!

1 个答案:

答案 0 :(得分:2)

您的方法onFrogMouseOveronFrogClick嵌套在onRightButtonClick中。

将它们移出onRightButtonClick块:

function onRightButtonClick(event:MouseEvent):void
{
    if(hillPage.cat.x <= 487)
    {
        hillPage.cat.x +=  15;
    }

    // They were previously defined here.
    // Removed and put below.
}

function onFrogMouseOver(event:MouseEvent):void
{
    pondPage.frog.goToAndStop(2);
    pondPage.frog.removeEventListener(MouseEvent.MOUSE_OVER, onFrogMouseOver);
}

function onFrogClick(event:MouseEvent):void
{
    pondPage.frog.goToAndStop(3);
    pondPage.frog.removeEventListener(MouseEvent.CLICK, onFrogClick);
}