Welcome to the Official BlackBerry® Support Community Forums. This is your resource to discuss support topics with your peers, and learn from each other. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Adobe AIR Development

Reply
New Contributor
BazZz
Posts: 4
Registered: 02-22-2012
My Carrier: Vodafone

PromptDialog inherit class does not work for me

[ Edited ]

Hello,

 

a short question from my side. I have created my own helper packe:

 

package helpers
{
	import qnx.dialog.PromptDialog;
	
	public class MyDialog extends PromptDialog
	{
		public var dialogId:int = 0;
		
		public function MyDialog()
		{
			super();
		}
	}
}

 

Then in my App I do:

 

package
{
...

	import helpers.*;
...

public class Testproject extends Sprite
	{
		private var testDialog:MyDialog;
		testDialog = new MyDialog();
		testDialog.message = "Please enter text";
		testDialog.prompt = "[Textinput]";
		testDialog.dialogId = 1;

		testDialog.addButton("OK");
		testDialog.setButtonPropertyAt(DialogButtonProperty.CONTEXT, "enterText", 0);
		testDialog.addButton("Cancel");
		testDialog.setButtonPropertyAt(DialogButtonProperty.CONTEXT, "cancel", 1);

testDialog.addEventListener(Event.SELECT, onDialogButton);

testDialog.show(IowWindow.getAirWindow().group);
}

It compiles without any errors, but does not work. I do not receive any input prompt/popup on the tablet.

 

 If I do it with the normal PromptDialog() class instead of my MyDialog class from the helper package, then everything works fine. Any ideas? I am not that experienced in object oriented programming languages and believe that I do something terribly wrong here...

 

Please use plain text.
Developer
JRab
Posts: 2,387
Registered: 11-04-2010

Re: PromptDialog inherit class does not work for me

Hey,

 

From what I remember the Dialog classes in the QNX library arent really classes -- they are a service in the playbook (PPS). So you can't extend them and create a custom class. They can only be called and used as is. Hope that clears things 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 Contributor
BazZz
Posts: 4
Registered: 02-22-2012
My Carrier: Vodafone

Re: PromptDialog inherit class does not work for me

[ Edited ]

Hello,

 

thank you for the quick reply. Good to know. Then I will have to find another way around for my problem.

 

Let me explain what I am trying to do:

 

Basically I want to generate a sequence of input dialogs in order to gather all the necessary data from the user before my app actually starts off. So after clicking on my start button:

 

	var startBtn:LabelButton = new LabelButton();
	startBtn.label = "Play";
	startBtn.x = stage.stageWidth / 2 - startBtn.width / 2;
	startBtn.y = 420;
	startBtn.addEventListener(MouseEvent.CLICK, resetData);
	addChild(startBtn);

 I trigger the first Input dialog:

private function resetData(event:MouseEvent): void
{
	inputDialog(1);
}

 

Then I call my function which contains all my dialogs:

private function inputDialog(DialogID:int):void
{
	switch(DialogID)
	{
		//read asset amount
		case 1:
			testDialog = new PromptDialog();
			testDialog.message = "How many?";
			testDialog.prompt = "[amount]";
			testDialog.id = "1";
			
			// add buttons and associate semantic context tags to them
			testDialog.addButton("OK");
			testDialog.setButtonPropertyAt(DialogButtonProperty.CONTEXT, "enterText", 0);
			testDialog.addButton("Cancel");
			testDialog.setButtonPropertyAt(DialogButtonProperty.CONTEXT, "cancel", 1);
			
			break;
		
		//read information for each asset
		case 2:
			testDialog = new PromptDialog();
			testDialog.message = "Value please";
			testDialog.prompt = "[value]";
			testDialog.id = "2";
			
			// add buttons and associate semantic context tags to them
			testDialog.addButton("OK");
			testDialog.setButtonPropertyAt(DialogButtonProperty.CONTEXT, "enterText", 0);
			testDialog.addButton("Cancel");
			testDialog.setButtonPropertyAt(DialogButtonProperty.CONTEXT, "cancel", 1);

			break;
		//case 3 not implemented yet
		default:
			break;
	}
	
	testDialog.addEventListener(Event.SELECT, onDialogButton);
	testDialog.show(IowWindow.getAirWindow().group);
}

 

And then I catch the events from the input screen to proceed the data:

private function onDialogButton(event:Event):void
{
	switch (testDialog.id)
	{
		case "1":
			/* Respond to the user's input. */
			if ("enterText" == testDialog.getButtonPropertyAt(DialogButtonProperty.CONTEXT, testDialog.selectedIndex))
			{
				//amount
				amount=int(testDialog.text);
				InputCount=0;
				inputDialog(2); //dialog finished, call the next dialog
			}
			else
			{
				this.clearScreen();
				this.drawWelcomeScreen();
			}
			break;
		case "2":
			if ("enterText" == testDialog.getButtonPropertyAt(DialogButtonProperty.CONTEXT, testDialog.selectedIndex))
			{
				//set values
				ListEntries[InputCount]=testDialog.text;
				InputCount++;

				//check if each entry has its value set
				if(InputCount<amount) {
					inputDialog(2); //if no, ask again
				}
				else {
					inputDialog(3); //if yes, proceed to next dialog
				}
			}
			else
			{
				this.clearScreen();
				this.drawWelcomeScreen();
			}
		//case 3 not implemented yet
			break;
	}
					
}

This did not work properly, as soon as I call the inputDialog(2) from within the switch-case statement, the thing gets messed up and no further dialog appears. So I wondered if it might be somthing with the testDialog.id I am using and that is why I wanted to create my own helper class containing an int ID which I can use for that.

 

I am pretty sure that there is a more efficient and structured way to implementing a long sequence of input dialogs with logic in it, but my programming skills are limited and I am trying to learn :smileyhappy:

 

I guess it is a bad idea to call the inputDialog() from within the onDialogButton() function, but I am not sure how to implement it better.

 

Any help would be appreciated!!

 

Please use plain text.
Developer
jtegen
Posts: 4,247
Registered: 10-27-2010
My Carrier: Verizon

Re: PromptDialog inherit class does not work for me

You can keep the id as a private member of the parent class or you can use an internal function so the id is in scope to the internal function.
Please use plain text.