【发布时间】: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