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
New Developer
tstark
Posts: 22
Registered: ‎12-20-2010
My Device: Not Specified

DropDown bug?

Hey, I am observing some weird behavior in my DropDown while dealing with multiple clicks on the same item. Just using a simple:

 

 

trace("DropDown Selection: " + myDropDown.selectedIndex);

 

 

to check the value of the index of the item selected (zero based, of course), this returns me the correct value the first time I click on the item and zero the second time, and so on repeating the actions.

 

What's worse is that if I use:

 

 

trace("DropDown ID: " + myDropDown.selectedItem.id);

 

 

where 'id" is the value that comes from a DataProvider associated to the DropDown, like:

 

 

myDropDown.dataProvider = new DataProvider( [
				{label:'Apples', id:'25'},
				{label:'Oranges', id:'31'}]};

 

I get the correct value the first time I click and null the second time, crashing the whole app! Has anyone observed something like that?

 

Thanks and Happy Holidays!

 

 

 

Developer
JRab
Posts: 2,462
Registered: ‎11-04-2010
My Device: Bold 9700

Re: DropDown bug?

hey,

 

thanks reporting the possible bug. im going to recreate it but just so i know exact steps are you setting up your data provider like that every time? and also what are you using as a listener function? and how is that set up? thanks!

J. Rab (Blog) (Twitter)
--
1. If you liked my post or found it useful please click on the thumbs up and provide a Like!
2. If my post solved your problem please click on the Accept as Solution button. Much appreciated!

Approved Apps: OnTrack | ssShots | Hangman
Developer
JRab
Posts: 2,462
Registered: ‎11-04-2010
My Device: Bold 9700

Re: DropDown bug?

hey,

 

ok so i recreated the bug and wow never noticed. its so obvious too. just to reiterate wat tstark stated, when you select the same item on the drop down list a second time it will give you the wrong selected item and selected index. you can run the following code to confirm it:

 

 

package
{
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.text.TextFieldAutoSize;
	
	import qnx.ui.buttons.LabelButton;
	import qnx.ui.data.DataProvider;
	import qnx.ui.events.DataProviderEvent;
	import qnx.ui.listClasses.CellRenderer;
	import qnx.ui.listClasses.DropDown;
	import qnx.ui.listClasses.List;
	import qnx.ui.text.Label;
	import qnx.ui.text.TextInput;
	
	
	[SWF(width="1024",height="600",backgroundColor="#E8E8E8",frameRate="30")]
	public class ListTests extends Sprite
	{
		private var myList:DropDown;
		private var myDataProvider:DataProvider;
		private var myArray:Array;
		private var newTextInput:TextInput;
		private var myBtn:LabelButton;
		
		
		public function ListTests()
		{
			super();
			
			// support autoOrients
			stage.align = StageAlign.TOP_LEFT;
			stage.scaleMode = StageScaleMode.NO_SCALE;
			
			myList = new DropDown();
			myArray = new Array();
			
			myArray.push({label:"2 Cups Onions"});
			myArray.push({label:"2 Cups Milk"});
			myArray.push({label:"2 Cups Water"});
			myArray.push({label:"2 Cups Garlic"});
			myArray.push({label:"2 Cups Peppercorn"});
			myArray.push({label:"2 Cups Breadcrumbs"});
			myArray.push({label:"2 Cups Sugar"});
			
			myDataProvider = new DataProvider(myArray);
			
			myList.dataProvider = myDataProvider;
			
			myList.setPosition(10,10);
			
			myList.width = 300;
			
			myList.addEventListener(Event.SELECT, myFunction);
			
			addChild(myList);
			
			newTextInput = new TextInput();
			newTextInput.setSize(300, 50);
			newTextInput.setPosition(360,10);
			
			addChild(newTextInput);
			
			myBtn = new LabelButton();
			myBtn.label = "Get the current selectedIndex";
			myBtn.setSize(250, 50);
			myBtn.setPosition(360, 70);
			
			myBtn.addEventListener(MouseEvent.CLICK, getSelectedIndex);
			
			addChild(myBtn);
			
		}
		public function myFunction(e:Event):void
		{
			//stores the wrong details about the selected item on the list when select
			trace("Selected item: " + e.target.selectedIndex +  ": " + myList.getItemAt(e.target.selectedIndex).label);
			
			trace("Current List of Items on List:");
			
			for(var i:int = 0; i<myList.dataProvider.length ; i++)
			{
				trace(i + ": " + myList.getItemAt(i).label);
			}
		}
		public function getSelectedIndex(e:MouseEvent):void
		{
			newTextInput.text = myList.selectedIndex.toString();
			
			//throws error when selecting the same item again
			
			//newTextInput.text = myList.selectedItem.label;
		}
		
	}
}

 

