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 Contributor
dmkp
Posts: 2
Registered: ‎01-09-2011
My Device: Not Specified
Accepted Solution

ListEvent.ITEM_CLICKED doesn't fire

Hello all,

 

This is my first post so first off thanks to everyone in advance for their help! I'm working on an application for the Playbook and so far things have been going quite well. Unfortunately I've hit a snag that I've been struggling with for the past few days. The problem I am having is that the the ListEvent.ITEM_CLICKED event doesn't seem to fire when the list is added to a sprite that isn't the main application sprite. If I add the same list code to the main sprite everything works correctly. I've created a demo app to demonstrate what I am doing and the result:

 

ListTest.as - Application entry point. 

 

 

package
{
	import flash.display.Screen;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	import caurina.transitions.Tweener;
	
	import qnx.ui.buttons.LabelButton;
	import qnx.ui.data.DataProvider;
	import qnx.ui.theme.ThemeGlobals;
	
	[SWF(width="1024", height="600", backgroundColor="#666666", frameRate="30")]
	public class ListTest extends Sprite
	{
		public var button:LabelButton;
		public var listScreen:Screen1;

		public function ListTest()
		{
			super();
			ThemeGlobals.currentTheme = ThemeGlobals.BLACK;
			
			button = new LabelButton();
			button.label = "Switch Screen";
			button.addEventListener(MouseEvent.CLICK, switchScreen);
			
			addChild(button);
			
			this.stage.nativeWindow.visible = true;
				
		}
		
		public function switchScreen(e:Event):void
		{
			listScreen = new Screen1();
			addChild(listScreen);
			Tweener.addTween(this, {x:0, y:-600, time:.3, transition:"linear"});
		}
	}
}

 Screen1.as - The second sprite that is animated in when the "Switch Screen" button is clicked.

 

 

package
{
	import flash.display.Sprite;
	
	import qnx.ui.data.DataProvider;
	import qnx.ui.events.ListEvent;
	import qnx.ui.listClasses.List;
	import qnx.ui.listClasses.ListSelectionMode;
	import qnx.ui.theme.ThemeGlobals;

	public class Screen1 extends Sprite
	{
		public var testList:List;
		public var ar:Array = [ { label : 'bob', id:1234 }, { label : 'fred', id: 4567 } ];
		
		public function Screen1()
		{
			super();
			this.y = 600;
			ThemeGlobals.currentTheme = ThemeGlobals.BLACK;
			
			testList = new List();
			testList.width = 500;
			testList.height = 500;
			testList.x = 200;
			testList.selectionMode = ListSelectionMode.SINGLE;
			testList.dataProvider = new DataProvider(ar);
			testList.addEventListener(ListEvent.ITEM_CLICKED, onClick);
			
			addChild(testList);
		}
		
		public function onClick(e:ListEvent):void
		{
			trace("onClick called from ListeEvent.ITEM_CLICKED event");
		}
	}
}

 If I debug the app "onClick" never fires. I'm hoping it's something simple but as I mentioned this only happens with the list is a child of a Sprite that is not the main application sprite.

 

 

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

Re: ListEvent.ITEM_CLICKED doesn't fire

hey dmkp,

 

i just ran and tested it and it had me stumped for a while lol. but soon after i removed a few lines of coding (mainly the tweening effects and everything related to it) and it solved the click issue. so my theory is based on the initial values's of the second sprites y value, its throwing of the way the list functions in the second sprite. i noticed the y is at a set position (600) when the list is created but after its actaulyl on screen its y changes to -600 (what is relative to the list). i would would find an alternate way of doing the tween so it doesnt conflict with the list.

 

here is the corrected code:

 

ListTest.as:

 

 

package
{
import flash.display.Screen;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;

import caurina.transitions.Tweener;

import qnx.ui.buttons.LabelButton;
import qnx.ui.data.DataProvider;
import qnx.ui.theme.ThemeGlobals;

[SWF(width="1024", height="600", backgroundColor="#666666", frameRate="30")]
public class ListTest extends Sprite
{
public var button:LabelButton;
public var listScreen:Screen1;

public function ListTest()
{
super();
ThemeGlobals.currentTheme = ThemeGlobals.BLACK;

button = new LabelButton();
button.label = "Switch Screen";
button.addEventListener(MouseEvent.CLICK, switchScreen);

addChild(button);

this.stage.nativeWindow.visible = true;

}

public function switchScreen(e:Event):void
{
listScreen = new Screen1();
addChild(listScreen);
//Tweener.addTween(this, {x:0, y:-600, time:.3, transition:"linear"});
}
}
}

 

 

