You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@flex.apache.org by mark goldin <ma...@gmail.com> on 2016/03/16 21:55:40 UTC

Custom itemrenderer doesn't show data

Here is my custom itemrenderer code:
import mx.controls.Text;
import mx.controls.listClasses.BaseListData;
import mx.controls.listClasses.IDropInListItemRenderer;
import mx.controls.listClasses.IListItemRenderer;
import mx.core.UIComponent;
public class AssetPathRenderer extends UIComponent implements
IDropInListItemRenderer, IListItemRenderer
{
private var _listData:BaseListData;
private var _data:Object;
private var assetPathText:Text;
public function AssetPathRenderer()
{
super();
assetPathText = new Text();
this.(assetPathText);
assetPathText.visible = true;
}
public function get listData():BaseListData
{
return _listData;
}
public function set listData(value:BaseListData):void
{
_listData = value;
}
public function get data() : Object
{
return _data;
}
public function set data(value:Object):void
{
if (value)
{
if (value.assetPath != "")
assetPathText.text = value.assetPath;
else
assetPathText.text =  value.path;
}
_data = value;
}
}

Implementation. Simplified:
<column itemRenderer="AssetPathRenderer"/>

No data is shown in the column. What am I doing wrong?

Thanks

Re: Custom itemrenderer doesn't show data

Posted by OK <OK...@edscha.com>.
mark goldin wrote
> Implementation. Simplified:
> <column itemRenderer="AssetPathRenderer"/>
> No data is shown in the column. What am I doing wrong?
> 
> Thanks

I don't unterstand your renderer completely but are you sure that you pass
any data object to the column that Provides at least probably the properties
path or assetPath?

Olaf




--
View this message in context: http://apache-flex-users.2333346.n4.nabble.com/Custom-itemrenderer-doesn-t-show-data-tp12269p12270.html
Sent from the Apache Flex Users mailing list archive at Nabble.com.

Re: Custom itemrenderer doesn't show data

Posted by mark goldin <ma...@gmail.com>.
Here is what actually worked:
public class AssetPathRenderer extends UIComponent implements
IListItemRenderer
{
private var _listData:BaseListData;
private var _data:Object;
private var assetPathText:Text;
public function AssetPathRenderer()
{
super();
}
override protected function createChildren() : void
{
super.createChildren();
assetPathText = new Text();
this.addChild(assetPathText);
assetPathText.visible = true;
}
public function get data() : Object
{
return _data;
}
public function set data(value:Object):void
{
if (value)
{
if (value.assetPath != "")
assetPathText.text = value.assetPath;
else
assetPathText.text =  value.path;
}
_data = value;
}
override protected function updateDisplayList(unscaledWidth:Number,
unscaledHeight:Number ) : void
{
super.updateDisplayList(unscaledWidth, unscaledHeight);
assetPathText.setActualSize(unscaledWidth,unscaledHeight);
}
}
The critical piece was:
assetPathText.setActualSize(unscaledWidth,unscaledHeight);



On Thu, Mar 17, 2016 at 9:06 AM OK <OK...@edscha.com> wrote:

> Just remember another solution:
> Regarding performance issues probably the fastest way is to don't use any
> itemRenderers.
> So if it works in your scenario you may go with this:
>
> public class MySuperVO
> {
>    public var path:String;
>    public var assetPath:String;
>
>    // Getter that returns the path depending on custom conditions
>    public function get currentPath():string {
>       return assetPath!=""?assetPath:path;
>    }
> }
>
> // Will invoke our getter
> <column id="currentPath"/>
>
> HTH,
> Olaf
>
>
>
>
> --
> View this message in context:
> http://apache-flex-users.2333346.n4.nabble.com/Custom-itemrenderer-doesn-t-show-data-tp12269p12276.html
> Sent from the Apache Flex Users mailing list archive at Nabble.com.
>

Re: Custom itemrenderer doesn't show data

Posted by OK <OK...@edscha.com>.
Just remember another solution:
Regarding performance issues probably the fastest way is to don't use any
itemRenderers.
So if it works in your scenario you may go with this:

public class MySuperVO
{
   public var path:String;
   public var assetPath:String;
	
   // Getter that returns the path depending on custom conditions
   public function get currentPath():string {
      return assetPath!=""?assetPath:path;           
   }
}

// Will invoke our getter
<column id="currentPath"/>

HTH,
Olaf




--
View this message in context: http://apache-flex-users.2333346.n4.nabble.com/Custom-itemrenderer-doesn-t-show-data-tp12269p12276.html
Sent from the Apache Flex Users mailing list archive at Nabble.com.

Re: Custom itemrenderer doesn't show data

Posted by OK <OK...@edscha.com>.
Hi Mark,
I don't know if this is more performant, but this should do the trick:

// Wrapper method that creates a ClassFactory instance
public static function createItemRenderer(renderer:Class, properties:Object
):IFactory {
	var factory:ClassFactory = new ClassFactory(renderer); 
	factory.properties = properties;
	return factory;
}

<column itemRenderer="{MyComponent.createItemRenderer(Text, {text:
'MyPath'}) }"/>

HTH,
Olaf



--
View this message in context: http://apache-flex-users.2333346.n4.nabble.com/Custom-itemrenderer-doesn-t-show-data-tp12269p12274.html
Sent from the Apache Flex Users mailing list archive at Nabble.com.

Re: Custom itemrenderer doesn't show data

Posted by mark goldin <ma...@gmail.com>.
Yes, mxml alternative would work, but I am trying to use UIComponent for
performance reasons. also I am still doing mx, no Spark.

On Thu, Mar 17, 2016 at 3:38 AM OK <OK...@edscha.com> wrote:

> If mxml could be an alternative perhaps you'd would like to try it this?:
>
> <?xml version="1.0" encoding="utf-8"?>
> <s:ItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
>                                 xmlns:s="library://ns.adobe.com/flex/spark
> "
>                                 xmlns:mx="library://ns.adobe.com/flex/mx"
>                                 autoDrawBackground="true" width="100%">
>
>         <mx:Text id="myText"
> text="{data.assetPath!=''?data.assetPath:data.path}"/>
>
> </s:ItemRenderer>
>
> Olaf
>
>
>
> --
> View this message in context:
> http://apache-flex-users.2333346.n4.nabble.com/Custom-itemrenderer-doesn-t-show-data-tp12269p12272.html
> Sent from the Apache Flex Users mailing list archive at Nabble.com.
>

Re: Custom itemrenderer doesn't show data

Posted by OK <OK...@edscha.com>.
If mxml could be an alternative perhaps you'd would like to try it this?:

<?xml version="1.0" encoding="utf-8"?>
<s:ItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009" 
				xmlns:s="library://ns.adobe.com/flex/spark" 
				xmlns:mx="library://ns.adobe.com/flex/mx" 
				autoDrawBackground="true" width="100%">

	<mx:Text id="myText" text="{data.assetPath!=''?data.assetPath:data.path}"/>

</s:ItemRenderer>

Olaf



--
View this message in context: http://apache-flex-users.2333346.n4.nabble.com/Custom-itemrenderer-doesn-t-show-data-tp12269p12272.html
Sent from the Apache Flex Users mailing list archive at Nabble.com.