i'll look for a work around but that seems like a pretty bad bug to have to work around. ill keep you updated and great find tstark!

 

J. Rab (Blog) (Twitter)
--
1. If you liked my post or found it useful please click on the thumbs up and provide a Like!
2. If my post solved your problem please click on the Accept as Solution button. Much appreciated!

Approved Apps: OnTrack | ssShots | Hangman
New Developer
tstark
Posts: 22
Registered: ‎12-20-2010
My Device: Not Specified

Re: DropDown bug?

Hey JRab! Thank you for checking!

 

Yes, the setup of the DataProvider is always the same. As listener function I am using:

 

 

myDropDown.addEventListener(Event.SELECT, function():void{

	trace("ID: " + myDropDown.selectedItem.id);
        trace("Index: " + myDropDown.selectedIndex);
				
			});

 

 

I have also tried to setup the DataProvider just with the labels, without passing the extra 'id', then checking the myDropDown.selectedIndex and nothing changes, same alternate error on multiple clicks on the same item on the DB.

 

 

myDropDown.dataProvider = new DataProvider( [
				{label:'Apples'},
				{label:'Oranges'}] );

 

 

New Developer
tstark
Posts: 22
Registered: ‎12-20-2010
My Device: Not Specified

Re: DropDown bug?

Actually, it's a pretty bad bug, I agree with you JRab! The only workaround I found it's the following, not that elegant but it seems to work, at least for me...

 

 

myDropDown.addEventListener(Event.SELECT, function():void{

				var sel:String = myDropDown.selectedItem ? myDropDown.selectedItem.id: '';	
				
				if (sel != '') {
					
					trace("Valid value!");
					// Your code here...

				}
			});

 

Hope it helps and just let me know if you find some better way... Thanks!

 

Developer
JRab
Posts: 2,462
Registered: ‎11-04-2010
My Device: Bold 9700

Re: DropDown bug?

hey,

 

that works to catch the exception and prevent the user from seeing an error but unfortunately it doesnt fix the selecteditem value on the drop down. it stems from a poor structuring of the dataprovider on the list. when the user clicks on an item it rearranges things to account for the dropdown's function of showing hte selected item on top. or at least thats my theory lol.

 

in any case i submitted a bug into the Issue Tracker here:

 

https://www.blackberry.com/jira/browse/TABLET-36

(Must be logged in)

 

hope fully things get cleared up in the next release. ill keep you updated!

J. Rab (Blog) (Twitter)
--
1. If you liked my post or found it useful please click on the thumbs up and provide a Like!
2. If my post solved your problem please click on the Accept as Solution button. Much appreciated!

Approved Apps: OnTrack | ssShots | Hangman
New Developer
tstark
Posts: 22
Registered: ‎12-20-2010
My Device: Not Specified

Re: DropDown bug?

Yes, you are right. In order to assign the right value I would create a temp variable and assign the valid value there. The first time the user click, the correct value is assigned to the temp variable. If the user click a second time the same item nothing happens and the temp variable still holds the correct value of the selection. New values are assigned to the temp variable only when a different item is selected.

 

