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
Regular Contributor
SatishK
Posts: 90
Registered: ‎09-04-2009
My Device: Blackberry Z10

Custom Dialog alert

hi...

 

 

How to create custom dialog alert ?

 

Thanks,

Satish

 

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

Re: Custom Dialog alert

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.

Trusted Contributor
PBDev
Posts: 108
Registered: ‎12-28-2010
My Device: Free PlayBook

Re: Custom Dialog alert

[ Edited ]

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

Regular Contributor
SatishK
Posts: 90
Registered: ‎09-04-2009
My Device: Blackberry Z10

Re: Custom Dialog alert

hi

 

thanks for reply,

MainApp background event occured. when CustomDialog alert is display.

how to remove mainApp class event.