01-03-2011 08:13 AM
hi...
How to create custom dialog alert ?
Thanks,
Satish
01-03-2011 08:17 AM
That is not currently possible in the SDK. Alerts and dialogs API is just an interface to a background service on the PB OS. That is why you get a runtime error as an AIR application. In one of the webinars, they did say that will be possible in a future SDK release (been waiting patiently of months). There was a posting to create your own "dialog" class with the use of dual sprites, so you might dig that up from about a week ago.
01-03-2011 01:53 PM - edited 01-03-2011 02:01 PM
This will create a custom dialog box with the same appearance as the default Alert Dialog box.
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 customDialog:CustomDialog;
public function MainApp()
{
super();
// support autoOrients
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
customDialog = new CustomDialog(this);
addChild(customDialog);
}
public function OKClicked(e:MouseEvent):void
{
// Do stuff here
removeChild(customDialog);
}
public function cancelDialog(e:MouseEvent):void
{
removeChild(customDialog);
}
}
}
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.buttons.LabelButton
public class CustomDialog extends UIComponent
{
public function CustomDialog(main:MainApp)
{
var myFormat:TextFormat = new TextFormat();
myFormat.color = 0x000000;
myFormat.size = 20; //
myFormat.bold = true; // Changed to match Alert Dialog box
myFormat.font = "Verdana"; //
myFormat.align = "center";
var titleText:TextField = new TextField()
titleText.text = "Title"
titleText.width = 500;
titleText.x = 262;
titleText.y = 102;
titleText.setTextFormat(myFormat)
addChild(titleText)
var OKButton:LabelButton = new LabelButton()
OKButton.label = "OK";
OKButton.setPosition(348, 466);
OKButton.setSize(158, 40);
OKButton.addEventListener(MouseEvent.CLICK, main.OKClicked);
addChild(OKButton);
var cancelButton:LabelButton = new LabelButton()
cancelButton.label = "Cancel";
cancelButton.setPosition(517, 466);
cancelButton.setSize(158, 40);
cancelButton.addEventListener(MouseEvent.CLICK, main.cancelDialog);
addChild(cancelButton);
}
override protected function draw():void
{
var g:Graphics = graphics;
g.clear();
g.beginFill(0x000000, .8); // Changed to match Alert Dialog box
g.drawRect(0, 0, 1024, 600);
g.endFill();
g.beginFill(0xEDEDED, 1); // Changed color to match Alert Dialog box
// g.drawRoundRect(314, 142, 396, 316, 10); // Small dialog box
// g.drawRoundRect(314, 32, 396, 536, 10); // Tall dialog box
g.drawRoundRect(314, 62, 396, 476, 10); // Custom size
g.endFill();
}
}
}
This is modified code that was originally posted by Ebscer and JRab. see Text input in modal dialog
01-04-2011 07:22 AM
hi
thanks for reply,
MainApp background event occured. when CustomDialog alert is display.
how to remove mainApp class event.