【问题标题】:i getting stack overflow error in as3我在 as3 中遇到堆栈溢出错误
【发布时间】:2012-11-14 06:06:48
【问题描述】:

我是 Flash 初学者,但不是面向对象编程的初学者。 我正在制作一个商业模拟多人棋盘游戏。这个敬礼函数是从 .fla 文件调用的,这个 salute 函数调用 moveto 函数。salute 函数工作正常。但是问题来自 dialog2.x=200;moveto()。如果我删除该行,问题会转到下一行,请帮助我

 public function salute(a:Array)
{
    a[0].x=200;
    a[0].y=200;
    if(k==0)
    {
    tilehold.amount.text=String(amount);
    tilehold.networth.text=String(networth);
    tilehold.playertitle.text=playername;
    dialog2=a[1];
    dialog3=a[2];
    dialog4=a[3];
    dialog5=a[4];
    dialog6=a[5];
    forbuild=a[6];
    k=1
    }
    a[0].dialogtext.text=playername+"'s turn";
    a[0].addEventListener(MouseEvent.MOUSE_DOWN,nothing1);
    function nothing1(e:MouseEvent)
    {
        a[0].x=1000;
        e.target.removeEventListener(MouseEvent.MOUSE_DOWN,nothing1);
        a[7].x=-10;
        a[7].y=-10;
        a[7].addEventListener(MouseEvent.CLICK,wheelspin);
    }
    function wheelspin(e:MouseEvent)
    {
        spinvalue=Math.floor(Math.random()*10);
        a[7].wheel.spin(spinvalue);
        a[7].wheel.gotoAndPlay(2);
        e.target.removeEventListener(MouseEvent.CLICK,wheelspin);
        a[7].addEventListener(MouseEvent.CLICK,wheelmove);
    }
    function wheelmove(e:MouseEvent)
    {
        a[7].x=1000;
        e.target.addEventListener(MouseEvent.CLICK,wheelmove);

    }
    moveto();
}
public function moveto()
{
    if(spinvalue==0||spinvalue==7||spinvalue==8||spinvalue==9)
    {
        if(nooflandsown==0)
        {

/* 上面的工作正常,但是这个错误表明下面的行*/

                            dialog2.x=200;
            dialog2.dialogtext.text="you dont own any land";
            dialog2.okbut.addEventListener(MouseEvent.CLICK,nothing2);
            function nothing2(e:MouseEvent)
            {
                dialog2.x=1000;
                e.target.removeEventListener(MouseEvent.CLICK,nothing2);
                endturn();
            }

        }
        else
        {
            dialog3.x=200;
            dialog3.y=200;
            dialog3.dialogtext.text="do you want to build";
            dialog3.yesbut.addEventListener(MouseEvent.CLICK,wanttobuild);
            dialog3.nobut.addEventListener(MouseEvent.CLICK,nothing3);
            function wanttobuild(e:MouseEvent)
            {
            dialog3.x=1000;
            e.target.removeEventListener(MouseEvent.CLICK,wanttobuild);
            dialog3.nobut.removeEventListener(MouseEvent.CLICK,nothing3);
             chooseland();
            }
            function nothing3(e:MouseEvent)
            {
                dialog3.x=1000;
                dialog3.yesbut.removeEventListener(MouseEvent.CLICK,wanttobuild);
            e.target.removeEventListener(MouseEvent.CLICK,nothing3);
            endturn();
            }
        }
    }
    else
    {
        l=(currentposition+spinvalue)%18;
        this.pos=l;
        switch(currentposition)
        {
            case 1:
            this.gotoAndPlay(15);
            break;
            case 2:
            this.gotoAndPlay(25);
            break;
            case 3:
            this.gotoAndPlay(35);
            break;
            case 4:
            this.gotoAndPlay(55);
            break;
            case 5:
            this.gotoAndPlay(65);
            break;
            case 6:
            this.gotoAndPlay(75);
            break;
            case 7:
            this.gotoAndPlay(85);
            break;
            case 8:
            this.gotoAndPlay(105);
            break;
            case 9:
            this.gotoAndPlay(115);
            break;
            case 10:
            this.gotoAndPlay(125);
            break;
            case 11:
            this.gotoAndPlay(135);
            break;
            case 12:
            this.gotoAndPlay(145);
            break;
            case 13:
            this.gotoAndPlay(165);
            break;
            case 14:
            this.gotoAndPlay(175);
            break;
            case 15:
            this.gotoAndPlay(195);
            break;
            case 16:
            this.gotoAndPlay(205);
            break;
            case 17:
            this.gotoAndPlay(215);
            break;
            default:
            this.gotoAndPlay(1);
        }
        currentposition=l;


    }
}

请帮帮我。我通过更改整个代码尝试了很多。但我无法弄清楚

【问题讨论】:

  • 不知道为什么会在没有解释的情况下获得如此多的反对票。无论如何,你可以发布你得到的堆栈溢出错误。如果dialog2.x = 200; 导致堆栈溢出错误,我只能假设您已经覆盖了显示对象的xsetter 方法。可能看起来像override public function set x(value:Number) { this.x = value; },这只是一个猜测。
  • 检查一下:在轮子旋转中你说 a[7].addEventListener(MouseEvent.CLICK,wheelmove);然后在轮子移动中再次说 e.target.addEventListener(MouseEvent.CLICK,wheelmove);这又是 [7]。

标签: actionscript-3


【解决方案1】:

首先,为什么要在事件监听器中添加事件监听器(函数wheelmove)?其次,检查您是否真的退出了moveto() 函数而没有再次调用salute(),如果没有,那么您必须在其他地方更改您的代码流逻辑。另外,如果代码较大,您可以使用 Internet 上的 PasteBin 服务来托管代码。

【讨论】:

  • 对不起,这是一个 removeEventlistener (wheelmove),退出 moveto() 是什么意思,这一步进一步调用另一个函数
  • 是的,moveto() 正在调用 endturn(),而 endturn() 又调用了 salute()?您已经有效地创建了一个无限递归场景。您必须重做逻辑,以便您的函数最终结束执行,并且下一阶段的执行应该从事件侦听器开始。这就是所谓的架构,将您的代码变成更小的块,并设计一种方式让它们作为单个实体移动。
  • 错误:错误 #1023:发生堆栈溢出。在 game_fla::MainTimeline/frame5()[game_fla.MainTimeline::frame5:75] ReferenceError:错误 #1069:在 Land1 上找不到属性成本并且没有默认值。在 Icon4/buyorrent()[D:\game\Icon4.as:318] 在 Icon4/frame35()[Icon4::frame35:5]
  • a 是一个动画片段数组,其中 a[7] 是我在游戏中使用的轮子
  • 请提供函数源代码:endturn()chooseland(),例如通过更新问题,并再次检查是否有调用moveto(),而实际上它是从moveto()调用的,甚至如果是间接的。
猜你喜欢
  • 2012-02-07
  • 2021-12-13
  • 1970-01-01
  • 1970-01-01
  • 2020-11-13
  • 1970-01-01
  • 1970-01-01
  • 2014-01-26
  • 2019-02-16
相关资源
最近更新 更多