Rachel Mack
Rachel Mack

Reputation: 1

Actionscript 3.0, TypeError: Error #1006: Value is not a Function

So I have an assignment for school due next week, but I'm getting an error. I asked my T/A about it, but she wasn't sure either. I've looked around on Google and this site for a while, but couldn't find anything to help me. The exact output/error is this:

1:false
usedfunction Function() {}
Maybe
TypeError: Error #1006: value is not a function.
    at Assign6/usedAnswer()
    at Assign6/ballEndDrag()

The problem seems to be within the if statement

if(usedAnswer(msg)==false)

The program is not even tracing a value for

trace(usedAnswer(msg));

Any help would be appreciated. Thanks so much!!

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;
        }
    }
}

Upvotes: 0

Views: 637

Answers (3)

Fergoso
Fergoso

Reputation: 1582

There's are errors in your for-loop and while loop.

replace this

for (i==0; i<usedList.length(); i++)

with

for (i=0; i<usedList.length; i++)

Upvotes: 0

Barış Uşaklı
Barış Uşaklı

Reputation: 13532

var i = 0;
for (i==0; i<usedList.length(); i++)

should be

for (var i=0; i<usedList.length; i++)

No?

Alternatively you can replace the for loop with indexOf.

function usedAnswer( answer: String ): Boolean
{
    return usedList.indexOf(answer) !== -1;
}

Upvotes: 2

Brian
Brian

Reputation: 3914

Expanding on @Barış Uşaklı's answer:

Your usedAnswer() function references usedList which is an Array type. In Actionscript 3, Arrays have a length property that you can reference rather than a length() function that you can call. You can read more in the Array as3docs.

Your practical fix is simply:

var i = 0;
for (i==0; i<usedList.length; i++)

Upvotes: 0

Related Questions