actionscript-3 - 函数执行次数和激活问题
问题描述
下面是简单匹配字母与影子游戏的代码。从所有 24 个字母中随机选择的 4 个字母连同它们的影子一起出现在屏幕上。
这些字母是可拖动的,如果它们碰到它们的影子,它们就会粘在上面。对应的对象分别命名为:alfa、bita、gama、delta及其阴影:alfa_shadow等。
每个字母对应一个分数:score1、score2、score 3、score4。当一个字母击中阴影目标时,它的分数从 0 变为 1。在分数调整线下面有一个分数轨迹线,只是为了检查发生了什么。
还有一个分数检查功能“score_check”,它检查四个分数是否都为1,然后移动到下一个场景。
我有两个问题:
1.
第一次匹配字母时一切正常。
第二次匹配一个字母时,跟踪线工作两次
第三次匹配一个字母,跟踪线工作三次
第四次匹配一个字母,跟踪线工作四次。
无论我匹配字母和阴影的顺序如何,都会发生这种情况。我不明白为什么会发生这种情况,每个字母的代码完全相同,只更改变量和函数的名称。
- score_check 函数永远不会激活。我什至尝试用 || 替换 && 不成功。
有任何想法吗?
谢谢
import flash.text.engine.EastAsianJustifier;
import flash.events.Event;
var gramata:Array = new Array(cpencil_1, cpencil_2, cpencil_3, cpencil_4, cpencil_5, cpencil_6, cpencil_7, cpencil_8, cpencil_9, cpencil_10, cpencil_11, cpencil_12, cpencil_13, cpencil_14, cpencil_15, cpencil_16, cpencil_17, cpencil_18, cpencil_19, cpencil_20, cpencil_21, cpencil_22, cpencil_23, cpencil_24);
var shadows:Array = new Array(shadow_01, shadow_02, shadow_03, shadow_04, shadow_05, shadow_06, shadow_07, shadow_08, shadow_09, shadow_10, shadow_11, shadow_12, shadow_13, shadow_14, shadow_15, shadow_16, shadow_17, shadow_18, shadow_19, shadow_20, shadow_21, shadow_22, shadow_23, shadow_24);
var gramata_choice:Array = [];
var shadow_choice:Array = [];
var choice:Array = [];
var score:Number = 0;
var score1:Number = 0;
var score2:Number = 0;
var score3:Number = 0;
var score4:Number = 0;
function score_check():void
{
if(score1==1 && score2==1 && score3==1 && score4==1)
{
gotoAndStop(1, "Scene2");
}
}
function dialekse_auto():void
{
for (var i:uint=0; i<4; i++)
{
choice[i] = uint(Math.random()*gramata.length);
gramata_choice[i] = gramata[choice[i]];
shadow_choice[i] = shadows[choice[i]];
trace(gramata_choice[i])
}
}
function emfanise_auto():void
{
var alfa_shadow = new shadow_choice[0];
alfa_shadow.x = 300;
alfa_shadow.y = 200;
addChild(alfa_shadow);
var alfa = new gramata_choice[0];
alfa.x = 100;
alfa.y = 400;
addChild(alfa);
alfa.mouseEnabled = enabled;
alfa.addEventListener(MouseEvent.MOUSE_DOWN, traba);
stage.addEventListener(MouseEvent.MOUSE_UP, stamata);
function traba(e:Event):void
{
alfa.startDrag();
}
function stamata(e:MouseEvent):void
{
if(alfa.hitTestObject(alfa_shadow))
{
alfa.stopDrag();
alfa.x = 300;
alfa.y = 200;
score1 = 1;
trace(score1);
}
else
{
alfa.x = 100;
alfa.y = 400;
alfa.stopDrag();
}
}
var bita_shadow = new shadow_choice[1];
bita_shadow.x = 100;
bita_shadow.y = 200;
addChild(bita_shadow);
var bita = new gramata_choice[1];
bita.x = 200;
bita.y = 400;
addChild(bita);
bita.mouseEnabled = enabled;
bita.addEventListener(MouseEvent.MOUSE_DOWN, traba2);
stage.addEventListener(MouseEvent.MOUSE_UP, stamata2);
function traba2(e:Event):void
{
bita.startDrag();
}
function stamata2(e:MouseEvent):void
{
if(bita.hitTestObject(bita_shadow))
{
bita.x = 100;
bita.y = 200;
bita.stopDrag();
score2 = 1;
trace(score2);
}
else
{
bita.x = 200;
bita.y = 400;
bita.stopDrag();
}
}
var gama_shadow = new shadow_choice[2];
gama_shadow.x = 400;
gama_shadow.y = 200;
addChild(gama_shadow);
var gama = new gramata_choice[2];
gama.x = 300;
gama.y = 400;
addChild(gama);
gama.mouseEnabled = enabled;
gama.addEventListener(MouseEvent.MOUSE_DOWN, traba3);
stage.addEventListener(MouseEvent.MOUSE_UP, stamata3);
function traba3(e:Event):void
{
gama.startDrag();
}
function stamata3(e:MouseEvent):void
{
if(gama.hitTestObject(gama_shadow))
{
gama.stopDrag();
gama.x = 400;
gama.y = 200;
score3 = 1;
trace(score3);
}
else
{
gama.x = 300;
gama.y = 400;
gama.stopDrag();
}
}
var delta_shadow = new shadow_choice[3];
delta_shadow.x = 200;
delta_shadow.y = 200;
addChild(delta_shadow);
var delta = new gramata_choice[3];
delta.x = 400;
delta.y = 400;
addChild(delta);
delta.mouseEnabled = enabled;
delta.addEventListener(MouseEvent.MOUSE_DOWN, traba4);
stage.addEventListener(MouseEvent.MOUSE_UP, stamata4);
function traba4(e:Event):void
{
delta.startDrag();
}
function stamata4(e:MouseEvent):void
{
if(delta.hitTestObject(delta_shadow))
{
delta.stopDrag();
delta.x = 200;
delta.y = 200;
score4 = 1;
trace(score4);
}
else
{
delta.x = 400;
delta.y = 400;
delta.stopDrag();
}
}
}
score_check();
dialekse_auto();
emfanise_auto();
stop();
解决方案
推荐阅读
- python-3.x - 在 XML 文件中查找嵌套标签并在数据框 Python 中转换它
- javascript - 每次我想发出获取请求时使用一个定义获取请求的函数(最佳实践)?
- php - php file_get_contents 没有文件名
- testing - 嗡嗡声游戏
- maven - maven 依赖项中的 @WebFilter 未被 Quarkus 拾取
- c - 静态变量如何区分初始化和赋值
- javascript - 未捕获的 ReferenceError:未在 HTMLFormElement 中定义 signInWithEmailAndPassword。
(index.js:61) (匿名)@index.js:61 - c# - iOS App 将用户凭据正确保存在文件/appmemory 中
- android - 仅允许在 Android Material 文本字段中输入数字
- c++ - 检查从 void* 到已知类型的转换是安全的