12-28-2010 04:08 PM
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!
12-28-2010 04:26 PM
Where is "functionName" being set? Is that a callback function that needs to be set in the dialog class?
12-28-2010 04:30 PM
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.
12-28-2010 04:30 PM
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!
12-28-2010 04:33 PM
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 ![]()
12-28-2010 05:09 PM
Thanks JRab! That worked. The problem was I made the functionName function private instead of public.
12-29-2010 02:30 PM - edited 12-29-2010 02:48 PM
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 ![]()
12-29-2010 02:39 PM
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.
12-29-2010 03:00 PM
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.
05-07-2011 09:12 PM
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.