0

添加增长和缩小按钮代码后,我的代码出现问题。它在告诉我

“C:\Users\Dan\Desktop\Flash\Interactive Story Book\Main.as,第 28 行 1120:访问未定义属性 onShrinkBut​​tonClick。”

“C:\Users\Dan\Desktop\Flash\Interactive Story Book\Main.as,第 29 行 1120:访问未定义属性 onGrowButtonClick。

实例名称是正确的,与我的 AsLinkage 或对象名称不同。

package 
{

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

public class Main extends MovieClip
{

    var startPage:StartPage;
    var hillPage:HillPage;
    var lakePage:LakePage;

    public function Main()
    {
        startPage = new StartPage();
        hillPage = new HillPage();
        lakePage = new LakePage();
        addChild(hillPage);

        //Add event listeners
        startPage.buttonHill.addEventListener(MouseEvent.CLICK, onHillButtonClick);
        startPage.buttonLake.addEventListener(MouseEvent.CLICK, onLakeButtonClick);
        hillPage.btsButton.addEventListener(MouseEvent.CLICK, onStartButtonClick_hill);
        lakePage.btsButton.addEventListener(MouseEvent.CLICK, onStartButtonClick_lake);
        hillPage.upButton.addEventListener(MouseEvent.CLICK, onUpButtonClick);
        hillPage.downButton.addEventListener(MouseEvent.CLICK, onDownButtonClick);
        hillPage.shrinkButton.addEventListener(MouseEvent.CLICK, onShrinkButtonClick);
        hillPage.growButton.addEventListener(MouseEvent.CLICK, onGrowButtonClick);
    }
    //Event handlers
    function onHillButtonClick(event:MouseEvent):void
    {
        addChild(hillPage);
        removeChild(startPage);
    }
    function onLakeButtonClick(event:MouseEvent):void
    {
        addChild(lakePage);
        removeChild(startPage);
    }
    function onStartButtonClick_hill(event:MouseEvent):void
    {
        addChild(startPage);
        removeChild(hillPage);
    }
    function onStartButtonClick_lake(event:MouseEvent):void
    {
        addChild(startPage);
        removeChild(lakePage);
    }
    function onUpButtonClick(event:MouseEvent):void
    {
        hillPage.cat.y -=15
        if(hillPage.cat.y < 90)
        {
            hillPage.cat.y =90
        }
    }
    function onDownButtonClick(event:MouseEvent):void
    {
        hillPage.cat.y +=15
        if(hillPage.cat.y >190)
        {
            hillPage.cat.y =190
        }
    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;
    }
    
    
    }
}
}
4

1 回答 1

1

您之前的函数 ( function onDownButtonClick(event:MouseEvent):void) 缺少关闭}。结果onGrowButtonClick成为内部功能,onDownButtonClick因此在外部不可见。

注意:你在末尾放了很多右大括号,所以整个文件实际上有适当数量的大括号,只是onGrowButtonClickonShrinkButtonClick在里面onDownButtonClick。您的代码目前类似于:

function onDownButtonClick(event:MouseEvent):void
{
   function onGrowButtonClick() ...;
   function onShrinkButtonClick() ...;
}

建议:找个好的带有大括号匹配的文本编辑器。ActionScript 与 JavaScript 很接近——因此为任何一种找到合适的都可以。

于 2013-05-26T17:40:20.443 回答