我遇到这个问题,只有最后一个函数有效,所有以前的函数都被flash忽略。由于所有功能都以相同的方式编写,我找不到问题。
这段代码只是一个按下按钮来改变事物的场景类型,我按下某个键然后它会改变,但在这种情况下,只有我选择的最后一个键有效。
任何提示?
var gomas:Object = new Object();
var chocolate:Object = new Object();
var tarte:Object = new Object();
var peixe:Object = new Object();
var lama:Object = new Object();
gomas.onKeyDown = function()
{
if (Key.getCode() == "51","54","222","87","73","71","86");
{
loadMovieNum("01 Gomas.swf",0);
}
};
Key.addListener(gomas);
chocolate.onKeyDown = function()
{
if (Key.getCode() == "49","56","69","71","76","67","78");
{
loadMovieNum("02 Chocolate.swf",0);
}
};
Key.addListener(chocolate);
tarte.onKeyDown = function()
{
if (Key.getCode() == "52","48","82","75","66","85");
{
loadMovieNum("03 Tarte.swf",0);
}
};
Key.addListener(tarte);
peixe.onKeyDown = function()
{
if (Key.getCode() == "50","55","84","79","83","72","77");
{
loadMovieNum("04 Peixe.swf",0);
}
};
Key.addListener(peixe);
lama.onKeyDown = function()
{
if (Key.getCode() == "53","57","81","89","80","68","74");
{
loadMovieNum("05 Lama.swf",0);
}
};
Key.addListener(lama);
答案 0 :(得分:1)
看起来问题出在你的if语句中。运行代码时,按下某个键时会按顺序调用所有方法。由于它们都将swf加载到同一级别,因此它们会覆盖,从而导致最后一个被加载。
我认为你不能用这样的逗号,它似乎被视为一种不同的条件。这总是勾勒出“是”(我的猜测是由于“54”是“真实的”):
var temp:String = "1";
if(temp == "0", "54"){
trace("yes");
}
我建议使用switch语句,因为您只想检查与单个值匹配的键代码。