PDA

View Full Version : CellRenderer example please?


danimal
03-03-2006, 03:25 AM
Can someone point out or post a good example of using a CellRenderer in a List please? Every example I've found, including Macromedia's, just does not explain it very well. I've been using cell renderers for a long time in Java Swing, so I'm familiar with how it works in theory, but for some reason ActionScripts's version of it is just not clicking with me.

My current use of it requires displaying an icon, and a bit of text, for an array of objects that holds several fields. But I just cannot see how to make it actually display anything, all I get is a blank field (which is still selectable).

Thanks.

Xeef
03-03-2006, 12:10 PM
http://livedocs.macromedia.com/flash/8/main/00003131.html

danimal
03-07-2006, 02:35 PM
http://livedocs.macromedia.com/flash/8/main/00003131.html


Yeah, I've read this and looked over the example code several times, but it just doesn't make any sense. First, there isn't a simple demonstration of a single column list to look at, only datagrids, and I don't see where the value to display gets from the array into the cell object to render. Does the renderer's setValue() just intuit the proper field to display? What about in the more complex example with the combobox and checkbox? I'm just not finding detailed enough documentation from Macromedia or anywhere else on how this works.

Thanks,
Dan

Xeef
03-07-2006, 02:58 PM
Does the renderer's setValue() just intuit the proper field to display?

yes ( sortof )

each field has a function "setValue" wich is called then


and I don't see where the value to display gets from the array into the cell object to render

here :

setValue(suggestedValue:String, item:Object, selected:Boolean)

item is the object whit the values

eg.

item.MyValue
item.MycheckboxValue
....

danimal
03-07-2006, 03:24 PM
yes ( sortof )

each field has a function "setValue" wich is called then




here :

setValue(suggestedValue:String, item:Object, selected:Boolean)

item is the object whit the values

eg.

item.MyValue
item.MycheckboxValue
....

Ok, so when I want to add my object into the Array, I would use
addItem({field1:value, field2:value})

Then in setValue() I can retrieve those fields using
item.field1
item.field2
?

I've found that I'm not able to trace() from my cellrenderer class, is that normal or is there some other way to check values while in there?

Thanks for all the help,
Dan

Xeef
03-07-2006, 03:29 PM
you shoud by abel to trace from the class if not there is something wrong !

danimal
03-07-2006, 06:31 PM
you shoud by abel to trace from the class if not there is something wrong !

So I see-- I put traces in the Macromedia cellrendering example (combobox & checkbox cells in a datagrid) and they output fine. I get nothing in my own single column List cellrenderer though. I don't know what it could be though, I started off with the MultiLineCell example and began customizing from there. I set it with list.cellRenderer = myCellRenderer. Is it done some different way?

Thanks,
Dan

Scottae
03-07-2006, 07:08 PM
Here's a good example:

http://www.flash-db.com/Tutorials/cellrenderer/index.php

Remember, the DataGrid class (http://livedocs.macromedia.com/flash/8/main/00003260.html) extends the List class (http://livedocs.macromedia.com/flash/8/main/00003703.html). So it's essentially going to be done the same way for both. The difference being that List components only have one column where DataGrid components can have more than one. You may also want to take a look at this thread (http://flashmove.com/forum/showthread.php?t=16717) as well.

Xeef
03-07-2006, 07:41 PM
list.cellRenderer = myCellRenderer

myCellRenderer needs to by a STRING whit the library identifier of the clip linked to the cellrendererClass

danimal
03-07-2006, 09:43 PM
list.cellRenderer = myCellRenderer

myCellRenderer needs to by a STRING whit the library identifier of the clip linked to the cellrendererClass

Oops, I did mean the string. I'm starting to think somehow my custom cell renderer simply is not being used, and my list.cellRenderer = "myCellRenderer" is just setting an undefined renderer. I put it in an external .as file, found in the same folder as the fla, and it contains all of the MultiLineCell.as example code. Isn't that enough, or is there something else I must do?

Ah, is it necessary to setup the class for exporting using the Linkage Properties dialog as well?

danimal
03-08-2006, 08:39 PM
I don't think I can express just how frustrating this is. :)

I have gone through several examples, threads, and looked at completed projects that run correctly, and yet my own cellrenderer simply does not work. I don't think the list object is even using it, because a trace() in it's constructor never displays. Is there something else to setting one up that is so simple, that tutorials simply forget to explain it?

Scottae
03-08-2006, 09:12 PM
Here's a very quickie example

danimal
03-08-2006, 10:03 PM
Thanks Scott, I actually had to rename the MyCellRenderer for some reason because it kept giving me some error that the class was already being imported, but after naming everything to ACellRenderer your example worked. Now I'm concerned why yours works and mine doesn't. :) I'm thinking that I may be missing some detail in setting up the Linkage properties, but I don't know what it could be.

in my fla, I have
list.cellRenderer = "UsersCellRenderer";

my as file is UsersCellRenderer.as, found in the same directory.

I've added a blank MovieClip to my library, and named it UsersCellRenderer, and it's Linkage settings are:
Name: UsersCellRenderer
Type: Movie Clip

Identifier: UsersCellRenderer
AS2.0 class: UsersCellRenderer
Export for ActionScript

However I do not see the trace I have in my constructor, and when the applet is run and the list gets filled with some entries, all I see are the correct number, but blank rows (which do highlight and select when clicked). If I comment out the list.cellRenderer line, then text representations of my rows do appear, which makes me think that the = "UsersCellRenderer" line is just resolving to a null or undefined somehow.

Could I be making a mistake in my linkage properties?

Thanks for all the help

danimal
03-09-2006, 03:06 PM
I have even tried dragging your cell renderer over into my own library and still it won't work. My List object was added onto the stage in Flash, is it necessary to create the List dynamically instead, for a cellrenderer to work?

Thanks,
Dan

Scottae
03-09-2006, 03:19 PM
No it should work either way. Could you mock up an example of what you are doing and attach it and I'll see if I can look at it later.

danimal
03-09-2006, 03:54 PM
Well, I threw together an example really quickly, just a List on the stage, and my cellrenderer worked fine on it. But the exact same code, with the exact same linkage properties does not work in my real project. I don't know what the difference could be, but I'll keep plugging away at it.

Thanks for the help..

kirs10
03-21-2006, 09:17 PM
Hi All,

I have a Datagrid displaying a bunch of columns, with either a 'true' or 'false' value in each cell (kinda looks like the table below). I want a check mark icon to show in place of the 'true's and nothing for the 'false' cells.

17056

I am learning how to use CellRenderer and I can get it to show the icon for the entire column, by doing something like:

column.cellRenderer = "ComboBoxCellRenderer";

But the cell values change from row to row and column to column. Is there some way to specify the CellRenderer for each cell?? I read Scottae's post refering to another thread about his button example, and I've also been using the tutorial at http://www.flash-db.com/Tutorials/cellrenderer/ and I'm not fully understanding how to get it to do this.

Any help would be appreciated! Thanks!!
Kirsten
:)

kirs10
03-22-2006, 08:51 PM
Nevermind. I got mine to work like the car icon example : http://www.flash-db.com/Tutorials/cellrenderer/.

Thanks for everyone's help on this topic!! I'm sure I'll be back! :p