11 Replies Latest reply on Nov 25, 2008 7:26 PM by Newsgroup_User

    {object object] in ComboBox + ListEvent.CHANGE itemRenderer always null

    blipstation
      I am a Flex newbie and I am having several problems with a custom ComboBox.

      The textInput value (user choice) always comes out [object Object]. And when I listen for the ListEvent.CHANGE event the itemRenderer is always null although it is successfully being used. The itemRenderer returns its height so I can adapt the textInput or user choice to also expand and show more than one line (not sure this is the right approach as textInput.textHeight is read-only).

      The code is:
        • 1. Re: {object object] in ComboBox + ListEvent.CHANGE itemRenderer always null
          Level 7

          "blipstation" <webforumsuser@macromedia.com> wrote in message
          news:ggbv73$o93$1@forums.macromedia.com...
          >I am a Flex newbie and I am having several problems with a custom ComboBox.
          >
          > The textInput value (user choice) always comes out [object Object].

          Have you tried specifying a labelField or labelFunction?


          • 2. Re: {object object] in ComboBox + ListEvent.CHANGE itemRenderer always null
            blipstation Level 1
            Thank you very much , Amy. I set the labelField thus in the constructor:

            labelField="line"

            and now it works. Presumably that is the only place it can go as I set the dataProvider before I do the addChild() and thus allow it to go throughthe pre-initialisation and intialization stages of its lifecycle.

            Any ideas as to why the ListEvent has no itemRenderer available to it?

            Or indeed how to get rid of :

            warning: unable to bind to property 'line' on class 'Object' (class is not an IEventDispatcher) ?

            What I am trying to do is set the textInput or chosen field to wrap along with the line choice if that wraps.
            • 3. Re: {object object] in ComboBox + ListEvent.CHANGE itemRenderer always null
              blipstation Level 1
              I got rid of that pesky message:

              warning: unable to bind to property 'line' on class 'Object' (class is not an IEventDispatcher)

              The bound data in the itemRenderer must point to a strongly typed object. The ArrayCollection was one of plain vanilla objects. The same goes for XML which does not have typing information ie it is weakly typed. Tried it with the following as the dataProvider which has Strings not objects:

              <mx:ArrayCollection id="typed_dp">
              <mx:Array>
              <mx:String>Example of line one</mx:String>
              <mx:String>Example of line two</mx:String>
              <mx:String>Example of line three</mx:String>
              <mx:String>Example of line four</mx:String>
              <mx:String>Example of line five</mx:String>
              <mx:String>Example of line six</mx:String>
              <mx:String>Example of a very long one that should effortlessly (unlike working with the Flex API) wrap</mx:String>
              </mx:Array>
              </mx:ArrayCollection>

              This was bound using the following:

              <mx:Text id="line" text="{data}" width="90%" selectable="false"/>

              And then I had no need for the labelField setting in the constructor.

              The final problem is the absence of the itemRenderer in the ListEvent. It is null although there is the ComboBox.itemRenderer as an component.LineItem instance I can see in the debugger.

              Anyone any ideas on this one?
              • 4. Re: {object object] in ComboBox + ListEvent.CHANGE itemRenderer always null
                chris.huston.t10 Level 3
                What if you used ObjectProxies in your ArrayCollection instead of Objects?

                import mx.utils.ObjectProxy;
                private var dp:ArrayCollection = new ArrayCollection([
                new ObjectProxy({line:"Example line one in the combo."}),
                new ObjectProxy({line:"Example line two in the combo."}),
                new ObjectProxy({line:"Example line three in the combo."})
                ]);

                Chris
                • 5. Re: {object object] in ComboBox + ListEvent.CHANGE itemRenderer always null
                  blipstation Level 1
                  Yes, Masamune/Chris that appears to work as well. Thanks for the tip.
                  Now to get that combo choice to wrap. Probably need to iterate through the line options to get the full height of the dropdown so I don't get a scroll on it...



                  • 6. Re: {object object] in ComboBox + ListEvent.CHANGE itemRenderer always null
                    Level 7

                    "blipstation" <webforumsuser@macromedia.com> wrote in message
                    news:ggcjue$iot$1@forums.macromedia.com...
                    > Thank you very much , Amy. I set the labelField thus in the constructor:
                    >
                    > labelField="line"
                    >
                    > and now it works. Presumably that is the only place it can go as I set the
                    > dataProvider before I do the addChild() and thus allow it to go throughthe
                    > pre-initialisation and intialization stages of its lifecycle.

                    You can just set it where you instantiate your custom Combobox, just like
                    you'd do with a normal Combobox.

                    var ASCombo:FreeAlt=new FreeAlt();
                    ASCombo.dataProvider=dp;
                    ASCombo.labelField='line';
                    vertBox.addChild(ASCombo);


                    > Any ideas as to why the ListEvent has no itemRenderer available to it?

                    I suspect it does have an itemRenderer, but probably your statement
                    e.itemRenderer as components.LineItem
                    makes some poor assumptions as to what it is. Remember "as" will return
                    null if e.itemRenderer exists, but is not a components.LineItem. I'd put a
                    break point there and look at what the variables window can tell you.

                    HTH;

                    Amy


                    • 7. Re: {object object] in ComboBox + ListEvent.CHANGE itemRenderer always null
                      blipstation Level 1
                      Amy,

                      Thanks for your input. I did put a break in there and debugged it. The itemRenderer is there under 'this' (ie FreeAlt - the custom ComboBox in question) as an isntance of mx.core.ClassFactory with a generator value showing 'componets.LineItem' but
                      under e (for the ListEvent variable) in the variables window, it is defintitely null, which is most odd.

                      Incidentally, you cannot put a multiline choice in a ComboBox as this is handled by an internal TextInput control which is intrinsically for single lines only. So it looks like I will have to implement my own Combo afresh, which is somewhat daunting. I am trying, by the way, to port from AS3 my scenario generator at blipstation.com into Flex.

                      best

                      ian
                      • 8. Re: {object object] in ComboBox + ListEvent.CHANGE itemRenderer always null
                        article man Level 1
                        this helped me dubug too,thanks and now it seems to work well,thanks guys.
                        regards,
                        • 9. Re: {object object] in ComboBox + ListEvent.CHANGE itemRenderer always null
                          Level 7

                          "blipstation" <webforumsuser@macromedia.com> wrote in message
                          news:ggegg6$21g$1@forums.macromedia.com...
                          > Amy,
                          >
                          > Thanks for your input. I did put a break in there and debugged it. The
                          > itemRenderer is there under 'this' (ie FreeAlt - the custom ComboBox in
                          > question) as an isntance of mx.core.ClassFactory with a generator value
                          > showing
                          > 'componets.LineItem' but
                          > under e (for the ListEvent variable) in the variables window, it is
                          > defintitely null, which is most odd.

                          In that type of circumstance, I often find that stepping through the
                          Framework code is the only way to figure out what's going on. But you might
                          find this helpful:
                          http://flexdiary.blogspot.com/2008/07/debugging-itemrenderers.html

                          > Incidentally, you cannot put a multiline choice in a ComboBox as this is
                          > handled by an internal TextInput control which is intrinsically for single
                          > lines only. So it looks like I will have to implement my own Combo afresh,
                          > which is somewhat daunting. I am trying, by the way, to port from AS3 my
                          > scenario generator at blipstation.com into Flex.

                          You can probably override createChildren to delete theirs and replace it
                          with yours, depending on how specific they were with the variable type they
                          used to reference it.

                          HTH;

                          Amy


                          • 10. Re: {object object] in ComboBox + ListEvent.CHANGE itemRenderer always null
                            blipstation Level 1
                            Amy,

                            I had a look at your blog and it is kinda comforting to know that others too have floundered getting to grips with itemRenderers.

                            As regards stepping through the Flex framework code, I have done that with the textInput property of the ComboBox and it's just everywhere in the ComboBase source.The textInput is in createChildren(), styleChanged(styleProp:String) - where no less than 5 eventListener methods are attached, updateDisplayList, setFocus, and isOurFocus(target:DisplayObject). I think there comes a point where overriding is just too troublesome so it might be best to start over and learn the lessons from the Flex source. eg the dropdown is added via a PopUpManager.addPopUp() call.

                            The itemRenderer remains a mystery I am afraid despite stepping through and into the code carefully as it seems to be there in both 'this' and in the dropdown it has.
                            • 11. Re: {object object] in ComboBox + ListEvent.CHANGE itemRenderer always null
                              Level 7

                              "blipstation" <webforumsuser@macromedia.com> wrote in message
                              news:gghuhu$gn0$1@forums.macromedia.com...
                              > Amy,
                              >
                              > I had a look at your blog and it is kinda comforting to know that others
                              > too
                              > have floundered getting to grips with itemRenderers.
                              >
                              > As regards stepping through the Flex framework code, I have done that with
                              > the
                              > textInput property of the ComboBox and it's just everywhere in the
                              > ComboBase
                              > source.The textInput is in createChildren(),
                              > styleChanged(styleProp:String) -
                              > where no less than 5 eventListener methods are attached,
                              > updateDisplayList,
                              > setFocus, and isOurFocus(target:DisplayObject). I think there comes a
                              > point
                              > where overriding is just too troublesome so it might be best to start over
                              > and
                              > learn the lessons from the Flex source. eg the dropdown is added via a
                              > PopUpManager.addPopUp() call.

                              You missed my point. Depending on what the _type_ they used for the
                              variable they refer to the textinput, you can simply delete it right after
                              it's created and replace it with something that's more to your
                              liking...which will then be acted on by all those other methods. If the
                              type actually is TextInput, you're SOL, but if it starts with I, for
                              example, that's an interface and there might be another object that
                              implements the same interface that you could use to replace it.

                              Hope this clarifies;

                              Amy