Monday, August 8, 2011

Binding itemRenderer with property not in data object

I really had a tough time with this one. Almost all the approaches I took with this failed.

So, what I really wanted to do was to add a line in the itemRenderer based on whether some property outside matched with the itemIndex or not. Getting the data in was not a problem. Binding it sure was.

Using outerDocument.property_name works only if the line was predefined, but since predefining Graphics elements caused a huge performance issue. I could not use that approach. Instead I added the code to draw the line in the updateDisplayList function.

Now the only thing was to bind the data. I tried to use outerDocument from the child and failed. Even the ClassFactory for the itemRenderer failed. So, then I tried adding event listeners on the change event of the NumericStepper in the parent and changed my display accordingly. Worked like a charm.

ItemRenderer Code:

private function creationComplete_eventHandler(event:Event):void
      outerDocument.nStepper.addEventListener(Event.CHANGE, this.onStepperChange);

private function onStepperChange(event:Event):void

       //Your code goes here.

I am still at a loss though on why the others failed. If anyone has any ideas, do share.

No comments :