* Newbie Alert *
I have an AdvancedDataGrid with 5 columns. The second column, with header Labels, needs to be able to contain multiple lines in each cell.
Initially, my grid’s dataprovider was defined as follows:
[Bindable]
public var mappedTagsArray:ArrayCollection = new ArrayCollection( [
{ name: "garbage-garbage", semanticTags: "garbage-flirt\ngarbage-garbage\ngarbage-noise\ngarbage-profanity", exitStrategy: "Fallback", confirmationMode: "IF NECESSARY", confirmationPromptlet: "cp5" },
{ name: "report-sim", semanticTags: "enquire-sim\nreport-sim", exitStrategy: "Direct", confirmationMode: "NEVER", confirmationPromptlet: "cp6" }
] );
The Columns label was defined as follows, with an inlined TextArea component to handle the multiple lines in one cell:
<mx:AdvancedDataGridColumn id="semanticTags" headerText="Labels" dataField="semanticTags" editable="false">
<mx:itemRenderer>
<fx:Component>
<mx:HBox horizontalScrollPolicy="off" verticalScrollPolicy="off"
top="0" bottom="0" right="0" left="0">
<fx:Script>
<![CDATA[
import com.nuance.csportal.mw_api.CallerIntent;
public function get value() : String
{
return ta_labels.text;
}
override public function set data(value:Object):void
{
super.data = value;
ta_labels.text = value.semanticTags;
}
]]>
</fx:Script>
<!-- BUG: Scroll bar is fixed in one location; does not move with resizing of cell -->
<s:TextArea id="ta_labels" heightInLines="2" editable="false" borderVisible="false"
horizontalScrollPolicy="auto" verticalScrollPolicy="auto" contentBackgroundAlpha="0"
top="0" bottom="0" right="0" left="0"/>
</mx:HBox>
</fx:Component>
</mx:itemRenderer>
</mx:AdvancedDataGridColumn>
In this scenario, the semanticTags multiple lines are displayed in the Labels column’s cell.
Now I’ve created a custom ActionScript class called CallerIntent:
package com.nuance.csportal.mw_api
{
import mx.controls.List;
public class CallerIntent
{
public function CallerIntent( id:int, name:String, semanticTags:Array, exitStrategy:String, confirmationMode:String, confirmationPromptlet:String )
{
this.id = id;
this.name = name;
this.semanticTags = semanticTags;
this.exitStrategy = exitStrategy;
this.confirmationMode = confirmationMode;
this.confirmationPromptlet = confirmationPromptlet;
}
public var id:int;
public var name:String;
public var semanticTags:Array;
public var exitStrategy:String;
public var confirmationMode:String;
public var confirmationPromptlet:String;
}
}
And in my init() method which is called upon creationComplete of my form, I populate my grid’s dataprovider:
public function init( event:Event ):void
{
var st1:Array = new Array( "garbage-flirt", "garbage-garbage", "garbage-noise", "garbage-profanity" );
var st2:Array = new Array( "enquire-sim", "report-sim" );
var ci1:CallerIntent = new CallerIntent( 1, "garbage-garbage", st1, "Fallback", "IF NECESSARY", "cp1" );
var ci2:CallerIntent = new CallerIntent( 2, "report-sim", st2, "Direct", "NEVER", "cp2" );
mappedTagsArray.addItem( ci1 );
mappedTagsArray.addItem( ci2 );
}
In this scenario, my app crashes in the override set data method at
ta_labels.text = value.semanticTags;
with
Cannot access a property or method of a null object reference.
This is true – value remains null when I’m using an ArrayCollection of CallerIntent objects as opposed to the ArrayCollection of unnamed objects (in this case, value will hold the unnamed Object).
I tried changing the function’s signature to
override public function set data(value:CallerIntent):void
and got Incompatible Override.
Any ideas? Thanks!
Bonnie
I’ve fixed my problem.
My grid’s dataprovider is getting populated AFTER the overridden set data method is first called.
Hence I just had to put
around this code.