4 Replies Latest reply on Nov 5, 2008 5:40 AM by alice_data

    Combine Two Arrays Using Actionscript in Flex Applications Errors

    alice_data Level 1
      Hi,

      I have a set of Actionscript code below that I would like to execute based on some query and have it display what are all the selections I have displayed from the two repeater checkbox elements.

      This does not seem to work every time when I get to checkBox_change2 function. I am always seeing error messages popping up telling me that I have null references at this particular line: var selArr3:Array= selArr2.concat(selArr);

      Could anyone tell me how I can have checkBox_change2() remember the selections I have made in checkBox_change()? I tried using public var for the [Bindable] elements above, but I still get the same error.

      Thanks in advance.

      Alice
        • 1. Re: Combine Two Arrays Using Actionscript in Flex Applications Errors
          chris.huston.t10 Level 3
          It looks like you are declaring both local and global variables with the same names. In this case, the local declarations within the functions are overriding the global variables. Instead of using var selArr;Array = [] in your checkBox_change function, remove the 'var' keyword and just use:
          selArr = [];

          I think you can also delete the global selArr2 and selArr3 variables since they only appear within the checkbox_change2 function and don't need global scope. If this is not the case, then you will need to also remove the 'var' keyword within the function as above.

          I think this should help with your error messages, but post back if you still encounter errors.

          Vygo
          • 2. Re: Combine Two Arrays Using Actionscript in Flex Applications Errors
            alice_data Level 1
            Hi,

            Thanks for the reply, but the answer here now gives me errors. To make sure that I have understood what you were saying here, I have attached the revised version of the code below.

            I see the errors on the page right away after I made these changes, and the most obvious one is here: Severity and Description Path Resource Location Creation Time Id
            1067: Implicit coercion of a value of type Array to an unrelated type Class and 1188: Illegal assignment to class Array. at the line where selArr:Array= [] is declared.

            Have I not added something I should be adding here?

            Thanks for your help.

            Alice
            • 3. Re: Combine Two Arrays Using Actionscript in Flex Applications Errors
              m_hartnett Level 3
              You are still not declaring your selArr correctly.
              The declaration [Bindable]private var selArr:Array; is an instance variable. It is defined outside of any function and is visible to anything in your object.

              In your function
              private function checkBox_change(evt:Event,x:Array):void {
              selArr:Array = [];

              selArr is defined as a local variable visible only within the function checkBox_change. Since the names are the same you are overriding the instance variable. (In reality this should not have compiled properly ... your first try of var selArr:Array = [] was the valid syntax for overriding the variable)

              To fix it you just need to change
              selArr:Array = [] into selArr = [];


              • 4. Combine Two Arrays Using Actionscript in Flex Applications Errors
                alice_data Level 1
                Hi,

                I did what you mentioned here, and selArr did the trick. :)

                Thanks very much for your help.

                Alice