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
Developer
JRab
Posts: 2,462
Registered: ‎11-04-2010
My Device: Bold 9700

Re: Text input in modal dialog

hey,

 

from the looks of ebscer code, this is how your main application should look:

 

MainApp.as:

 

 

package
{
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.MouseEvent;
	
	[SWF(width="1024", height="600", backgroundColor="#E8E8E8", frameRate="30")]
	public class MainApp extends Sprite
	{
		private var inputDialog:InputDialog;
		
		public function MainApp()
		{
			super();
			
			// support autoOrients
			stage.align = StageAlign.TOP_LEFT;
			stage.scaleMode = StageScaleMode.NO_SCALE;
			
			inputDialog = new InputDialog(this);
			
			addChild(inputDialog);
			
			
		}
		
		public function functionName(e:MouseEvent):void
		{
			removeChild(inputDialog);
		}
	}
}

 

Ebscer's InputDialog.as:

 

 

package
{
	
import qnx.ui.core.UIComponent
	import flash.display.Graphics
	import flash.events.MouseEvent
	import flash.events.Event
	import flash.text.TextField
	import flash.text.TextFormat
	import flash.text.TextFormatAlign
	import qnx.ui.text.TextInput;
import qnx.ui.buttons.LabelButton
	
	public class InputDialog extends UIComponent
	{
		public var inputText:TextInput = new TextInput();
		
		public function InputDialog(main:MainApp)
		{
			width = 1024
			height = 600
			
			var myFormat:TextFormat = new TextFormat()
			myFormat.color = 0x000000  
			myFormat.size = 32
			myFormat.align = "center"
			
			var titleText:TextField = new TextField()
			titleText.text = "Title"
			titleText.width = 500
			titleText.x = 260
			titleText.y = 200
			titleText.setTextFormat(myFormat)
			addChild(titleText)
			
			myFormat.size = 22
			var instText:TextField = new TextField()
			instText.text = "instructions"
			instText.width = titleText.width
			instText.x = titleText.x
			instText.y = 245
			instText.setTextFormat(myFormat)
			addChild(instText)
			
			inputText.width = 240
			inputText.x = 392
			inputText.y = 277
			inputText.height = 40
			inputText.prompt = "Prompt Text"
			addChild(inputText)
			
			var doneButton:LabelButton = new LabelButton()
			doneButton.label = "Done"
			doneButton.x = inputText.x
			doneButton.y = 330
			doneButton.width = 240
			doneButton.height = 45	
			doneButton.addEventListener(MouseEvent.CLICK,main.functionName)
			addChild(doneButton)
		}
		
		override protected function draw():void
		{
			var g:Graphics = graphics;
			g.clear();
			g.beginFill(0xCCCCCC,.5);
			g.drawRect(0,0,1024,600);
			g.endFill();
			g.beginFill(0xDDDDDD,1.0);
			g.drawRoundRect(262,180,500,270,10);
			g.endFill();
		}
	}
}

 

 

 

you are sending in your main application class (of type MainApp) into the InputDialog class. so you would send "this" into the inputDialog object so you can reference the main application's funciton called "functionName". 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
Please use plain text.
Developer
jtegen
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10

Re: Text input in modal dialog

Where is "functionName" being set?  Is that a callback function that needs to be set in the dialog class?

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

Re: Text input in modal dialog

To make that class more arbitrary, I would not pass in the root Sprite as a parameter, I would set an attribute or pass in a Function to be called on various button presses.  They way it is now, it is too tightly coupled to the root class and could not be used anywhere else.  I know it is just an example.

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

Re: Text input in modal dialog

hey john,

 

the function 'functionName' is being set in the main application class "MainApp". here's the code from the main app:

 

 

package
{
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.MouseEvent;

[SWF(width="1024", height="600", backgroundColor="#E8E8E8", frameRate="30")]
public class MainApp extends Sprite
{
private var inputDialog:InputDialog;

public function MainApp()
{
super();

// support autoOrients
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;

inputDialog = new InputDialog(this);

addChild(inputDialog);


}

public function functionName(e:MouseEvent):void
{
removeChild(inputDialog);
}
}
}

 

the function is in bold. so the custom inputdialog class that ebscer wrote up is a "utility" class used by the Main Application which is called "MainApp". hope that helps!

 

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: Text input in modal dialog

hey john,

 

yah i agree that its best to send in a function or some other sort of reference instead of the class itself. but for an example thats not bad. just a proof of concept model and it gets the job done :smileyhappy:

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.
Trusted Contributor
PBDev
Posts: 108
Registered: ‎12-28-2010
My Device: Free PlayBook

Re: Text input in modal dialog

Thanks JRab! That worked. The problem was I made the functionName function private instead of public.

Please use plain text.
Developer
TheDarkIn1978
Posts: 409
Registered: ‎12-10-2010
My Device: PlayBook

Re: Text input in modal dialog

[ Edited ]

another option would be to unzip the qnx-screen.swc and decompile its library.swf to see how the dialog class is programmed, using it as a base to roll your own.

 

[EDIT] assuming the code isn't obfuscated, of course.

 

[EDIT 2]  it's not obfuscated :smileywink:


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

Re: Text input in modal dialog

In terms of GUI code, you're probably would not see much since the dialog functionality is a service running in the background of the PB.  The API is likely just an interface to that service.

Please use plain text.
Developer
TheDarkIn1978
Posts: 409
Registered: ‎12-10-2010
My Device: PlayBook

Re: Text input in modal dialog

ah, you're right.  oh well, it's still fun to poke around.  i see they have the qnx.notificationManager package ready to go.  i wonder if it works since it's not documented.


PlayBook Applications:
Drop Swatch
Please use plain text.
Developer
DT655
Posts: 71
Registered: ‎04-27-2011
My Device: Bold 9700 and Playbook 64

Re: Text input in modal dialog

I have the class working, and calling it ok, and its responding to the click event fine and running the appropriate function.

 

Question: How do I retrieve the value of inputText in the function that is called when the done button is clicked.

 

 

Please use plain text.