我有一个问题,无论我放的任何文字甚至空白我仍然进入第170帧,因为你看到我把171帧放在那里,如果我输入“因此”它进入171,似乎它的工作正常它即使我把错误的文字放到第170帧,我也找不到问题,我也不知道我是否应该做一个其他声明,所以如果这个词不在列表中它会转到其他帧,谢谢你的伙伴
var i:int = 0;
var names:Array = new Array("therefore","disciples","nations","baptizing","father","son","holy spirit");
var frames:Array = new Array("171","170","170","170","170","170","170","170");
button_140.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler_4);
function fl_MouseClickHandler_4(event:MouseEvent):void
{
var searchtext:String = searchtext.text.toLowerCase();
findInArray(searchtext);
gotoAndStop(frames[i]);
}
function findInArray(str:String):int
{
for(i=0; i < names.length; i++)
{
if(names[i] == str)
{
return i;
}
}
return 0;
}
答案 0 :(得分:1)
为什么你总是去第170帧:
让我们看看您的功能Intent intent = new Intent(First.this, Second.class);intent.putExtra("userData",registeredUsersData);startActivity(intent);
:
fl_MouseClickHandler_4
修复代码:
函数findInArray(searchtext);//string won't be found so "i" would be 7 (the last index in array)
gotoAndStop(frames[i]);//so it goes to frame 170
:
fl_MouseClickHandler_4
函数function fl_MouseClickHandler_4(event:MouseEvent):void
{
var searchtext:String = searchtext.text.toLowerCase();
var index:int=findInArray(searchtext);
if(index==-1){
//do something when frame not found
}
else{
gotoAndStop(frames[index]);
}
:
findInArray
我希望这会有所帮助......
修改强>
您无需创建函数即可在数组中查找值。您可以使用function findInArray(str:String):int
{
for(i=0; i < names.length; i++)
{
if(names[i] == str)
{
return i;//return the found index
}
}
return -1;//return -1 if nothing found
}
类内置方法Array
来查找数组中项目的索引:有关详细信息,请参阅AS3 manual。
indexOf()
返回theValue的索引。如果theValue不在theArray中,则返回-1。
测试以下示例:
theArray.indexOf(theValue);