所以我下周要上学,但我收到了错误。我问了我的T / A,但她也不确定。我已经浏览了谷歌和这个网站一段时间,但找不到任何帮助我的东西。确切的输出/错误是这样的:
1:false
usedfunction Function() {}
Maybe
TypeError: Error #1006: value is not a function.
at Assign6/usedAnswer()
at Assign6/ballEndDrag()
问题似乎在if语句
中if(usedAnswer(msg)==false)
该程序甚至没有追踪
的值trace(usedAnswer(msg));
任何帮助将不胜感激。非常感谢!!
package
{
import flash.display.*;
import flash.events.*;
public class Assign6 extends MovieClip
{
var ballDisplay:Array = new Array("Yes","No","It is certain!","Ask again","Try again","Better not","Most likely","Maybe","Reply is No","Doubtful","Outlook good");
var usedList: Array = new Array();
var magicInt:Number;
public function Assign6()
{
magicBall.addEventListener( MouseEvent.MOUSE_DOWN, ballStartDrag );
magicBall.addEventListener( MouseEvent.MOUSE_UP, ballEndDrag );
}
// When the user presses the mouse down on magicBall, this function is called
function ballStartDrag( evt: MouseEvent )
{
magicBall.startDrag( );
magicBall.magicText.text = " ";
magicBall.eightDisplay.text = "8";
}
// When the user lets the mouse up on magicBall, this function is called
function ballEndDrag( evt: MouseEvent )
{
magicBall.stopDrag( );
magicBall.eightDisplay.text = " ";
var checkVal = false;
while(checkVal==false){
trace("1:" + checkVal);
trace("used" + usedAnswer);
var msg:String = randomAnswer();
trace(msg);
trace(usedAnswer(msg));
if(usedAnswer(msg)==false){
usedList.push(ballDisplay[magicInt]);
checkVal = true;
trace("2" + checkVal);
}
}
}
//Display random answer in magicText
function randomAnswer( ):String
{
magicInt = Math.round(Math.random() * 11);
magicBall.magicText.text = ballDisplay[magicInt];
return ballDisplay[magicInt];
}
// Check whether answer has already been used
// Returns true if answer is in usedList and false if not
function usedAnswer( answer: String ): Boolean
{
var i = 0;
for (i==0; i<usedList.length(); i++)
{
if (answer == usedList[i])
{
return true;
}
}
return false;
}
}
}
答案 0 :(得分:2)
var i = 0;
for (i==0; i<usedList.length(); i++)
应该是
for (var i=0; i<usedList.length; i++)
没有
或者,您可以使用indexOf替换for循环。
function usedAnswer( answer: String ): Boolean
{
return usedList.indexOf(answer) !== -1;
}
答案 1 :(得分:0)
for-loop和while循环中存在错误。
替换此
for (i==0; i<usedList.length(); i++)
与
for (i=0; i<usedList.length; i++)
答案 2 :(得分:0)
扩展@BarışUşaklı的回答:
您的usedAnswer()
函数引用usedList
这是一种数组类型。在Actionscript 3中,数组具有length
属性,您可以引用它而不是可以调用的length()
函数。您可以在Array as3docs中阅读更多内容。
您的实际解决方法很简单:
var i = 0;
for (i==0; i<usedList.length; i++)