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: 16
Registered: ‎03-12-2011
My Device: BlackBerry Playbook
My Carrier: None

Re: The GUI of my app can't display properly.

Both don't work unfortunately....is it really that hard to get what user inputs and converts it to number ?

 

Thank you very much for your help

Developer
Posts: 45
Registered: ‎01-14-2011
My Device: Not Specified

Re: The GUI of my app can't display properly.

I think the biggest problem you've got at the moment is you are defining each input twice. Once "globally" as a public variable, and then again inside your BMI function.

 

 i.e.

 

public var resultvalue:TextInput = null;

 

....

var resultvalue:TextInput = new TextInput();

So when you try to get a handle on the values in calcBMI it's looking at different (the public) ones to those (the local) you actually added to the stage.

I've corrected the code for you, and tweaked it a little, and have tested it in my 0.9.3 simulator and it works. Hopefully this should be enough to get you past the starting blocks.

package
{
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.events.*;
	import flash.text.TextField;
	
	import qnx.ui.buttons.LabelButton;
	import qnx.ui.text.TextInput;
	
	[SWF(width="1024", height="600", backgroundColor="#cccccc", frameRate="30")]
	
	
	
	public class BMI extends Sprite
	{
		
		public var weightvalue:TextInput = null;
		public var heightvalue:TextInput = null;
		public var resultvalue:TextInput = null;
		
		public function BMI()
		{
			weightvalue = new TextInput();
			weightvalue.x = 10;
			weightvalue.y = 40;
			weightvalue.text = "Enter your weight here in kilograms";
			
			heightvalue = new TextInput();
			heightvalue.x = 10;
			heightvalue.y = 80;
			heightvalue.text = "Enter your height here in meters";
			
			var calcButton:LabelButton = new LabelButton();
			calcButton.label = "Calculate your BMI";
			calcButton.addEventListener(MouseEvent.CLICK, calcBMI);
			
			calcButton.x = 30;
			calcButton.y = 150;
			
			
			var closeButton:LabelButton = new LabelButton();
			closeButton.label = "Close";  
			closeButton.addEventListener(MouseEvent.CLICK, closeWindow);
			closeButton.x = 200;
			closeButton.y = 150;
			
			resultvalue = new TextInput();
			resultvalue.x = 100;
			resultvalue.y = 250;
			
			
			addChild(weightvalue);
			addChild(heightvalue);
			addChild(resultvalue);
			addChild(calcButton);
			addChild(closeButton);
			
			stage.nativeWindow.visible = true;
			
			
		}
		public function closeWindow(event:MouseEvent):void{
			stage.nativeWindow.close();
		}
		public function calcBMI(event:MouseEvent) :void
		{
			var weight:String = this.weightvalue.text;
			var height:String = this.heightvalue.text;
			var num_bmi:Number = Number(weight)/Math.pow(Number(height),2);
			num_bmi = Math.round(num_bmi*100) / 100;
			resultvalue.text = "Your BMI is " + String(num_bmi);
		}
		
	}
	
}

 

Highlighted
Contributor
Posts: 16
Registered: ‎03-12-2011
My Device: BlackBerry Playbook
My Carrier: None

Re: The GUI of my app can't display properly.

Thank you very much for your help !