Screen1.as:

 

 

package
{
import flash.display.Sprite;

import qnx.ui.data.DataProvider;
import qnx.ui.events.ListEvent;
import qnx.ui.listClasses.List;
import qnx.ui.listClasses.ListSelectionMode;
import qnx.ui.theme.ThemeGlobals;

public class Screen1 extends Sprite
{
public var testList:List;
public var ar:Array = [ { label : 'bob', id:1234 }, { label : 'fred', id: 4567 } ];

public function Screen1()
{
super();
//this.y = 600;
ThemeGlobals.currentTheme = ThemeGlobals.BLACK;

testList = new List();
testList.width = 500;
testList.height = 500;
testList.x = 200;
testList.selectionMode = ListSelectionMode.SINGLE;
testList.dataProvider = new DataProvider(ar);
testList.addEventListener(ListEvent.ITEM_CLICKED, onClick);

addChild(testList);
}

public function onClick(e:ListEvent):void
{
trace("onClick called from ListeEvent.ITEM_CLICKED event");
}
}
}

 

hope that helps! good luck!

 

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: ListEvent.ITEM_CLICKED doesn't fire

hey,

 

just an update to get the same effect as you initially had without that "boring" workaround i gave in my previous post, run the following code. This time the Screen1 class will have the this.y = 600 as you initially had it. So that entire file stays the same. The only thing we ar going to change is the switchScreen function in your main application. Instead of tweening the main application, we are going to tween just the Screen1 object.

 

ListTest.as (changes in bold):

 

 

package
{
import flash.display.Screen;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;

import caurina.transitions.Tweener;

import qnx.ui.buttons.LabelButton;
import qnx.ui.data.DataProvider;
import qnx.ui.theme.ThemeGlobals;

[SWF(width="1024", height="600", backgroundColor="#666666", frameRate="30")]
public class ListTest extends Sprite
{
public var button:LabelButton;
public var listScreen:Screen1;

public function ListTest()
{
super();
ThemeGlobals.currentTheme = ThemeGlobals.BLACK;

button = new LabelButton();
button.label = "Switch Screen";
button.addEventListener(MouseEvent.CLICK, switchScreen);

addChild(button);

this.stage.nativeWindow.visible = true;

}

public function switchScreen(e:Event):void
{
listScreen = new Screen1();
addChild(listScreen);
removeChild(button);
Tweener.addTween(listScreen, {x:0, y:0, time:.3, transition:"linear"});
}
}
}

 

 

Screen1.as (original):

 

 

package
{
	import flash.display.Sprite;
	
	import qnx.ui.data.DataProvider;
	import qnx.ui.events.ListEvent;
	import qnx.ui.listClasses.List;
	import qnx.ui.listClasses.ListSelectionMode;
	import qnx.ui.theme.ThemeGlobals;
	
	public class Screen1 extends Sprite
	{
		public var testList:List;
		public var ar:Array = [ { label : 'bob', id:1234 }, { label : 'fred', id: 4567 } ];
		
		public function Screen1()
		{
			super();
			this.y = 600;
			ThemeGlobals.currentTheme = ThemeGlobals.BLACK;
			
			testList = new List();
			testList.width = 500;
			testList.height = 500;
			testList.x = 200;
			testList.selectionMode = ListSelectionMode.SINGLE;
			testList.dataProvider = new DataProvider(ar);
			testList.addEventListener(ListEvent.ITEM_CLICKED, onClick);
			
			addChild(testList);
		}
		
		public function onClick(e:ListEvent):void
		{
			trace("onClick called from ListeEvent.ITEM_CLICKED event");
		}
	}
}

 

hope that helps some more. good luck!

 

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 Contributor
dmkp
Posts: 2
Registered: ‎01-09-2011
My Device: Not Specified

Re: ListEvent.ITEM_CLICKED doesn't fire

Thanks JRab! 

 

Now that you've isolated it to the tweening code and releated properties it makes sense. I'll have to look into other options to achieve what I'm after. The second option you provided is pretty close.