Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Adobe AIR Development

Reply
Contributor
Posts: 18
Registered: ‎02-24-2011
My Device: Not Specified

Problem capturing index from item in array using list vs. drop down

I was using a drop down menu, filling it from a data provider.  I was able to delete particular items in the drop down, by capturing the selectedIndex and passing the index to a deleteItem function that would splice that index from the array.

 

I have switched to a list that fills the data from the same data provider.  I am still using the selectedIndex, but when I pass it to the deleteItem function, incorrect items are being deleted.

 

Is there something I need to do differently capturing a selection from a list and passing that to a function?

 

Thanks for the help guys, I am still pretty green with this.

Developer
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: Problem capturing index from item in array using list vs. drop down

Any chance you're deleting multiple items, in a loop?

If not, maybe you'd better post a bit of code showing what you're doing in the routine where you call deleteItem().

Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Contributor
Posts: 18
Registered: ‎02-24-2011
My Device: Not Specified

Re: Problem capturing index from item in array using list vs. drop down

here is the list:

 

var entryTitles:List = newList();

entryTitles.x = 40;

entryTitles.y = 70;

entryTitles.height = 490;

entryTitles.width = 420;

 

entryTitles.dataProvider = getSharedData();

entryTitles.dataProvider.data.sortOn("label");

entryTitles.dataProvider.setItems(entryTitles.dataProvider.data, true);

 

entryTitles.addEventListener(ListEvent.ITEM_CLICKED,showEntry);

addChild(entryTitles);

 

here is the delete button call:

 

var

deleteSelected:LabelButton = newLabelButton();

deleteSelected.setTextFormatForState(buttonFormat,SkinStates.DISABLED);

deleteSelected.setTextFormatForState(buttonFormat,SkinStates.UP);

deleteSelected.setTextFormatForState(buttonFormat,SkinStates.DOWN);

deleteSelected.setTextFormatForState(buttonFormat,SkinStates.SELECTED);

deleteSelected.setTextFormatForState(buttonFormat,SkinStates.DISABLED_SELECTED);

deleteSelected.label = "Delete Entry"

deleteSelected.addEventListener(MouseEvent.CLICK,function(){

deletetrip(entryTitles.selectedIndex);

});

deleteSelected.x = 765;

deleteSelected.y = 500;

deleteSelected.width = 220;

deleteSelected.height = 60;

addChild(deleteSelected);

 

Here is the deletetrip function:

 

private function deletetrip(index):void{

 

var soSmiley FrustratedharedObject = SharedObject.getLocal("MileageManager");

var storedObjectSmiley Surprisedbject = so.data["entries"];

var savedentries:Array = newArray

 

if(storedObject != null){

savedentries = storedObject as Array;

 

savedentries.splice(index, 1);

 

so.data["entries"] = savedentries;

so.flush();

drawManageWindow();

}

 

}

Developer
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: Problem capturing index from item in array using list vs. drop down

This code doesn't even show that you are deleting anything from the List or its DataProvider, so it's hard to point to anything there as the direct cause.

I think if you learn to use the debugger and trace() calls, you'll sort this out on your own. You can dump the state of the various objects or components involved in each routine, including "before and after" views, and pinpoint the problem that way.

Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Developer
Posts: 231
Registered: ‎05-03-2011
My Device: PlayBook V1 and proud of it :-)
My Carrier: Legs

Re: Problem capturing index from item in array using list vs. drop down

In your showEntry function place a trace() statement and display the entryTitles index thats been selected. Then place a trace() statement in the deleteTrip() method also displaying the index. If these two are the same, then the code for deletion is wrong, if these values are different, then passing the index value is wrong (probably being populated from the wrong property.

Keep the Forum productive and useful for all. Click Kudos button if I've helped you. Select Solved to help everyone.

PlayBook qualifying app - Pandoras' Lights
Blog - CoCopia.co.uk Catch me on Twitter cocopia_apps
Contributor
Posts: 18
Registered: ‎02-24-2011
My Device: Not Specified

Re: Problem capturing index from item in array using list vs. drop down

I'll give it a shot when I get home tonight.  Thanks.

Contributor
Posts: 18
Registered: ‎02-24-2011
My Device: Not Specified

Re: Problem capturing index from item in array using list vs. drop down

Ok, using the list, the ITEM_CLICKED passes the correct index (index of 1) to showEntry, which basically writes out the value for the objects in the item that was clicked.

 

The deletetrip function captures an index of -1, which from what I read means that nothing was passed.  The delete button that calls the deletetrip function is in the same function as the list and the ListEvent.ITEM_CLICKED.  Since I am calling the showEntry function upon click, I guess I am unsure of how to pass that same index from the delete button to the deletetrip function.

 

I know with the dropdown menu, I would just pass entryTitles.selectedIndex and it worked, but for this type of list, selectedIndex doesn't seem to work.

 

Hopefully this clarifies things a little bit, or maybe I just cluttered it up more.

Developer
Posts: 231
Registered: ‎05-03-2011
My Device: PlayBook V1 and proud of it :-)
My Carrier: Legs

Re: Problem capturing index from item in array using list vs. drop down

Have a go at it this way,

 

When the showEntry method is called, store the index value in an internal var, then when the delete button is pressed check this value is greater than -1, if it is call the deletetrip function. I would popup a confirmation window first incase the user touched delete accidently.

Keep the Forum productive and useful for all. Click Kudos button if I've helped you. Select Solved to help everyone.

PlayBook qualifying app - Pandoras' Lights
Blog - CoCopia.co.uk Catch me on Twitter cocopia_apps
Contributor
Posts: 18
Registered: ‎02-24-2011
My Device: Not Specified

Re: Problem capturing index from item in array using list vs. drop down

See that's one of the issues.  Being new to this, I know how to pass the value of the index to the showEntry function (ListEvent.ITEM_CLICKED, then at showEntry is e.index), but within the same function where I am selecting the item from the list, I am not sure how to capture the current index.  With the dropdown list, I know it was dropdownname.selectedIndex.  For this list, I can't find what I think is the right property.

Developer
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: Problem capturing index from item in array using list vs. drop down

Try e.currentTarget.selectedIndex. The docs for the Event class can tell you more about the currentTarget property.

Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!