So what would be an alternative ?? Is it best practice to create IRs using AS3 ? I am all for whatever works consistently.
If I am pushing the envelop trying to use an MXML component as an Item Renderer and adding events to produce dynamic styles and object then by all means somebody save me ! Alex Harui wrote: > I'd be careful about using "render" it can get called often. Always > assume that data could be null. > > > > -Alex > > > > ________________________________ > > From: [email protected] [mailto:[EMAIL PROTECTED] On > Behalf Of Aaron Wright > Sent: Friday, June 01, 2007 8:41 AM > To: [email protected] > Subject: [flexcoders] Re: [SOLVED] itemRenderer null object error > > > > Maybe I've a little naive but I like making nearly everything in > actionscript 3, especially itemRenderers. Then, you can handle all the > positioning and styles in the updateDisplayList function if you want. > This generally follows the Adobe approach to it as well. I say start > with looking over Adobe code for itemRenderers, and see where you need > to add your code to make it do what you want. > > In the end you avoid listening for events, and not knowing what event > is going to fire in what occasion. > > --- In [email protected] <mailto:flexcoders%40yahoogroups.com> > , Ben Marchbanks <[EMAIL PROTECTED]> wrote: >> After experimenting I found the solution was to change the event > trigger from >> "initialize" to "render". >> >> Happy to have resolved the problem but still puzzled why > "initialize" worked for >> one itemRenderer and not the other since from all appearances the >> implementations are identical ??? >> >> >> >> pdflibpilot wrote: >>> I am so happy I was able to create an itemRenderer with an > initialize >>> event that dynamically set the style for each item based on the > source >>> data. This worked flawlessly for one HorizontalList ( List A) so I >>> tried to implement the same on a TileList (List B) on the same > layout. >>> They have virtually the same dataProvider - List B items are >>> originally drag/dropped to List A. >>> >>> These list are nearly identical in every way yet when the event > fires >>> for the itemRenderer in List B it fails with "null object" error. It >>> seems that the data is not available when the event dispatches. I am >>> at a loss as to why it works for one list and not the other. The > data >>> used by the event is not null when it renders since all the items >>> (data) are accounted for. >>> >>> here my itemRenderer code that works - >>> >>> <?xml version="1.0" encoding="utf-8"?> >>> <!-- itemRenderers\navScreenRender.mxml --> >>> >>> <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml > <http://www.adobe.com/2006/mxml> " >>> width="200" >>> height="200" >>> horizontalScrollPolicy="off" >>> verticalScrollPolicy="off" >>> borderStyle="solid" backgroundImage="assets/images/{data.imageID}" >>> alpha="1.0" backgroundAlpha="1.0" borderColor="#333333"> >>> >>> <mx:Script> >>> <![CDATA[ >>> >>> private function setContentButton(event:Event,V):void{ >>> var e = event.currentTarget >>> if(V==''){ >>> e.styleName = 'customcontentbuttonOff' >>> e.alpha = 1.0 >>> e.toolTip = "Content Editor is not enabled for this screen - click >>> to complete the setup" >>> } >>> else if(V!="(preset)"){ >>> e.styleName = 'customcontentbuttonOn' >>> e.alpha = 1.0 >>> e.toolTip = "Content Editor is enabled for this screen - click to >>> change the setup" >>> } >>> else if(V=="(preset)"){ >>> e.alpha = 0.0 >>> } >>> } >>> ]]> >>> >>> </mx:Script> >>> <mx:Text id="layoutLabel" text = "{data.label}" >>> fontSize="8" >>> color="#ffffff" >>> textAlign="center" >>> letterSpacing="0" >>> horizontalCenter="0" verticalCenter="-38"/> >>> <mx:Image source = "assets/images/{data.imageID}" >>> toolTip="{data.description}" >>> scaleContent="false" alpha="1" >>> visible="false"/> >>> <mx:Button label="{data.displaySeq-0+1}" width="25" height="20" >>> cornerRadius="12" styleName="adminbutton" fontWeight="bold" >>> fontSize="9" verticalCenter="20" horizontalCenter="0"/> >>> <mx:Button id="contentButton" >>> initialize="{setContentButton(event,data.contentLocation)}" >>> label="C" width="18" height="18" >>> cornerRadius="12" >>> styleName="customcontentbuttonOff" >>> fontWeight="bold" fontSize="10" >>> verticalCenter="-1" horizontalCenter="0" >>> alpha="1.0"/> >>> >>> </mx:Canvas> >>> >>> >> -- >> Ben Marchbanks >> >> ::: alQemy ::: transforming information into intelligence >> http://www.alQemy.com <http://www.alQemy.com> >> >> ::: magazooms ::: digital magazines >> http://www.magazooms.com <http://www.magazooms.com> >> >> Greenville, SC >> 864.284.9918 >> > > > > -- Ben Marchbanks ::: alQemy ::: transforming information into intelligence http://www.alQemy.com ::: magazooms ::: digital magazines http://www.magazooms.com Greenville, SC 864.284.9918

