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
Developer
mdd
Posts: 225
Registered: ‎01-17-2012
My Device: PB

BB10 ToastBase.cancelRequired

Wondering if anyone else is using ToastBase, since it seems not to work properly and I've seen no related posts:

 

My code:

public static function doToast( title:String, msg:String, buttons:Array = null, handler:Function=null ):ToastBase
{
	var dlg:ToastBase = new ToastBase();
	{
		dlg.title = title;
		dlg.message = msg;

		dlg.cancelRequired = buttons is Array;
				
		if ( dlg.cancelRequired )
		{
			dlg.buttonLimit = 1;
			dlg.defaultButtonIndex = 0;
				
			for each ( var s:String in buttons )
			{
				dlg.addButton( s );
			}
			dlg.addEventListener( Event.SELECT, onToastButtonSelected );
		}
		dlg.show();
	}
	return dlg;
			
	function onToastButtonSelected( e:Event ):void
	{
		var t:ToastBase = e.target as ToastBase;
		{
			t.removeEventListener( e.type, onToastButtonSelected );

			t.cancel();
						
			if ( handler is Function )
			{
				handler( t.selectedIndex );
			}
		}
	}

}

Works fine until you click outside of the Toast dialog, in which case, the Toast dialog is closed.  Clicks inside the Toast but NOT in the button area ARE ignored.

 

Adding a test for selectedIndex == -1 in the event handler doesn't help: the dialog still closes.  Also tried adding other event handlers to the parent/stage without success.

 

I've also tried using an IconToast: the dialog appears albeit without an icon.

 

I am running on the latest simulator since my LE still not here, though the DA was received at GCSS more than 3 weeks ago.

 

Regards,

 

 

Retired
dmalik
Posts: 427
Registered: ‎02-22-2012
My Device: BlackBerry Z10, BlackBerry Dev Alpha C, BlackBerry PlayBook

Re: BB10 ToastBase.cancelRequired

Hey,

 

Sorry to hear about not getting your LE device yet :smileyfrustrated:

 

What are you trying to do with Toast? I'm wondering if a different API like notification might be better suited for this type of task. 

 

Anyway let me know and I'll see what I can do to help!

Follow me on Twitter: @dustinmalik
-----------------------------------------------------------------------------------------------------
Keep up to date on BlackBerry development: http://devblog.blackberry.com/
Developer
Developer
mdd
Posts: 225
Registered: ‎01-17-2012
My Device: PB

Re: BB10 ToastBase.cancelRequired

Hi Dustin;

 

I'm trying to use ToastBase to indicate that an error has occurred: e.g. when MediaPlayer fails (during input attach).

 

I've previously used my own CustomDialog (which includes an icon), but trying to follow UI guidelines/be more BB10-like, so tried to use ToastBase.

 

If only 1 button added, you might argue that touching anywhere SHOULD close, but it doesn't actually close if you touch INSIDE the ToastBase, and anyway, if you try adding more buttons, they don't show.

 

Also, ToastBase should support html in the message (like DialogBase) but no way to set htmlMessage...

 

I know BB is working hard to support new AIR/3D, but an SDK update is badly needed to keep the rest of us going.

 

Regards,

Retired
dmalik
Posts: 427
Registered: ‎02-22-2012
My Device: BlackBerry Z10, BlackBerry Dev Alpha C, BlackBerry PlayBook

Re: BB10 ToastBase.cancelRequired

[ Edited ]

Oh ok. I would use an AlertDialog for that then. A similar example is when you get a calendar notification on BB10.

https://developer.blackberry.com/air/apis/bb10/qnx/fuse/ui/dialog/AlertDialog.html 

 

var errorDiag:AlertDialog;	
			//show a popup	
			errorDiag = new AlertDialog(); 
			errorDiag.title = "Dialog Title"; 
			errorDiag.message = "You got an error"; 
			errorDiag.addButton("Whateves");	
			errorDiag.show(); 
			errorDiag.addEventListener(Event.SELECT, errorButtonClicked);	

Toasts are more for notifications. Like when you put your device in development mode you see that toast pop up. I don't think they're intended to have buttons in them. 

 

Hope that helps.

 

Follow me on Twitter: @dustinmalik
-----------------------------------------------------------------------------------------------------
Keep up to date on BlackBerry development: http://devblog.blackberry.com/