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
BrianMcPeek
Posts: 74
Registered: ‎02-09-2011
My Device: Torch 9850/64GB PlayBook
My Carrier: Verizon
Accepted Solution

Picker List Component Not Working

 

Hello I'm kind of new to using Flash Builder and I'm trying to create a simple Picker.  I cant seem to get it to work at all.  It doesnt show up in Design mode or in the simulator.  I am getting errors when i create the picker gameList:smileytongue:icker.  All the properties for the picker that I'm trying to set are giving me Error 1120: Access of Undefined Property gameList.  I really have no ideea what I am doing wrong.  I tried looking at many examples, even the one in the Blackberry Tablet API Reference, and I still get errors.  Also the dataprovider property says undefined property PickProvider(), and the event listeners all also say access of undefined property pickerSelect. I tried making the Picker variable public, retyping everything, renaming the variable, I dont know what else to do! Any help?
<fx:smileyfrustrated:cript>
  <![CDATA[
  import qnx.dialog.AlertDialog;
  import qnx.dialog.BaseDialog;
  import qnx.dialog.DialogSize;
  import qnx.display.IowWindow;
  import qnx.ui.data.DataProvider;
  import qnx.ui.data.IDataProvider;
  import qnx.ui.picker.Picker;

  private function PickProvider():IDataProvider{

  var game:Array = new Array();

  game.push({label: "301"});
  game.push({label: "401"});
  game.push({label: "501"});
  game.push({label: "601"});
  game.push({label: "701"});
  game.push({label: "801"});
  game.push({label: "901"});

  var gData:Array = new Array();

  gData.push(new DataProvider(game));

  return new DataProvider(gData);
  }

  var gameList:smileytongue:icker = new Picker();

  gameList.dataProvider = PickProvider();
  gameList.rowCount = 3;
  gameList.setPosition(450, 450);
  gameList.height = 40;
  gameList.width = 125;
  gameList.selectedIndices = 2;
  gameList.addEventListener(Event.OPEN, pickerSelect, false, 0, true);
  gameList.addEventListener(Event.SELECT, pickerSelect, false, 0, true);
  gameList.addEventListener(Event.CLOSE, pickerSelect, false, 0, true);

  private function pickerSelect(event:Event):void{
  trace(event.type);
  if (event.type == Event.CLOSE){
  trace(gameList.selectedItems);
  Tscore1.text = gameList.selectedItems.toString();
  Tscore2.text = gameList.selectedItems.toString();
  }
  }

 

Please use plain text.
Developer
jtegen
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10
My Carrier: Verizon

Re: Picker List Component Not Working

I'm not seeing where you are adding the control to the display list with addChild().

 

Also, selectedIndicies takes an array.

Please use plain text.
New Developer
BrianMcPeek
Posts: 74
Registered: ‎02-09-2011
My Device: Torch 9850/64GB PlayBook
My Carrier: Verizon

Re: Picker List Component Not Working

I added the addChild method underneath all the Picker properties and it still says access of undefined property gameList.  Also any methods that are involved with the picker say call to possibly undefined method....addChild, pickerSelect etc.

Please use plain text.
Developer
jtegen
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10
My Carrier: Verizon

Re: Picker List Component Not Working

Maybe it is the structure.

 

Your variable is not scoped properly.

 

Try:

 

private var gameList : Picker = new Picker();

 

In a function that gets called when the object is initialized, then set the attributes.

 

private function init( event : Event ) : void

{

  this.gameList.dataProvider = this.PickProvider();

  ...

}

Please use plain text.
Developer
JRab
Posts: 2,462
Registered: ‎11-04-2010
My Device: Bold 9700

Re: Picker List Component Not Working

if im not mistaken (probably am hah) you cant use "visual" classes from the QNX API library. you can only use non-visual stuff like dataproviders, etc. so its probably going to happen to anything that you can see on screen that specific to the QNX api such as lists, buttons, etc. if you are going to use Flex you are going to have to use the spark / mx libraries.

 

that being said i think is saw a post / blog (renaun) about using a "hybrid" library. but i dont know if its out dated or not. search for "qnx mxml" and see what pops up. 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
Please use plain text.
New Developer
BrianMcPeek
Posts: 74
Registered: ‎02-09-2011
My Device: Torch 9850/64GB PlayBook
My Carrier: Verizon

Re: Picker List Component Not Working

Now my code looks exactly like this...

 

All the errors went away, and it seems to compile fine, no warnings, errors, anything.  but now when the creationComplete calls the setPicker function i get an error at the addChild method inside the function.  it halts the application and says addChild() is not available in this class. Instead, use addElement() or modify the skin, if you have one.  if i change it to addElement(gameList), then when i save it it says Error 1067: implicit coercion of a value type Picker to an unrelated type IVisualElement.

Any Ideas??? I'm at such a loss!!!

 

 

 

<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009
   xmlns:s="library://ns.adobe.com/flex/spark" 
   xmlns:mx="library://ns.adobe.com/flex/mx"
   xmlns:qnx="library://ns.adobe.com/flex/qnx"
   width= "1024" height="600" 
   xmlns:listClasses="qnx.ui.listClasses.*" creationComplete="setPicker()">

 <fx:smileyvery-happy:eclarations>
 </fx:smileyvery-happy:eclarations>

 <fx:smileyfrustrated:cript>
 <![CDATA[

 import qnx.dialog.AlertDialog;
 import qnx.dialog.BaseDialog;
 import qnx.dialog.DialogSize;
 import qnx.display.IowWindow;
 import qnx.ui.data.DataProvider;
 import qnx.ui.data.IDataProvider;
 import qnx.ui.picker.Picker;

 private function PickProvider():IDataProvider{
 var game:Array = new Array();
 game.push({label: "301"});
 game.push({label: "401"});
 game.push({label: "501"});
 game.push({label: "601"});
 game.push({label: "701"});
 game.push({label: "801"});
 game.push({label: "901"});
 var gData:Array = new Array();
 gData.push(new DataProvider(game));
 return new DataProvider(gData);
 }

 private var gameList:smileytongue:icker = new Picker();

 private function setPicker():void{
 gameList.dataProvider = PickProvider();
 gameList.rowCount = 3;
 gameList.setPosition(650, 450);
 gameList.height = 40;
 gameList.width = 125;
 gameList.addEventListener(Event.OPEN, pickerSelect, false, 0, true);
 gameList.addEventListener(Event.SELECT, pickerSelect, false, 0, true);
 gameList.addEventListener(Event.CLOSE, pickerSelect, false, 0, true);
 addChild(gameList);
 }

 private function pickerSelect(event:Event):void{
 trace(event.type);
 if (event.type == Event.CLOSE){
 trace(gameList.selectedItems);
 Tscore1.text = gameList.selectedItems.toString();
 Tscore2.text = gameList.selectedItems.toString();
 }

 }

 

Please use plain text.
Developer
billfoust
Posts: 382
Registered: ‎05-19-2008
My Device: BlackBerry Torch
My Carrier: AT&T

Re: Picker List Component Not Working

It looks like you are creating your class member as "gameListPicker" but inside setPicker method, you are using the name "gameList".

 

Adobe AIR, like JavaScript, is not a strongly typed language, so the compiler won't fail on things like this. I think the object "gameList" is being implicitely constructed as an anonymous type the first time the propery is accessed.

 

Bill

Bill
-------------------------------------------
Check out my book on BlackBerry Development for Java.
And my other really really old book
My Apps: FlashKids
Please use plain text.
New Developer
BrianMcPeek
Posts: 74
Registered: ‎02-09-2011
My Device: Torch 9850/64GB PlayBook
My Carrier: Verizon

Re: Picker List Component Not Working

my apologies, the variable gameList should look like this    

 

private var gameList : Picker = new Picker();

 

the forum puts that smiley in after i post it because its the letter p and a colon

 

so i he type does get set as a picker named gameList.  After it starts to load the app it hangs on the addChild(gameList) line saying that addChild cant be used in this class to use addElement instead, but addElement throws an error when i compile the app because var type Picker is not an IVisualElement so it says implicit coercion of value type picker to unrelated type IVisualElement. i have no idea why this is happening.

 

Please use plain text.
Developer
JRab
Posts: 2,462
Registered: ‎11-04-2010
My Device: Bold 9700

Re: Picker List Component Not Working

Flex and AS3 have two different setups. you can interchange their non-visual classes but you cannot use their display objects interchangebly without using a workaround and finding a good middle ground. i think thats the problem you are running into. the qnx classes were compiled against the AIR sdk not flex. theres a good chance if you try to use any of the QNX display objects in flex, they will fail just as you saw this one fail. also as you found you flex does not use the addChild() method like in strict as3. the equivelent is using hte addElement() method.

 

here is a blog post regarding the work around. bear in mind that the swc file is old and may not contain updated sdk material. but it'll explain a few things:

 

http://renaun.com/blog/2010/12/using-mxml-with-qnx-ui-components-for-the-playbook/

 

you will have to use a work around such as the one described in the link or use strictly flex (mxml) type display objects in your flex projects. if you want to use the qnx display components your best bet will be to use strictly as3 in your project. hope that sheds some light. 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
Please use plain text.
Developer
JRab
Posts: 2,462
Registered: ‎11-04-2010
My Device: Bold 9700

Re: Picker List Component Not Working

hey Brian,

 

just an update to your issue. there was a post today showing an easy work around to your problem. it seems my reply above is premature and i didnt look into it as much as i could have.

 

based on information from this thread:

 

http://supportforums.blackberry.com/t5/Tablet-OS-SDK-for-Adobe-AIR/ToggleSwitch-in-Flex/m-p/797353/h...

 

i was able to put together a sample application showing you how to make the picker work with your flex project:

 

FlexTestHome.mxml:

 

 

<?xml version="1.0" encoding="utf-8"?>
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
title="Home" creationComplete="init()" xmlns:mx="library://ns.adobe.com/flex/mx">
<fx:Script>
<![CDATA[
import qnx.ui.data.DataProvider;
import qnx.ui.picker.Picker;

private function init():void
{
// Create three arrays to handle days, months, years.

var arrDay:Array=[];
var arrMonth:Array=[];
var arrYear:Array=[];

// Populate the month array and create the
// day DataProvider

for (var i:int=1; i<32; i++) {
arrDay.push({label: i.toString()});
}

var dayDP:DataProvider=new DataProvider(arrDay);


// Populate and month array and create the month
// DataProvider

arrMonth.push({label: "January"});
arrMonth.push({label: "February"});
arrMonth.push({label: "March"});
arrMonth.push({label: "April"});
arrMonth.push({label: "May"});
arrMonth.push({label: "June"});
arrMonth.push({label: "July"});
arrMonth.push({label: "August"});
arrMonth.push({label: "September"});
arrMonth.push({label: "October"});
arrMonth.push({label: "November"});
arrMonth.push({label: "December"});

var monthDP:DataProvider=new DataProvider(arrMonth);

// Create the year DataProvider

for (var l:int=1900; l<2011; l++) {
arrYear.push({label: l.toString()});
}

var yearDP:DataProvider=new DataProvider(arrYear);

// Add the day, month and year DataProviders to the main
// array

var dpp:Array = new Array();

dpp.push(dayDP);
dpp.push(monthDP);
dpp.push(yearDP);

// Create the picker and add the main DataProvider

var picker:Picker = new Picker();

picker.width=400;
picker.height=50;
picker.x=300;
picker.y=200;
picker.dataProvider=new DataProvider(dpp);
pickerContainer.addChild(picker);


// To customize column widths,
// all widths are added up and then used for
// a ratio against the component set width

picker.setListWidth(0,100);
picker.setListWidth(1,300);
picker.setListWidth(2,200);

// Set to Jan 1, 2010

picker.selectedIndices=[0,0,110];

// Add listeners for open, close and select events

picker.addEventListener(Event.OPEN,handleOpen);
picker.addEventListener(Event.CLOSE,handleClose);
picker.addEventListener(Event.SELECT,handleSelect);

// A simple function that displays currently selected
// item information in the console.

traceItems();

function traceItems():void
{
for (var j:int = 0; j <picker.selectedItems.length; j++) {
trace("Picker.selectedItems " +picker.selectedItems[j].label);
}
trace("Picker.selectedIndices "+picker.selectedIndices);
trace("Picker.data "+picker.data);
}
function handleSelect(e:Event):void {
traceItems();
}

function handleOpen(e:Event):void {
trace("Picker.open event captured");
}
function handleClose(e:Event):void {
trace("Picker.close event captured");
}

}

]]>
</fx:Script>

<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<mx:UIComponent id="pickerContainer" x="10" y="10" />
</s:View>

 

 

I used the picker example from this page of the QNX docs:

 

http://www.blackberry.com/developers/docs/airapi/1.0.0/qnx/ui/picker/Picker.html

 

the two lines that you should focus on are:

 

pickerContainer.addChild(picker);

and

 

	<mx:UIComponent id="pickerContainer" x="10" y="10" />

 

so you need a UIComponent "container" and just add your picker as a child to that and you should be golden! good luck and let me know how it works out!

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
Please use plain text.