Skip to main content
Inspiring
September 19, 2012
Answered

Why undefined for a number in this datagrid ?

  • September 19, 2012
  • 1 reply
  • 975 views

Hi,

Flash CS5

(Keeping this separate to my other thread so as not to sidetrack it too much and assist others with this issue.)

I have a datagrid in which the content is not pulled from an outside source but written in the code just for testing. The grid when clicked on displays in a dynamic text box on stage, (following a youtube article which used Dynamic text) but I get:

BusRoute: Undefined

Sttmnt1: Oxford

Sttmnt2: Burford

Sttmnt3: Swindon

why not the number ?  It displays the number as such for each row by the way.

code is:-

import fl.controls.DataGrid;
import flash.events.Event;
import fl.controls.ScrollPolicy;

var item1:Object={BusRoute:"43",Sttmnt1:"Oxford",Sttmnt2:"Burford",Sttmnt3:"Swindon"};
var item2:Object={BusRoute:"361",Sttmnt1:"Evesham",Sttmnt2:"ChippingNorton",Sttmnt3:"Buckingham"};

var myTextFormat:TextFormat=new TextFormat();
myTextFormat.font="Arial";
myTextFormat.color=000000
myTextFormat.size=14;

var datagrid:DataGrid=new DataGrid;
datagrid.move(20,50);
datagrid.width=200;
datagrid.height=70;
datagrid.rowHeight=35;
datagrid.columns=["BusRoute","Sttmnt1","Sttmnt2","Sttmnt3"];
datagrid.columns[0].width=30;
datagrid.columns[1].width=70;
datagrid.columns[2].width=70;
datagrid.resizableColumns=true;
datagrid.horizontalScrollPolicy = ScrollPolicy.ON;
datagrid.setRendererStyle("textFormat",myTextFormat);
datagrid.addItem(item1);
datagrid.addItem(item2);

addChild(datagrid);

datagrid.addEventListener(Event.CHANGE,gridItemClick);

function gridItemClick(event:Event):void{

DataGridSelectedRowText.text="BusRoute:"+event.target.selectedItem.Task + "\n";
DataGridSelectedRowText.appendText("Sttmnt1:"+event.target.selectedItem.Sttmnt1 + "\n");
DataGridSelectedRowText.appendText("Sttmnt2:"+event.target.selectedItem.Sttmnt2 + "\n");
DataGridSelectedRowText.appendText("Sttmnt3:"+event.target.selectedItem.Sttmnt3 + "\n");

}

Envirographics


This topic has been closed for replies.
Correct answer Ned Murphy

In your item1 and item2 objects you are defining the first property to be "BusRoute"

var item1:Object={BusRoute:"43",Sttmnt1:"Oxford",Sttmnt2:"Burford",Sttmnt 3:"Swindon"};

but in your attempt to acquire the data you appear to be refering to it as "Task"

DataGridSelectedRowText.text="BusRoute:"+event.target.selectedItem.Task + "\n";

One of them has to be changed to agree with the other.

1 reply

Ned Murphy
Ned MurphyCorrect answer
Legend
September 19, 2012

In your item1 and item2 objects you are defining the first property to be "BusRoute"

var item1:Object={BusRoute:"43",Sttmnt1:"Oxford",Sttmnt2:"Burford",Sttmnt 3:"Swindon"};

but in your attempt to acquire the data you appear to be refering to it as "Task"

DataGridSelectedRowText.text="BusRoute:"+event.target.selectedItem.Task + "\n";

One of them has to be changed to agree with the other.

Inspiring
September 20, 2012

Hi and thanks,

OOps overlooked that one.

Understod.

Cheers

Envirographics

Ned Murphy
Legend
September 20, 2012

You're welcome