Adobe Dreamweaver Forums



Last 10 THreads :         Load dynamic text into an embeded swf (Last Post : mikeyjray - Replies : 4 - Views : 9 )           »          Log email text (Last Post : Torgom - Replies : 0 - Views : 1 )           »          Properties > Flex Build Path (Last Post : kevxross - Replies : 0 - Views : 1 )           »          Can Anyone Help With Sub Menus (Last Post : Murray *ACE* - Replies : 8 - Views : 9 )           »          transferring DW license from crashed computer (Last Post : Sonjay - Replies : 1 - Views : 7 )           »          DIV in Table not working. (Last Post : Murray *ACE* - Replies : 13 - Views : 14 )           »          Variable for Loader Content (Last Post : Sea Crystal - Replies : 0 - Views : 1 )           »          left join won't work in query of query? (Last Post : Dan Bracuk - Replies : 5 - Views : 6 )           »          fireworks exports hundreds of files (Last Post : Rob Miller - Replies : 0 - Views : 1 )           »          Fireworks Color Selection Bug (Last Post : Linda Rathgeber - Replies : 3 - Views : 4 )           »         


Home Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
User Info Statistics
Go Back   Adobe Dreamweaver Forums > Other Macromedia/Adobe Products > Flex
 
Tags:



Reply
  #1 (permalink)  
Old 11-23-2008, 04:13 PM
blipstation
 
Posts: n/a
Diggs:
Default {object object] in ComboBox + ListEvent.CHANGEitemRenderer always null

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(eropdownEvent):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>



Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 11-23-2008, 08:15 PM
Amy Blankenship
 
Posts: n/a
Diggs:
Default Re: {object object] in ComboBox + ListEvent.CHANGE itemRenderer always null


"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?


Reply With Quote
  #3 (permalink)  
Old 11-23-2008, 10:03 PM
blipstation
 
Posts: n/a
Diggs:
Default Re: {object object] in ComboBox + ListEvent.CHANGEitemRenderer always null

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.

Reply With Quote


  #4 (permalink)  
Old 11-24-2008, 12:13 AM
blipstation
 
Posts: n/a
Diggs:
Default Re: {object object] in ComboBox + ListEvent.CHANGEitemRenderer always null

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?

Reply With Quote
  #5 (permalink)  
Old 11-24-2008, 12:35 AM
Masamune
 
Posts: n/a
Diggs:
Default Re: {object object] in ComboBox + ListEvent.CHANGEitemRenderer always null

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

Reply With Quote
  #6 (permalink)  
Old 11-24-2008, 11:03 AM
blipstation
 
Posts: n/a
Diggs:
Default Re: {object object] in ComboBox + ListEvent.CHANGEitemRenderer always null

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...





Reply With Quote


  #7 (permalink)  
Old 11-24-2008, 02:04 PM
Amy Blankenship
 
Posts: n/a
Diggs:
Default Re: {object object] in ComboBox + ListEvent.CHANGE itemRenderer always null


"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


Reply With Quote
  #8 (permalink)  
Old 11-24-2008, 03:23 PM
blipstation
 
Posts: n/a
Diggs:
Default Re: {object object] in ComboBox + ListEvent.CHANGEitemRenderer always null

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

Reply With Quote
  #9 (permalink)  
Old 11-24-2008, 05:23 PM
article man
 
Posts: n/a
Diggs:
Default Re: {object object] in ComboBox + ListEvent.CHANGEitemRenderer always null

this helped me dubug too,thanks and now it seems to work well,thanks guys.
regards,
Reply With Quote


  #10 (permalink)  
Old 11-25-2008, 02:02 PM
Amy Blankenship
 
Posts: n/a
Diggs:
Default Re: {object object] in ComboBox + ListEvent.CHANGE itemRenderer always null


"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


Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



© Camley Interactive (camley.info) 2008 - all logos and images are copywrite their respective owners.
Proud member of the Camley Interactive Network
All times are GMT. The time now is 11:17 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0 ©2007, Crawlability, Inc.
Cheap Car Insurance - Compare Motor Insurance
Endsleigh Car Insurance Natwest Car Insurance
More Than Car Insurance Norwich Union Car Insurance
Prudential Car Insurance Zurich Car Insurance
Inactive Reminders By Mished.co.uk