2 Replies Latest reply on Jul 26, 2007 8:38 AM by luciewong

    Type mismatch with Array?

    luciewong Level 1
      Hi,
      please can someone help.
      I want to change the value of an Array using "splice", but get always a "Type mismatch" error.

      I have an Array>

      var sub1val_array:Array = Array();
      sub1val_array = myDH.myData_array;

      sub1val_array looks now like > [Yes,Yes,Yes,Yes,Yes]

      With a checkBoxListener I want to change now the data of sub1val_array
      for example on pos 1 to "No" and update myDH.myData_array.

      var myItem:String = "No";

      I use:
      sub1val_array.splice(1,myItem);//<<<<<<this will give me a Type mismatch error<
      myDH.myData_array = sub1val_array;

      Thanks,
      Luciewong

        • 1. Type mismatch with Array?
          Greg Dove Level 4
          well your myItem is in the place of the deletecount which is supposed to be a number and for what you're doing it should - I think - be 1. So you could do it like this:

          sub1val_array.splice(1,1,myItem);//

          But I think all you really want to do is this?
          sub1val_array[1]=myItem;//
          • 2. Re: Type mismatch with Array?
            luciewong Level 1
            Hi GWD,
            thank you for your reply.
            I think the problem is somehow deeper. I think I make a mistake in assigning the checkbox Listener. May I explain?

            Data is provided by this Array>
            var sub3_array:Array = Array();
            sub3_array = [Badmin42,Badmin43,Badmin44,Badmin45];
            var sub3L:Number = (sub3_array.length)-0;


            For each item in the array I want to have an empty MC.
            Each EMC creates its own Text field, displaying the titel of the array item.>

            for(lc:Number = 0;lc<sub3L;lc++){
            this._parent.holderSub_mc.createEmptyMovieClip(["sub3_mc"+lc], (sub3depth)+lc);
            this._parent.holderSub_mc["sub3_mc"+lc].createTextField(["sub3_txt"], 100+lc,sub3X, sub3Y, sub3W, sub3H);
            this._parent.holderSub_mc["sub3_mc"+lc]["sub3_txt"].type = "dynamic";
            this._parent.holderSub_mc["sub3_mc"+lc]["sub3_txt"].text = sub3_array[lc];
            this._parent.holderSub_mc["sub3_mc"+lc]["sub3_txt"].setTextFormat(sformatM);

            //now>beside each text field I want to have a CheckBox.
            Number of checkBoxes and values are provided by the next array>

            var sub3val_array:Array = Array();
            sub3val_array = [Yes,Yes,No,Yes];//_parent.myDH.compT_array;

            this._parent.holderSub_mc.createClassObject(mx.controls.CheckBox, ["sub3_cb"+lc], (sub3depth_cb)+lc, {label:""});

            I want the CheckBoxes at init selected, if the value is "Yes". If "No", then deselected. As I know that both arrays (sub3_array + sub3val_array) have the same number of items, I am still in the first for Loop>

            var sub3Check:String;
            sub3Check = sub3val_array[lc];
            if(sub3Check == "No"){
            this._parent.holderSub_mc["sub3_cb"+lc].selected = false;
            }else if
            (sub3Check == "Yes"){
            this._parent.holderSub_mc["sub3_cb"+lc].selected = true;
            }

            Until here everything works fine.
            But now I need to assign a Listener, if one of the CheckBoxes is deselected,
            it changes immediately the value of my sub1val_array to "No".

            this._parent.holderSub_mc["sub3_cb"+lc].addEventListener("click",sub3Listener);
            sub3Y = (sub3Y)+20;

            }
            //end of for

            var sub3Listener:Object = new Object();
            sub3Listener.click = function(evt:Object){
            sub3val_array.splice(lc,1,sub3Check);
            _parent.myDH.compT_array = sub3val_array;
            }
            //end of click

            I know I do something wrong with my Listener.
            What I want is to update the sub1val_array immediate on click with Yes or No;

            Thank you for your help.

            Luciewong