Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 12-04-2006, 02:38 PM   #1
ajonat
Registered User
 
Join Date: Dec 2006
Posts: 2
Unhappy Problem with custom ItemRenderer

Hi!

I want to create a custom itemRenderer that displays an image in a dataGrid cell. The problem I'm having is that the image is displayed AFTER I click on the cell. I mean, when the grid is first displayed it shows and error image (as if the image I wanted to show wasn't found). However, if click on a cell (to open the itemEditor) and then move to another cell (to close the itemEditor on the previous cell), the image is show correctly.

Here is the code of the Application with the dataGrid:

Code:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init();">

<mx:Script>
	<![CDATA[
		import mx.collections.ArrayCollection;

		[Embed(source="image1.gif")]
		[Bindable]
		public var IMAGE1:Class;
		
		[Embed(source="image2.gif")]
		[Bindable]
		public var IMAGE2:Class;

		[Embed(source="image3.gif")]
		[Bindable]
		public var IMAGE3:Class;
		
		[Bindable]
		public var dataProvider:ArrayCollection = new ArrayCollection();
		
		public function init():void {
			var o:Object;

			o = new Object();
			o["icon"] = IMAGE1;
			dataProvider.addItem(o);
			
			o = new Object();
			o["icon"] = IMAGE2;
			dataProvider.addItem(o);
			
			o = new Object();
			o["icon"] = IMAGE3;
			dataProvider.addItem(o);
		}
		
	]]>
</mx:Script>

<mx:DataGrid dataProvider="{dataProvider}" editable="true" enabled="true">
        <mx:columns>
		<mx:DataGridColumn id="col" dataField="icon" editable="true" itemRenderer="ImageItemRenderer"/>
		</mx:columns>
	</mx:DataGrid>
And here is the itemRenderer (ImageItemRenderer):

Code:
package
{
	import mx.controls.Image;
	import mx.events.FlexEvent;

	public class ImageItemRenderer extends Image
	{
		
		public function ImageItemRenderer() {
			super();
			addEventListener("dataChange", dataChangeHandler);
		}
		
		private function dataChangeHandler(event:FlexEvent):void {
			source = data["icon"];
		}
		
	}
}
ajonat is offline   Reply With Quote
Old 12-05-2006, 01:14 PM   #2
ajonat
Registered User
 
Join Date: Dec 2006
Posts: 2
Exclamation

The solution was simple: variableRowHeight must be set to true in the DataGrid for the images to be displayed correctly at the loading of the application. The documentation didn't help at all and I found the answer in the source of mx::Image (although it wasn't mentioned in relation with itemRenderers). Thanks Flex!
ajonat is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
problem creating a custom component based on another custom component oertime66 ActionScript 3.0 2 10-26-2006 01:16 PM
Movie clip custom Menu problem barry_normal ActionScript 2.0 1 12-13-2005 04:50 PM
Flash Number type and c# float and decimal types. Convertion problem within Flash. maglez ActionScript 2.0 2 06-02-2005 05:14 PM
Problem: Flash takes over browser resources Das123 ActionScript 1.0 (and below) 2 05-19-2004 08:14 PM
custom cursor problem... zxIceDragon ActionScript 2.0 2 03-23-2004 07:37 AM


All times are GMT. The time now is 04:25 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.