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

The GUI of my app can't display properly.

Basically, I want to have two textfields for the users to enter numerical values and do a calculation; however, the following code cannot run in the simulator (everything is blank). I want to know what is wrong in the following code. Thank you very much for help in advance.

 

package
{
 import flash.display.Sprite;
 import flash.events.MouseEvent;
 import flash.geom.Rectangle;
 import flash.text.TextField;
 
 import qnx.media.QNXStageWebView;
 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;
  private var webView:QNXStageWebView = null;
  public function BMI()
  {
   var weightvalue:TextInput = new TextInput();
   weightvalue.x = 10;
   weightvalue.y = 40;
   weightvalue.text = "Enter your weight here in kilograms";
   
   var heightvalue:TextInput = 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 = 130;
   
   
   var closeButton:LabelButton = new LabelButton();
   closeButton.label = "Close";  
   closeButton.addEventListener(MouseEvent.CLICK, closeWindow);
   closeButton.x = 200;
   closeButton.y = 10;
   
   addChild(weightvalue);
   addChild(heightvalue);
   addChild(calcButton);
   addChild(closeButton);
   
   stage.nativeWindow.visible = true;
   
   var text:TextField = new TextField();
   text.text = "BMI Calculator";
   text.width = stage.stageWidth;
   text.height = stage.stageHeight;
   var format:TextFormat = new TextFormat();
   format.font = "Comic Sans MS"
   format.size = 24;
   text.setTextFormat(format);
   addChild(text);
   
   
   
   
   
  }
  private function closeWindow(event:MouseEvent):void{
   stage.nativeWindow.close();
  }

 
 }
 
}

Developer
Posts: 119
Registered: ‎03-10-2010
My Device: Bold 9000
My Carrier: Rogers

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

There are few syntax errors on your code. If you're using FlashBuilder, check always the "Problems" window at the bottom of your IDE. It will show the errors.

 

I can point few here though:

 

public var weightvalue:Textinput = null;
public var heightvalue:Textinput = null;

 

TextInput has a capital I, but you're using lowercase "i", so this object won't be found

 

You have add a listener for:

 

calcButton.addEventListener(MouseEvent.CLICK, calcBMI);

 

But there is no calcBMI function defined.

 

I'm assuming you didn't post it here, though.

 

The blank screen seems actually due to the fact you are adding a textField at the end of your code using the whole state width and height, and therefore, overwritting the other UI objects.

 

Cheers

 

 

 

 



(*) Kudo-me if you really think I helped you!
My plug: I'm doing a Mobile Experiment, reported on my Blog: Check it out!.
---------------------------
Paulo Garcia
http://www.mobilecreators.com - Twitter: http://twitter.com/mobilecreators
Contributor
Posts: 16
Registered: ‎03-12-2011
My Device: BlackBerry Playbook
My Carrier: None

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

[ Edited ]

Thanks for your hints. The following is my current code and I can't eliminate the error 1119 from the code below. Thank you very much for your help.

 

package
{
 import flash.display.Sprite;
 import flash.events.MouseEvent;
 import flash.text.TextField;
 
    import qnx.media.QNXStageWebView;
 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 function BMI()
  {
   var weightvalue:TextInput = new TextInput();
   weightvalue.x = 10;
   weightvalue.y = 40;
   weightvalue.text = "Enter your weight here in kilograms";
   
   var heightvalue:TextInput = 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 = 130;
   
   
   var closeButton:LabelButton = new LabelButton();
   closeButton.label = "Close";  
   closeButton.addEventListener(MouseEvent.CLICK, closeWindow);
   closeButton.x = 200;
   closeButton.y = 150;
   
   
   addChild(weightvalue);
   addChild(heightvalue);
   addChild(calcButton);
   addChild(closeButton);
   
   stage.nativeWindow.visible = true;
   
   //var text:TextField = new TextField();
   //text.text = "BMI Calculator";
   //text.x = 30;
   //text.y = 200;
   //var format:TextFormat = new TextFormat();
   //format.font = "Comic Sans MS"
   //format.size = 24;
   //text.setTextFormat(format);
   //addChild(text);
   
   
   
   
   
  }
  private function closeWindow(event:MouseEvent):void{
   stage.nativeWindow.close();
  }

 
 }
 
}

 

Error codes from Flash Builder 4

 

Description ; Resource;  Path;  Location ; Type
1119: Access of possibly undefined property autoFit through a reference with static type qnx.media:QNXStageWebView; PlaybookTest.as ; /PlaybookTest/src; line 41; Flex Problem

 

