操作脚本3-为参考变量分配索引或比较两个索引号

0 arrays indexing actionscript-3

我正在Action Script 3中编写一个程序,使用两个数组为匹配的月份指定一个名称.我有它所以它已经检查以查看该名称是否与数组中的一个匹配,同样与月数组相匹配,但我在最后的if语句中遇到问题,询问两者的索引号是否匹配.

var Name:Array = new Array("John", "Mike", "Ben", "Thomas", "Chuck", "Charlie", "Peter", "Robert", "Dick", "Tracey", "Brienne", "Tywin");
var Month:Array = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");

var Wrong:String = new String("Sorry, Wrong Input");

stop();

startButton.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler);

function fl_MouseClickHandler(event:MouseEvent):void
{
// Start your custom code
var xName = NameInput.text;
var xMonth = MonthInput.text;
if (Name.indexOf(xName) != -1)
{
NameMatchOutput.text = xName;
}
else
{
NameMatchOutput.text = Wrong;
}

if (Month.indexOf(xMonth) != -1)
{
MonthMatchOutput.text = xMonth;
}
else
{
MonthMatchOutput.text = Wrong;
}
if (Name.indexOf(xName) = (Month.indexOf(xMonth)))
{
NameMonthMatchOutput.text = "They Match";
}
else
{
NameMonthMatchOutput.text = "They Don't Match.";
}

// This example code displays the words "Mouse clicked" in the Output panel.
trace("Mouse clicked");
// End your custom code
}   



trace(Name);
trace(Month);
Run Code Online (Sandbox Code Playgroud)

sta*_*com 5

使用

if (Name.indexOf(xName) == (Month.indexOf(xMonth)))
Run Code Online (Sandbox Code Playgroud)

代替

if (Name.indexOf(xName) = (Month.indexOf(xMonth)))
Run Code Online (Sandbox Code Playgroud)