简体   繁体   中英

Action Script 3 Error 1120 Access of undefined Property

I am having problems with my code after i added the grow and shrink button code. it is telling me

"C:\\Users\\Dan\\Desktop\\Flash\\Interactive Story Book\\Main.as, Line 28 1120: Access of undefined property onShrinkButtonClick."

"C:\\Users\\Dan\\Desktop\\Flash\\Interactive Story Book\\Main.as, Line 29 1120: Access of undefined property onGrowButtonClick.

Instance names are correct and are not the same as my AsLinkage or the object name.

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


    }
}
}

You have previous function ( function onDownButtonClick(event:MouseEvent):void ) is missing closing } . As result onGrowButtonClick becomes inner function of onDownButtonClick and hence not visible outside.

Note: you put plenty of closing braces at the end so whole file actually have proper number of braces, just onGrowButtonClick and onShrinkButtonClick are inside onDownButtonClick . Your code is currently similar to:

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

Suggestion: find good text editor with brace matching. ActionScript is close to JavaScript - so finding good one for either would work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM