操作脚本3错误1120访问未定义的属性

时间:2013-05-26 17:30:54

标签: actionscript-3 compiler-errors flash-cs5

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

  

“C:\ Users \ Dan \ Desktop \ Flash \ Interactive Story Book \ Main.as,Line 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;
    }


    }
}
}

1 个答案:

答案 0 :(得分:1)

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

注意:你在结尾处放置了大量的括号,因此整个文件实际上有正确数量的大括号,只有onGrowButtonClickonShrinkButtonClick位于onDownButtonClick内。您的代码目前类似于:

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

建议:找到带有大括号匹配的好文本编辑器。 ActionScript接近于JavaScript - 所以找到一个好的可以工作。