我創建了一個自定義類(.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