3 Replies Latest reply on May 29, 2006 10:49 AM by poonamsheth

    Changing 1 item in Array changes all items Flex 2 beta 2

    Chester_Copperpot
      I change one item in my array and it ends up changing all the items in that array. I originally thought that the array was just string the memory location, which it may, so I added a blank constructor to my class which should grab a new chunck of memory but it still is not working correct. Any ideas would be great.
        • 1. Re: Changing 1 item in Array changes all items Flex 2 beta 2
          Chester_Copperpot Level 1
          Pretty sure this fixed it. In my constructor of my class I cast the objects to get a new chunk of memory. See attached code.

          Chris
          • 2. Re: Changing 1 item in Array changes all items Flex 2 beta 2
            GordonSmith Level 4
            Normally a constructor with optional arguments would be coded like this:

            public function DateEvent(name:String = "", id:String = "")
            {
            _name = name;
            _id = id;
            }

            I'm guessing your original problem was because all your Array elements were actually referencing the same DateEvent instance. You need each element to reference a different DateEvent instance. How are you populating the Array?
            • 3. Re: Changing 1 item in Array changes all items Flex 2 beta 2
              poonamsheth Level 1
              FROM UR Doubt WHAT I CAN understand is .,
              u want to fot the date right?

              The example uses the change event l to display the selected date in several different formats.

              main.mxml
              ---------------------
              <?xml version="1.0"?>
              <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml">

              <mx:Script>
              <![CDATA[

              import mx.events.CalendarLayoutChangeEvent;

              private function useDate( eventObj:CalendarLayoutChangeEvent):void {

              // Make sure selectedDate is not null.
              if (eventObj.currentTarget.selectedDate == null) {
              return
              }

              //Access the Date object from the event object.
              day.text=eventObj.currentTarget.selectedDate.getDay();
              date.text=eventObj.currentTarget.selectedDate.getDate();
              month.text=eventObj.currentTarget.selectedDate.getMonth();
              year.text=eventObj.currentTarget.selectedDate.getFullYear();
              wholeDate.text=eventObj.currentTarget.selectedDate.getFullYear() +
              "/" + (eventObj.currentTarget.selectedDate.getMonth()+1) +
              "/" + eventObj.currentTarget.selectedDate.getDate();
              }
              ]]>
              </mx:Script>

              <mx ateChooser id="date1" change="useDate(event)"/>

              <mx:Form>
              <mx:FormItem label="Day">
              <mx:TextInput id="day" width="100"/>
              </mx:FormItem>
              <mx:FormItem label="Day of month">
              <mx:TextInput id="date" width="100"/>
              </mx:FormItem>
              <mx:FormItem label="Month">
              <mx:TextInput id="month" width="100"/>
              </mx:FormItem>
              <mx:FormItem label="Year">
              <mx:TextInput id="year" width="100"/>
              </mx:FormItem>
              <mx:FormItem label="Date">
              <mx:TextInput id="wholeDate" width="300"/>
              </mx:FormItem>
              </mx:Form>
              </mx:Application>

              well ,,, the first line of the event listener determines if the selectedDate property is null. This check is necessary because selecting the currently selected date deselects it, sets the selectedDate property to null, then dispatches the change event.