![]() |
![]() |
||||||
|
|||||||
| Tags: |
![]() |
|
|||
|
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: <?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:comp="components.*" xmlns:components="src.components.*" creationComplete="makeASFreeAlt(event)"> <mx:Style> FreeAlt{ cornerRadius: 0; fontWeight: normal; rowCount:10; } VBox{ verticalGap:0; } </mx:Style> <mx:Script> <![CDATA[ import mx.collections.ArrayCollection; import components.FreeAlt; [Bindable] private var dp:ArrayCollection = new ArrayCollection([{line:"Example line one in the combo."}, {line:"Example line two in the combo."}, {line:"Example line three in the combo."}, {line:"Example line four in the combo"}, {line:"Example line five in the combo"}, {line:"Example line six in the combo"}, {line:"Example line seven in the combo and a very long one for the last option to see if it wraps successfully or not"} private function makeASFreeAlt(e:Event):void{ var ASCombo:FreeAlt=new FreeAlt(); ASCombo.dataProvider=dp; vertBox.addChild(ASCombo); } ]]> </mx:Script> <mx:VBox id="vertBox"> </mx:VBox> </mx:Application> ///////////////////////////////////////////////Fre eAlt code///////////////////////////////////////////////////////// package components { import mx.controls.ComboBox; import mx.controls.listClasses.ListBase; import mx.core.ClassFactory; import mx.events.DropdownEvent; import mx.events.FlexEvent; import mx.events.ListEvent; public class FreeAlt extends ComboBox { private var _dropdownHeight:uint; private var _dropdownReset:Boolean=false; public function FreeAlt() { super(); addEventListener(FlexEvent.CREATION_COMPLETE,setup ); addEventListener(DropdownEvent.OPEN, wrapLines); addEventListener(ListEvent.CHANGE,adaptChoice); } private function setup(e:FlexEvent):void{ rowCount=dataProvider.length; explicitWidth=300; itemRenderer=new ClassFactory(components.LineItem); } private function wrapLines(e ropdownEvent):void{e.currentTarget.dropdown.variableRowHeight=true; _dropdownReset=true; } private function adaptChoice(e:ListEvent):void{ //throws error as e.itemRenderer is always null trace("itemRenderer.height "+ (e.itemRenderer as components.LineItem).textHeight); } }//class } ////////////////////////////////// Custom itemRenderer Lineitem //////////////////////////////////////////////// // throws warning about being unable to bind 'line' to 'Object' as it does not //extend IDispatcher although it does seem to work // Any way of getting rid of the warning? Use XML as dataProvider perhaps //as ArrayCollection does wrap 'Objects'? Or should I cast {text.line} to // something that is bindable? If so what? <?xml version="1.0" encoding="utf-8"?> <mx:HBox xmlns:mx="http://www.adobe.com/2006/mxml" width="100%" height="100%"> <mx:Script> <![CDATA[ public function get textHeight():int{ return line.height; } ]]> </mx:Script> <mx:Text id="line" text="{data.line}" width="90%" selectable="false"/> </mx:HBox> |
| Sponsored Links |
|
|||
|
"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? |
|
|||
|
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. |
|
|||
|
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? |
|
|||
|
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 |
|
|||
|
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... |
|
|||
|
"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 |
|
|||
|
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 |
|
|||
|
"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/0...renderers.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 |
![]() |
| Thread Tools | |
| Display Modes | |
|
|
- Contact Us
-|-
Adobe Dreamweaver Forums -|-
Archive -|-
Top -|-Rules/Disclaimer-|-Help/Support-|-Advertise