Actionscript (Adobe Animate actionscrtip)我如何使用name、arry和lib()将特定符号从舞台上移除?
我对此非常失望 首先让您了解我的代码-我的目标是让用户随机选择一个单词,让每个字母都出现在一个框中。 然后,如果用户单击一个名为Pick a word的按钮,将选择另一个单词,并显示正确数量的框 我有一系列这样的词:Actionscript (Adobe Animate actionscrtip)我如何使用name、arry和lib()将特定符号从舞台上移除?,actionscript,jquery-animate,adobe,removechild,lib,Actionscript,Jquery Animate,Adobe,Removechild,Lib,我对此非常失望 首先让您了解我的代码-我的目标是让用户随机选择一个单词,让每个字母都出现在一个框中。 然后,如果用户单击一个名为Pick a word的按钮,将选择另一个单词,并显示正确数量的框 我有一系列这样的词: var word_group_1 = ["abolsh", "absorbent", "betrayal", "frutish", "commensurate", "eonfident", "zite"] 我用这个函数从数组中随机选择一个单词,然后拼接它。。工作完美: fu
var word_group_1 = ["abolsh", "absorbent", "betrayal", "frutish", "commensurate", "eonfident", "zite"]
我用这个函数从数组中随机选择一个单词,然后拼接它。。工作完美:
function random_word_genereator() {
random = randomNumber(0, word_group_1.length);
//putting the chosen word from array in the chosen word variable
chosen_word = word_group_1[random]
//affter we used the chosen word were removing it from the awway
word_group_1.splice(random, 1)
//spliting the chosen word into an array
chosen_word_letters_arry = chosen_word.split("")
}
点击pick a word的按钮,我创建了5个Movieclip的实例,我的库中有一个蓝色的框,将文本放入其中,其中的文本如下:
function create_boxes(e)
{
//to know wichh word has been displayed to the user//
old_word=chosen_word
random_word_genereator()
for (i=0;i<chosen_word.length;i++){
cell_boxes = new lib.cell_box();
stage.addChild(cell_boxes)
cell_boxes.name="cell_box"+i;
cell_boxes.x=(xlocation * i) + 50
cell_boxes.y = 80;
output = new createjs.Text();
cell_boxes.addChild(output)
output.text=chosen_word_letters_arry[i]
}
事件处理在第一次单击时工作正常
在舞台上选择和显示的单词
我的问题是当我再次点击按钮时,选择一个单词
它没有删除正确数量的框
我把visible false放在我需要删除的旧单词所在的框中
但是它被搞砸了
有时,它的工作,开关从12个字母的单词,以4个一。
但这应该是运气。哈哈,我很想让它发挥作用!这是我的学业计划
请帮帮我 简单的答案,即插即用到您的代码中:
js
...
//to know wichh word has been displayed to the user//
old_word=chosen_word
random_word_genereator()
for (i = 0; i < stage.numChildren; i++) // Loop through all children of the stage
if (stage.getChildAt(i) is lib.cell_box) // Checks if the child is a lib.cell_box
stage.removeChildAt(i--); // Removes child from stage and decrements i
for (i=0;i<chosen_word.length;i++){
...
然后在Box类中设置文本。首先感谢您的回答。我不知道什么是课堂行动脚本。你刚才写的空白。它能在ActionScript2上工作吗?你有我看不懂的网站吗?我以为你用的是AS3。编辑my answer.void意味着函数不会返回任何内容。doSomething:void将不返回任何内容,但如果doSomething:String是您的返回类型,您可以像使用变量一样使用它。变量字:String=generateWord;例如
var boxes:MovieClip = new MovieClip();
boxes.y = 80;
addChild(boxes);
...
function createBoxes(word:String):void {
// Remove boxes first
while (boxes.numChildren > 0)
boxes.removeChildAt(0);
// Add boxes
for each(var c:String in word.split("")) {
var box:Box = new Box(c);
box.x = boxes.width + 50;
boxes.addChild(box);
}
}