2 Replies Latest reply on Jun 10, 2007 10:09 PM by fuzzarooO

    Combobox is null when referencing the id in script?

    fuzzarooO
      I think i've spent way too much time on this one for no real justification to why it is happening.

      my combobox, "PERIODINPUT" is always null. Any reason why?

      quote:

      <mx:Canvas xmlns:mx=" http://www.adobe.com/2006/mxml" width="318" height="228">
      <mx:Metadata>
      [ Event(name="dateChanged", type="events.dateChangedEvent") ]
      </mx:Metadata>

      <mx:Script>
      <![CDATA[
      import code.datePass;
      import events.dateChangedEvent;
      import mx.controls.ComboBox;


      public var myDate:datePass = new datePass();
      [Bindable] public var completeDate:String = myDate.getValidDate();
      [Bindable] public var planningYears:String = "3";
      [Bindable] public var timePeriodArray:Array = [{label:"Annnual", data:"1"}, {label:"Semi-Annual", data:"2"},
      {label:"Quarterly", data:"3"}, {label:"Monthly", data:"4"} ];

      private function onDateChanged():void {
      myDate.setValidDate(startDateInput.text);
      completeDate = myDate.getValidDate();
      var myEventObj:dateChangedEvent = new dateChangedEvent("dateChanged", myDate, int(planningYears), int(periodInput.selectedItem.data));
      dispatchEvent(myEventObj);
      }
      ]]>
      </mx:Script>

      <mx:Panel x="10" y="10" width="298" height="200" layout="absolute">
      <mx:HBox width="100%" y="42">
      <mx:Label text="Period:" id="periodLabel" width="170"/>
      <mx:ComboBox width="100" id="periodInput" dataProvider = "{timePeriodArray}"/>
      </mx:HBox>
      </mx:Panel>
        • 1. Re: Combobox is null when referencing the id in script?
          dimival Level 1
          You have an array of objects and you are no telling the combo which property it should show. You need to do the following:

          <mx:ComboBox width="100" id="periodInput" dataProvider = "{timePeriodArray}" labelField="label"/>

          or

          <mx:ComboBox width="100" id="periodInput" dataProvider = "{timePeriodArray}" labelField="data"/>

          Since you are using an array of objects you need to tell the ComboBox which property is to be displayed.
          • 2. Re: Combobox is null when referencing the id in script?
            fuzzarooO Level 1
            thank you for your response, however, that didn't do the trick.

            I should've mentioned that I have a validator that validates the current date as soon as the application launches?? I've bolded where the null error is happening.

            I would really appreciate anyone's help.

            quote:


            <mx:Canvas xmlns:mx=" http://www.adobe.com/2006/mxml" width="318" height="228">
            <mx:Metadata>
            [ Event(name="dateChanged", type="events.dateChangedEvent") ]
            </mx:Metadata>

            <mx:Script>
            <![CDATA[
            import code.datePass;
            import events.dateChangedEvent;
            import mx.controls.ComboBox;

            public var myDate:datePass = new datePass();
            [Bindable] public var completeDate:String = myDate.getValidDate();
            [Bindable] public var planningYears:String = "3";
            [Bindable] public var timePeriodArray:Array = [{label:"Annnual", data:"1"}, {label:"Semi-Annual", data:"2"},
            {label:"Quarterly", data:"3"}, {label:"Monthly", data:"4"} ];

            private function onDateChanged():void {
            myDate.setValidDate(startDateInput.text);
            completeDate = myDate.getValidDate();
            var myEventObj:dateChangedEvent = new dateChangedEvent("dateChanged", myDate, int(planningYears),
            int(periodInput.selectedItem.data));

            dispatchEvent(myEventObj);
            }
            ]]>
            </mx:Script>

            <mx:DateValidator id="stringDateValidator"
            source="{startDateInput}"
            property="text"
            inputFormat="mm/dd/yy"
            allowedFormatChars="*#~/"
            valid = "{onDateChanged();}"
            />

            <mx:Panel x="10" y="10" width="298" height="200" layout="absolute">
            <mx:HBox width="100%" y="42">
            <mx:TextInput id="startDateInput" text="{completeDate}" enabled="true" width="100" fontSize="9"/>
            <mx:Label text="Period:" id="periodLabel" width="170"/>
            <mx:ComboBox width="100" id="periodInput" dataProvider = "{timePeriodArray}"/>
            </mx:HBox>
            </mx:Panel>