我创建了一个自定义类(.as在下面:)。它存在于我的主要时间线中的三个实例(panel1,panel2和panel3),目前只有一个关键帧。为什么自定义类的构造函数被多次调用?
当我调试我的文件时,在第1帧中为每个实例调用构造函数。凉。然而,稍后的构造函数被称为每个实例AGAIN,消除我所做的任何更改。
将实例从库中拖放到舞台上。还有我的文字中没有“=新Scorepanel()线。
什么触发此,我该如何预防呢?
--Ken(难以置信的沮丧)富兰克林
{
import flash.display.MovieClip;
import fl.text.TLFTextField;
public class scoreunit extends MovieClip
{
private var team:String = "WHOAMI";
private var points:Number = 0;
private var scorevalue:String;
private var teamname:String;
private var inited:Boolean = false;
function scoreunit()
{
if (! inited)
{
this.teamname = team;
this.scorevalue = String(points);
var teamnamebox=new TLFTextField();
teamnamebox.x = 2.25;
teamnamebox.y = 295.25;
teamnamebox.width = 295.25;
teamnamebox.height = 70;
teamnamebox.text = team;
var scorevaluebox=new TLFTextField();
scorevaluebox.x = 2.25;
scorevaluebox.y = 95.80;
scorevaluebox.width = 295;
scorevaluebox.height = 97.5;
scorevaluebox.text = scorevalue;
trace("I set the starting values");
trace("teamnamebox = ",teamnamebox.text);
trace("scorevalue = ",scorevaluebox.text);
inited = true;
}
}
public function score():Number
{
return points;
}
public function winpoints(n:Number)
{
points += n;
scorevalue = String(points);
scorevaluebox.text = scorevalue;
}
public function losepoints(n:Number)
{
points -= n;
scorevalue = String(points);
scorevaluebox.text = scorevalue;
}
public function setname(s:String)
{
team = s;
teamname = team;
teamnamebox.text = s;
trace("I changed the name to ",teamnamebox.text);
}
public function buzzin()
{
this.gotoAndStop("buzzedin");
}
public function makeddselect()
{
this.gotoAndStop("ddtarget");
}
public function makeyay(y:Number)
{
switch (y)
{
case 1 :
this.gotoAndStop("yay1");
break;
case 2 :
this.gotoAndStop("yay2");
break;
case 3 :
this.gotoAndStop("yay3");
break;
case 4 :
this.gotoAndStop("yay4");
break;
case 5 :
this.gotoAndStop("yay5");
break;
case 6 :
this.gotoAndStop("yay6");
break;
default :
trace("CRASH! "+y+" IS NOT A VALID YAY!");
}
}
public function makeboo(b:Number)
{
switch (b)
{
case 1 :
this.gotoAndStop("boo1");
break;
case 2 :
this.gotoAndStop("boo2");
break;
case 3 :
this.gotoAndStop("boo3");
break;
case 4 :
this.gotoAndStop("boo4");
break;
case 5 :
this.gotoAndStop("boo5");
break;
case 6 :
this.gotoAndStop("boo6");
break;
default :
trace("CRASH! "+b+" IS NOT A VALID BOO!");
}
}
public function makescrewing()
{
this.gotoAndStop("evilface");
}
public function makescrewed()
{
this.gotoAndStop("screwed");
}
public function makesplat()
{
this.gotoAndStop("eekface");
}
public function makefreeze()
{
this.gotoAndStop("frozen");
}
public function makehome()
{
this.gotoAndStop("inactive");
}
}
}
使用它来调试:'var s:String =''; var mc = this;做{s + = mc.toString(); mc = mc.parent; } while(mc!= null);痕迹; ' – scibuff 2012-03-10 16:05:04
我在开始时收到了三次:[object scoreunit] [object MainTimeline]。 20帧之后我收到了三次:[object scoreunit] [对象MainTimeline] [object Stage] – 2012-03-10 16:20:23
那是在我给舞台添加了一个键盘监听器之后。嗯。 – 2012-03-10 16:22:43