Question

This is a view-based project for Android using Flash Builder 4.5

In my views.ListView I have a list element like this <s:List id = "myList" itemRenderer="components.myCustomRenderer" dataProvider="{Global.itemArrayList}"> </s:List>

Global is a class I use to store shared values for all the views

myCustomRenderer list has a deleteButton which when clicked, execute the following function

public function deleteButtonnHandler(event:MouseEvent):void {
    var removeItem:myItem = super.data as myItem;
        this.parentApplication.navigator.activeView.myList.dataProvider.removeItem(removeItem);
    }

it also overrides the set data function as follow

override public function set data(value:Object):void {
        super.data = value;
        nameText.text = value.name;
    }

when I click the deleteButton, I get ERROR #1009 saying the line nameText.text = value.name accesses properties of null object

I try removing the item from Global.itemArrayList directly but the same error occurs. This is my first time dealing with custom ItemRenderer and List so I don't understand the events that are dispatched when an item is removed very well. Tracing the error message, I see some kind of dataProvider change event was dispatched but as to why that causes the error I have no clue.

Other than this error, my renderer and list work fine.

Some help to elucidate me on the subject and to solve this problem would be very appreciated.

Thanks

Was it helpful?

Solution

If you update setter data in following way, you should avoid error 1009:

override public function set data(value:Object):void {
    super.data = value;
    if (value) {
        nameText.text = value.name;
    } else {
        nameText.text = "";
    }       
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top