Skip to main content
June 2, 2012
Answered

Error #1006: textBoxSet is not a function

  • June 2, 2012
  • 1 reply
  • 1754 views

Here is a little background about this error and myself:

I have been trying to fix this for some 2 hours, not qutie sure how to or what to fix. I am a Java programmer and the tutor in my school and switched to this language because it was "easier" to have GUI, animation, and interaction. As such, I am still stumbling around actionscript a bit.

As or right now, this code is intended to 1) set up a red rectangle movieClip, 2) move it 200 pixels and 3) have it call a function "textBoxSet" from the VeggieDisplay class which is imported and supposedly working.

1 and 2 work just fine, as they are relatively easy steps. However, when I try running displayItem.textBoxSet(); I recieve:

TypeError: Error #1006: textBoxSet is not a function.

  at ProduceProject_fla::MainTimeline/frame1()

I am not quite sure why this happens. I have everything set up and it should work. The methods arent nested etc. etc. and such.

For now, this is all I have to ask. I am going to worry about the other thing that isn't working later (class item is undefined in timeline when shouldnt be etc.)

Code in the Timeline at Frame 1:

import packages.VegetableDisplay;

var displayItem:VegetableDisplay = new VegetableDisplay();

trace(displayItem);

displayItem.x = 200;

this.addChild(displayItem);

displayItem.textBoxSet();

Code for VegetableDisplay:

package  packages{

          import flash.display.MovieClip;

          import packages.Vegetable;

          import flash.text.TextField;

          public class VegetableDisplay extends MovieClip {

                    public var veggieItem:Vegetable;

                    //two text boxes present in the movieclip

                    var nameText:TextField = new TextField();

                    var typeText:TextField = new TextField();

                    //"constructor". Not constructing much

                    public function VegetableDisplay() {

                              // constructor code

                              trace("9");

                              veggieItem = new Vegetable();

                              trace("veggieItem " + veggieItem.getName());

                    }

                    //set text boxes present in the movieClip

                    private function textBoxSet():void{

                              trace("in");

                              nameText.text = veggieItem.getName();

                              typeText.text = veggieItem.getType();

                    }

          }

}

Vegetable Class:

package packages {

          public class Vegetable {

                    /*I actually do have an issue with this class as well. When values are called form it, they come as "undefined" rather than what they should be.

                    Why and how could I fix it*/

                    private var myName:String = new String();                                        //name of item

                    private var typeNum:Number = 0;                                                                      //0: vegetable 1: fruit

                    private var myType:String = new String();                                        //string associated

                    private var classNum:Number = 0;                                                            //stone fruits and such

                    private var itemClass:String = new String();                                        //string associated

                    private var growingSeason:Array;                                                            //months

                    private var growingArea:Array;                                                                      //areas

                    public function Vegetable() {

                              // constructor code

                              myName = "tomato";                                                                                          //temporary until begin importing rather than static.

                              myType = "fruit";

                    }

                    //Get methods

                    public function getName():String{

                              return myName;

                    }

                    public function getTypeNum():Number{

                              return typeNum;

                    }

                    public function getType():String{

                              return myType;

                    }

                    public function getClassNum():Number{

                              return classNum;

                    }

                    public function getItemClass():String{

                              return itemClass;

                    }

                    public function getGrowingSeason():Array{

                              return growingSeason;

                    }

                    public function getGrowingArea():Array{

                              return growingArea;

                    }

                    //Set methods

                    public function setName(mName){

                              myName = mName;

                    }

                    public function setTypeNum(tyNum){

                              typeNum = tyNum;

                    }

                    public function setMyType(mType){

                              myType = mType;

                    }

                    public function setClassNum(claNum){

                              classNum = claNum;

                    }

                    public function setItemClass(itClass){

                              itemClass = itClass;

                    }

                    public function setGrowingSeason(growSeason){

                              growingSeason = growSeason;

                    }

                    public function setGrowingArea(growArea){

                              growingArea = growArea;

                    }

          }

}

Any and all help would be greatly appreciated. Thank you.

Added Vegetable class if anyone bothers to build the class and test. The make-up of the textbox is just a rectangle with two text boxes "nameText" and "typeText" so far, set to Dynamic text and such.

Also realized I never finished with the name of the question, so I made it less ambiguous.

This topic has been closed for replies.
Correct answer Ned Murphy

You might want to start with a fresh set of files.  If I test using your latest rendition of the VegetableDisplay class along with the other coding elements from your first posting I get no errors and the following outputs...

9

veggieItem tomato

[object VegetableDisplay]

in

1 reply

Ned Murphy
Legend
June 3, 2012

I don't think a private function can be accessed outside of the class.

June 3, 2012

True. It was private. However, upon fixing this and switching the method to public, still the same message. I updated the code above although it is not a huge change.

*EDIT* It would appear that I cannot change my old post as too much time has passed or something.

new Vegetable display:

package  packages{

 

          import flash.display.MovieClip;

          import packages.Vegetable;

          import flash.text.TextField;

 

          public class VegetableDisplay extends MovieClip {

 

                    public var veggieItem:Vegetable;

 

                    //two text boxes present in the movieclip

                    var nameText:TextField = new TextField();

                    var typeText:TextField = new TextField();

 

                    //"constructor". Not constructing much

                    public function VegetableDisplay() {

                              // constructor code

                              trace("9");

                              veggieItem = new Vegetable();

                              trace("veggieItem " + veggieItem.getName());

                    }

 

                    //set text boxes present in the movieClip

                    public function textBoxSet():void{

                              trace("in");

                              nameText.text = veggieItem.getName();

                              typeText.text = veggieItem.getType();

                    }

          }

}

On a separate note, when I try tracing the object veggieItem from the displayItem in the timeline, it returns undefined. This should not happen, as it knows it is a vegetable and such. Am I just running into a wall or something?

Ned Murphy
Ned MurphyCorrect answer
Legend
June 3, 2012

You might want to start with a fresh set of files.  If I test using your latest rendition of the VegetableDisplay class along with the other coding elements from your first posting I get no errors and the following outputs...

9

veggieItem tomato

[object VegetableDisplay]

in