Description;  Resource;  Path;  Location; Type
1119: Access of possibly undefined property enableJavascript through a reference with static type qnx.media:QNXStageWebView.; PlaybookTest.as;  /PlaybookTest/src;  line 44;  Flex Problem

Description Resource Path Location Type
1119: Access of possibly undefined property enableScrolling through a reference with static type qnx.media:QNXStageWebView.; PlaybookTest.as; /PlaybookTest/src;  line 45;  Flex Problem

 

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

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

As @pedgarcia  suggested:

 

You have add a listener for:

 

calcButton.addEventListener(MouseEvent.CLICK, calcBMI);

 

But there is no calcBMI function defined. 

 

Try copying and pasting your closeWindow function and change the name to "calcBMI".

 

Then all you need is another 10 lines of code, a pretty background image, and you'll be entitled to a free Playbook ;-)

 

HTH - Rufus.

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

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

Just noticed you edited your post. Sorry.

 

You can probably remove the 1119 errors by taking out the line:

 

import qnx.media.QNXStageWebView

 

as you don't appear to be using the QNXStageWebView anywhere in your code (yet).

 

Although the fact you are getting the errors is mildly worrying, worth checking your set up again to make sure FB is using the Flex SDK "Blackberry Tablet OS SDK 0.9.3 for Adobe AIR" and the installed simulator matches that version.

 

HTH - Rufus.

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

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

Another erratum from me!

 

The errors you are getting seem to be from another file, not the BMI one you are working on - FlashBuilder helpfully shows you issues across all projects you have open.

 

Were you playing with:

 

http://www.petefreitag.com/item/770.cfm

 

before you embarked on the BMI project?

 

Worth noting that this example code was based on the 0.9.0 version of the SDK, and some of the properties of the QNXStageWebView have changed since this release.

 

e.g. It won't work as written in 0.9.3, but if you comment out the affected lines, it should be okay.

 

HTH - Rufus.

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

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

You are totally right. I was playing with the web browser app before embarking to my BMI project. Are there any methods to eliminate those error 1119 ?

Thank you very much for your help.

Developer
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10
My Carrier: Verizon

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

Did you try commenting or removing those lines?

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

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

Now I update my code as the following. I try to retrieve the values that users enter from the two TextInput and store them into the variables, and then convert the variables from string to number. However, I am not sure how to store the variables and convert them from String to number. In addition, at the current state, I try to use the result Textfield to display the result retrieved from the weight TextInput in order to test the button event listener; however, I can't do it. Could anyone please explain why ? 

 

Any help is gratefully appreciated.

 

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()
  {
   var weightvalue:TextInput = new TextInput();
   weightvalue.x = 10;
   weightvalue.y = 40;
   weightvalue.text = "Enter your weight here in kilograms";
   
   var heightvalue:TextInput = 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;
   
   var resultvalue:TextInput = new TextInput();
   resultvalue.x = 100;
   resultvalue.y = 250;
   
   
   addChild(weightvalue);
   addChild(heightvalue);
   addChild(resultvalue);
   addChild(calcButton);
   addChild(closeButton);
   
   stage.nativeWindow.visible = true;
   
   //var text:TextField = new TextField();
   //text.text = "BMI Calculator";
   //text.x = 30;
   //text.y = 200;
   //var format:TextFormat = new TextFormat();
   //format.font = "Comic Sans MS"
   //format.size = 24;
   //text.setTextFormat(format);
   //addChild(text);
   
   
   
   
   
  }
  public function closeWindow(event:MouseEvent):void{
   stage.nativeWindow.close();
  }
        public function calcBMI(event:MouseEvent) :void{
   var weightSmiley Frustratedtring = weightvalue.text;
   var heightSmiley Frustratedtring = heightvalue.text;
   var num_weight:int = Number(weight);
   resultvalue.text = num_weight;
   
   
  }
 
 }
 
}

Highlighted
Developer
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10
My Carrier: Verizon

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

Dont know if this will help or answer your question:

 

 

public function calcBMI(event:MouseEvent) :void
{
   var weight:String = this.weightvalue.text;
   var height:String = this.heightvalue.text;
   var num_weight:int = parseInt(weight);
   this.resultvalue.text = String( num_weight );
}

 

 

OR

 

 

public function calcBMI(event:MouseEvent) :void
{
   var weight:String = this.weightvalue.text;
   var height:String = this.heightvalue.text;
   var num_weight:Number = parseFloat(weight);
   this.resultvalue.text = num_weight.toFixed(1); // eg 23.2

}