Thank you for submitting the bug! I tried tonight but for some reason the system was not working...maybe too late (for both)... :smileyhappy:

Developer
JRab
Posts: 2,462
Registered: ‎11-04-2010
My Device: Bold 9700

Re: DropDown bug?

[ Edited ]

hey,

 

back again. i hate things you cant work around hah. anyways i found a work around for this that should do the job. what we needed to do is "reset" the value of the selectedIndex to the previous value whenever its value goes null. so i used your idea and added a saftey net to it. the code is as follows:

 

ListTests.as:

 

 

package
{
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.text.TextFieldAutoSize;

import qnx.ui.buttons.LabelButton;
import qnx.ui.data.DataProvider;
import qnx.ui.events.DataProviderEvent;
import qnx.ui.listClasses.CellRenderer;
import qnx.ui.listClasses.DropDown;
import qnx.ui.listClasses.List;
import qnx.ui.text.Label;
import qnx.ui.text.TextInput;


[SWF(width="1024",height="600",backgroundColor="#E8E8E8",frameRate="30")]
public class ListTests extends Sprite
{
private var myList:DropDown;
private var myDataProvider:DataProvider;
private var myArray:Array;
private var newTextInput:TextInput;
private var myBtn:LabelButton;

private var lastSelectedIndex:int;

public function ListTests()
{
super();

// support autoOrients
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;

myList = new DropDown();
myArray = new Array();

myArray.push({label:"2 Cups Onions"});
myArray.push({label:"2 Cups Milk"});
myArray.push({label:"2 Cups Water"});
myArray.push({label:"2 Cups Garlic (Crushed)"});
myArray.push({label:"2 Cups Peppercorn"});
myArray.push({label:"2 Cups Board"});
myArray.push({label:"2 Cups Red"});

myDataProvider = new DataProvider(myArray);

myList.dataProvider = myDataProvider;

myList.setPosition(10,10);
myList.width = 300;
myList.selectedIndex = 0;

myList.addEventListener(Event.SELECT, myFunction);

addChild(myList);

newTextInput = new TextInput();
newTextInput.setSize(300, 50);
newTextInput.setPosition(360,10);

addChild(newTextInput);

myBtn = new LabelButton();
myBtn.label = "Get the current selectedIndex";
myBtn.setSize(250, 50);
myBtn.setPosition(360, 70);

myBtn.addEventListener(MouseEvent.CLICK, getSelectedIndex);

addChild(myBtn);

}
public function myFunction(e:Event):void
{
if (!e.target.selectedItem)
{
e.target.selectedIndex = lastSelectedIndex;
return;
}


trace("Selected item: " + e.target.selectedIndex + ": " + myList.getItemAt(e.target.selectedIndex).label);

trace("Current List of Items on List:");

for(var i:int = 0; i<myList.dataProvider.length ; i++)
{
trace(i + ": " + myList.getItemAt(i).label);
}

lastSelectedIndex = e.target.selectedIndex;
}
public function getSelectedIndex(e:MouseEvent):void
{
newTextInput.text = myList.selectedItem.label;
}

}
}

 

this is should plug the hole until things get fixed. hope this helps. good luck!

 

Edit: Ah you beat me to it tstark! but yeah you have the right idea. the above code implments it :smileyhappy:

 

and yeah the issue tracker was acting weird. made me change my password even though it met the criteria which is weird.

J. Rab (Blog) (Twitter)
--
1. If you liked my post or found it useful please click on the thumbs up and provide a Like!
2. If my post solved your problem please click on the Accept as Solution button. Much appreciated!

Approved Apps: OnTrack | ssShots | Hangman
New Developer
tstark
Posts: 22
Registered: ‎12-20-2010
My Device: Not Specified

Re: DropDown bug?

lol

 

Your version is very well documented and explained so I will gladly share the 'honor' with you. :smileyhappy:

 

Thanks again for checking on it!