我已經在舞臺上添加了許多對象(在Achievements.as類中)來創建成就板。當有人按下後退按鈕時,我想從main.as類中刪除所有的孩子。另外,有沒有辦法創建一個自定義textField類,其中每個textField.selectable = false,而不必分別分配給每個。刪除不同級別的孩子As3
public static var texts:Vector.<TextField> = new Vector.<TextField>();
public static var titleTxt:Vector.<TextField> = new Vector.<TextField>();
public static var descripTxt:Vector.<TextField> = new Vector.<TextField>();
public static var rewardTxt:Vector.<TextField> = new Vector.<TextField>();
public static var achCoins:Vector.<MovieClip> = new Vector.<MovieClip>();
for (var j:int = 0; j < 30; j++)
{
achCoins[j].x = 240;
achCoins[j].y = 45 + j * 70;
addChild(achCoins[j]);
descripTxt[j].x = 0;
descripTxt[j].y = 30 + 70 * j;
//descripTxt[j].antiAliasType = AntiAliasType.ADVANCED;
descripTxt[j].defaultTextFormat = tf2;
descripTxt[j].text = descriptext[j];
descripTxt[j].embedFonts = true;
addChild(descripTxt[j]);
titleTxt[j].x = 0;
titleTxt[j].y = j * 70;
//titleTxt[j].antiAliasType = AntiAliasType.ADVANCED;
titleTxt[j].defaultTextFormat = tf3;
titleTxt[j].text = titletext[j];
titleTxt[j].embedFonts = true;
addChild(titleTxt[j]);
rewardTxt[j].x = 200;
rewardTxt[j].y = 30 + j * 70;
rewardTxt[j].text = reward[j].toString();
rewardTxt[j].setTextFormat(tf1);
rewardTxt[j].embedFonts = true;
rewardTxt[j].textColor = 0x000000;
addChild(rewardTxt[j]);
texts[j].text = Main.achievement[j] + "/" + totnum[j];
texts[j].setTextFormat(tf1);
texts[j].x = 200;
texts[j].y = j * 70;
texts[j].embedFonts = true;
addChild(texts[j]);
}
然後我使用此代碼
for (var k:int = 0; k < 30; k++)
{
removeChild(achievementback.descripTxt[k]);
removeChild(achievementback.titleTxt[k]);
removeChild(achievementback.rewardTxt[k]);
removeChild(achievementback.texts[k]);
}
我得到的錯誤
1119: Access of possibly undefined property descripTxt through a reference with static type Achievements.
for (var i:int = 0; i < 30; i++)
{
texts.push(new TextField());
titleTxt.push(new TextField());
rewardTxt.push(new TextField());
descripTxt.push(new TextField());
achCoins.push(new coinSmall());
{
在Achievements.as刪除兒童類
public function RemoveTextboxes(){
for (var k:int = 0; k < 30; k++)
{
removeChild(descripTxt[k]);
removeChild(titleTxt[k]);
removeChild(rewardTxt[k]);
removeChild(texts[k]);
}
}
在Main.as類
achievementback.RemoveTextBoxes()
這裏是我的全部成果二等
package
{
import flash.display.MovieClip;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.display.Shape;
import flash.display.Graphics;
import flash.text.AntiAliasType;
public class Achievements extends MovieClip
{
public var backRect:Shape = new Shape();
public var coinsmall:MovieClip = new coinSmall();
public var titleText:MyTextField = new MyTextField();
public var descripText:MyTextField = new MyTextField();
public var reward_txt:MyTextField = new MyTextField();
public static var texts:Vector.<TextField> = new Vector.<TextField>();
public static var titleTxt:Vector.<TextField> = new Vector.<TextField>();
public static var descripTxt:Vector.<TextField> = new Vector.<TextField>();
public static var rewardTxt:Vector.<TextField> = new Vector.<TextField>();
public static var achCoins:Vector.<MovieClip> = new Vector.<MovieClip>();
public var tf1:TextFormat = new TextFormat();
public var tf2:TextFormat = new TextFormat();
public var tf3:TextFormat = new TextFormat();
//Achievement Variables
public var descriptext:Array = new Array();
public static var acharr:Array = new Array();
public var titletext:Array = new Array();
public var reward:Array = new Array(25,50,250,500,200,2000,10,100,500,10,25,50,10,25,100,25,25,50,50,100,500,500,5,5,5,50,10,50,100,250);
public function Achievements()
{
//Defining Objects
//Set Up Text Formats
//Text Format 1
tf1.font = "Myriad pro";
tf1.size = 20;
tf1.color = 0x660000;
tf1.align = "right";
//Text Format 2
tf2.size = 16;
tf2.color = 0xB8461D;
tf2.font = "Myriad Pro";
tf2.align = "center";
//Text Format 3
tf3.size = 23;
tf3.color = 0x660000;
tf3.font = "Myriad Pro";
tf3.align = "center";
//Text Box: Fraction Completed
//Text Box: Reward Amount For Each Achievement
//Text Box: Description of Achievement
for (var i:int = 0; i < 30; i++)
{
texts.push(new TextField());
titleTxt.push(new TextField());
rewardTxt.push(new TextField());
descripTxt.push(new TextField());
achCoins.push(new coinSmall());
backRect.graphics.beginFill(0x86B46D, 0.7);
backRect.graphics.drawRoundRect(0, i*70, 300, 60, 10, 10);
backRect.graphics.endFill();
addChild(backRect);
}
//change the text in a loop;
var acharr:Array = new Array();
var totnum:Array = new Array(50,100,500,1000,5,10,10,100,500,25,50,100,1,1,3,1,50,100,50,100,2,5,5,5,5,20,10,50,100,250);
for (var j:int = 0; j < 30; j++)
{
achCoins[j].x = 240;
achCoins[j].y = 45 + j * 70;
addChild(achCoins[j]);
descripTxt[j].width = 225;
descripTxt[j].height = 30;
descripTxt[j].x = 0;
descripTxt[j].y = 30 + 70 * j;
//descripTxt[j].antiAliasType = AntiAliasType.ADVANCED;
descripTxt[j].defaultTextFormat = tf2;
descripTxt[j].text = descriptext[j];
descripTxt[j].embedFonts = true;
addChild(descripTxt[j]);
titleTxt[j].width = 225;
titleTxt[j].height = 30;
titleTxt[j].x = 0;
titleTxt[j].y = j * 70;
//titleTxt[j].antiAliasType = AntiAliasType.ADVANCED;
titleTxt[j].defaultTextFormat = tf3;
titleTxt[j].text = titletext[j];
titleTxt[j].embedFonts = true;
addChild(titleTxt[j]);
rewardTxt[j].width = 100;
rewardTxt[j].height = 30;
rewardTxt[j].selectable = false;
rewardTxt[j].x = 200;
rewardTxt[j].y = 30 + j * 70;
rewardTxt[j].text = reward[j].toString();
rewardTxt[j].setTextFormat(tf1);
rewardTxt[j].embedFonts = true;
rewardTxt[j].textColor = 0x000000;
addChild(rewardTxt[j]);
texts[j].text = acharr[j] + "/" + totnum[j];
texts[j].setTextFormat(tf1);
texts[j].width = 100;
texts[j].height = 30;
texts[j].selectable = false;
texts[j].x = 200;
texts[j].y = j * 70;
texts[j].embedFonts = true;
addChild(texts[j]);
}
}
public function RemoveTextboxes(){
for (var k:int = 0; k < 30; k++)
{
removeChild(descripTxt[k]);
removeChild(titleTxt[k]);
removeChild(rewardTxt[k]);
removeChild(texts[k]);
}
}}
} 的陣列descriptext:數組acharr:數組titletext:陣列中的所有在他們正確的內容,但它是大量的文字,所以我把它張貼此
這裏是我使用從Main.as
除去孩子的代碼
是否在添加之前刪除它們? – Xela 2015-03-31 00:14:13
@Xela我將他們刪除後,但在不同的類 – TomMcmann 2015-03-31 03:35:09