1

我正在尝试从另一个类中的播放器类调用打孔函数,但由于某种原因,它给了我这个错误:

1180: Call to a possibly undefined method Punch.

我不确定为什么它会给我这个错误。我什至公开了这些功能。

这是我从中调用它的类:

package 
{
    public class Player extends MovieClip
    {
        public function Player()
        {
            stage.addEventListener(KeyboardEvent.KEY_DOWN,KeyDown);
            stage.addEventListener(KeyboardEvent.KEY_DOWN,KeyPressed);
            addEventListener(Event.ENTER_FRAME,Update);
        }


        function KeyPressed(event:KeyboardEvent):void
        {
            //If on floor
            if (CanJump)
            {
                //If A key is down
                if (event.keyCode == 65)
                {
                    //Punch
                    Punch(true);
                }
            }
        }


        function Update(event:Event)
        {
            //Do stuff
        }

    }
}

这就是我要调用的:

package 
{

    public class ComboSequence extends ComboHandler
    {

        public function ComboSequence(clipName:String, par:BaseObject, _oList:ObjectList)
        {
            // constructor code
            super(clipName, par, _oList);

        }

        public function Punch(PunchKey:Boolean)
        {
            if (currentAttack != null)
            {
                if (Recovery <= 0 && FollowUpTime > 0)
                {
                    currentAttack = currentAttack.GetNextAttack(PunchKey);

                    if (currentAttack != null)
                    {
                        SetAnimation(currentAttack.animName);
                        Recovery = currentAttack.Recovery;
                        FollowUpTime = currentAttack.Recovery + 25;
                    }
                }
            }

            if (FollowUpTime > 0)
            {
                FollowUpTime--;
            }
            else
            {
                currentAttack = null;
            }

            if (Recovery > 0)
            {
                Recovery--;
            }
        }

    }

}
4

2 回答 2

0

您需要将ComboSequence导入Player类并调用Punch虽然像 ComboSequence.Punch一样。 andypaxo在他的帖子中是正确的,你需要在Player类的某个地方实例化它。

但是,关于您的代码的一个注意事项是,您不应该用大写字母命名函数。类名通常以大写字母开头,但不是其中的方法。

package 
{
    import ComboSequence; //you may need the package path if its in a package, something like com.classes.ComboSequence, where com.classes is the folder that ComboSequence is saved.

    public class Player extends MovieClip
    {
        public function Player()
        {
            stage.addEventListener(KeyboardEvent.KEY_DOWN,KeyDown);
            stage.addEventListener(KeyboardEvent.KEY_DOWN,KeyPressed);
            addEventListener(Event.ENTER_FRAME,Update);
        }


        function KeyPressed(event:KeyboardEvent):void
        {
            //If on floor
            if (CanJump)
            {
                //If A key is down
                if (event.keyCode == 65)
                {
                    //Punch
                    ComboSequence.Punch(true);
                }
            }
        }


        function Update(event:Event)
        {
            //Do stuff
        }

    }
}

此外,关于您的“缺少 rightParen”错误,rightParen表示右括号,或者)leftParen将是(。该错误意味着您在某处缺少 a ) 。通常,这可能意味着您在某处添加了一个额外的括号,从而关闭了您不想关闭的括号部分,这将在某处留下一个未配对的括号。

于 2013-08-22T21:34:22.257 回答
0

当您Punch()在播放器类中自行调用时,ActionScript 正在寻找一种Player.Punch()方法。你的方法在ComboSequence课堂上。您可能正在尝试执行以下操作:

var comboSequence:ComboSequence = new ComboSequence();
comboSequence.Punch()

请记住,虽然此代码将运行,但它可能不会执行您希望它执行的操作。我猜你想ComboSequence在你的播放器对象中保留一个实例。如果这对您没有意义,那么最好阅读一些有关 ActionScript 和一般面向对象编程的背景知识。

于 2013-08-22T18:11:30.627 回答