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
lynnjswing
Posts: 3
Registered: ‎01-21-2011
My Device: Storm2
Accepted Solution

Missing something in my Custom Input Field?

Well, so far I've been able to learn pretty much what I've needed to know from lurking, until today.  I've created a simple LabelTextInput so I can tie a label to my textInput (I didn't miss a simpler way to do this did I?).  The code for that is below and it works, but the problem I'm having is when I try to add to my container.  The boxes get stacked on top of one another (Fig. 1).  Normal TextInput boxes get added as I would expect (Fig. 2).  Did I miss some essential override?  Thanks.

 

LabelTextInput.as

 

package
{
	import qnx.ui.core.UIComponent;
	import qnx.ui.text.Label;
	import qnx.ui.text.TextInput;
	
	public class LabelTextInput extends UIComponent 
	{
		private var _label:Label;
		private var _input:TextInput;
		
		public function LabelTextInput() 
		{
		}
		
		override protected function draw():void 
		{
			_label = new Label();
			_label.selectable = false;
			
			_input = new TextInput();
			_input.x = _label.width + 5;
			
			addChild(_label);
			addChild(_input);			
		}
		
		public function get labelText():String
		{
			return _label.text;
		}
		public function set labelText(text:String):void 
		{
			_label.text = text;
			_input.x = _label.width + 5;
		}
		public function get inputText():String
		{
			return _input.text;
		}
		public function set inputText(text:String):void 
		{
			_input.text = text;
		}
	}

}

 

Somewhat Psuedo Code where I am adding the items to my "View" which extends Sprite:

 

	// create subcontainer on the left side of the screen
	mySubLeft = new Container();
        mySubLeft.margins = Vector.<Number>([5, 5, 5, 5]);            
        mySubLeft.size = 50;
        mySubLeft.debugColor = 0xFF3300;
        mySubLeft.sizeUnit = SizeUnit.PERCENT;
        mySubLeft.flow = ContainerFlow.VERTICAL;
        mySubLeft.align = ContainerAlign.NEAR;
        mySubLeft.padding = 5;

	txtSurname = new LabelTextInput();
	txtSurname.labelText = "Surname";
	mySubLeft.addChild(txtSurname);
			
	txtGivenName = new LabelTextInput();
	txtGivenName.labelText = "Given Name";
	mySubLeft.addChild(txtGivenName);
			
	txtBirthDate = new LabelTextInput();
	txtBirthDate.labelText = "Birth Date";
	mySubLeft.addChild(txtBirthDate);

	txtDeathDate = new LabelTextInput();
	txtDeathDate.labelText = "Death Date";
	mySubLeft.addChild(txtDeathDate);
			
	var dp:DataProvider = new DataProvider();
	var arr:Array = new Array([ { data:"M", label:"Male" }, { data:"F", label:"Female" } ]);
	dp.setItems(arr[0]);
	cboGender = new DropDown();
	cboGender.dataProvider = dp;
	cboGender.rowCount = dp.length;
	mySubLeft.addChild(cboGender);

 

 

Fig. 1

 

PlayBook.png

 

Fig.2

 

PlayBook2.png

 

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

Re: Missing something in my Custom Input Field?

hey,

 

try setting the containment of your custom LabelTextInput object to Containment.CONTAINED and see if that works:

 

 

 

// create subcontainer on the left side of the screen
mySubLeft = new Container();
mySubLeft.margins = Vector.<Number>([5, 5, 5, 5]);
mySubLeft.size = 50;
mySubLeft.debugColor = 0xFF3300;
mySubLeft.sizeUnit = SizeUnit.PERCENT;
mySubLeft.flow = ContainerFlow.VERTICAL;
mySubLeft.align = ContainerAlign.NEAR;
mySubLeft.padding = 5;

txtSurname = new LabelTextInput();
txtSurname.labelText = "Surname";
txtSurname.containment = Containment.CONTAINED;
mySubLeft.addChild(txtSurname);

txtGivenName = new LabelTextInput();
txtGivenName.labelText = "Given Name";
txtSurname.containment = Containment.CONTAINED;
mySubLeft.addChild(txtGivenName);

txtBirthDate = new LabelTextInput();
txtBirthDate.labelText = "Birth Date";
txtSurname.containment = Containment.CONTAINED;
mySubLeft.addChild(txtBirthDate);

txtDeathDate = new LabelTextInput();
txtDeathDate.labelText = "Death Date";
txtSurname.containment = Containment.CONTAINED;
mySubLeft.addChild(txtDeathDate);

var dp:DataProvider = new DataProvider();
var arr:Array = new Array([ { data:"M", label:"Male" }, { data:"F", label:"Female" } ]);
dp.setItems(arr[0]);
cboGender = new DropDown();
cboGender.dataProvider = dp;
cboGender.rowCount = dp.length;
mySubLeft.addChild(cboGender);

 

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 Contributor
lynnjswing
Posts: 3
Registered: ‎01-21-2011
My Device: Storm2

Re: Missing something in my Custom Input Field?

Unfortunately, that didn't work.  Thanks for the suggestion. - Lynn

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

Re: Missing something in my Custom Input Field?

ah alrite sorry about that, i also noticed that there werent any sizes being set for your objects. sometimes containers need that data too. try the following code:

 

 

// create subcontainer on the left side of the screen
mySubLeft = new Container();
mySubLeft.margins = Vector.<Number>([5, 5, 5, 5]);            
mySubLeft.size = 50;
mySubLeft.debugColor = 0xFF3300;
mySubLeft.sizeUnit = SizeUnit.PERCENT;
mySubLeft.flow = ContainerFlow.VERTICAL;
mySubLeft.align = ContainerAlign.NEAR;
mySubLeft.padding = 5;

txtSurname = new LabelTextInput();
txtSurname.labelText = "Surname";
txtSurname.containment = Containment.CONTAINED;
txtSurname.setSize(300,60);
mySubLeft.addChild(txtSurname);

txtGivenName = new LabelTextInput();
txtGivenName.labelText = "Given Name";
txtGivenName.containment = Containment.CONTAINED;
txtGivenName.setSize(300,60);
mySubLeft.addChild(txtGivenName);

txtBirthDate = new LabelTextInput();
txtBirthDate.labelText = "Birth Date";
txtBirthDate.containment = Containment.CONTAINED;
txtBirthDate.setSize(300,60);
mySubLeft.addChild(txtBirthDate);

txtDeathDate = new LabelTextInput();
txtDeathDate.labelText = "Death Date";
txtDeathDate.containment = Containment.CONTAINED;
txtDeathDate.setSize(300,60);
mySubLeft.addChild(txtDeathDate);

var dp:DataProvider = new DataProvider();
var arr:Array = new Array([ { data:"M", label:"Male" }, { data:"F", label:"Female" } ]);
dp.setItems(arr[0]);
cboGender = new DropDown();
cboGender.dataProvider = dp;
cboGender.rowCount = dp.length;
mySubLeft.addChild(cboGender);

 

let me know how it turns out. 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 Contributor
lynnjswing
Posts: 3
Registered: ‎01-21-2011
My Device: Storm2

Re: Missing something in my Custom Input Field?

Thanks so much!  I was concerned that hardcoding the values would cause issues in dealing with screen orientation, but the reference to Containment.CONTAINED made me realize that I can set a larger number than I need for width and the container will keep it from spreading outside of the container (duh).

Please use plain text.