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
Highlighted
Developer
Developer
Posts: 227
Registered: ‎01-17-2012
My Device: PB
My Carrier: ATT

BB10 PromptDialog

I'm still having problems with the BB10 PromptDialog - specifically when selecting the Enter key to complete the dialog, the app crashes without any console output.

 

After restarting my DevAlpha B, and re-enabling dev mode, the air-log shows:

 

000 ---- 2013-02-25 12:25:39  --------------------------
warning: pps: failed open(read) /pps/services/private/deviceproperties	(tid:1)
001 ---- 2013-02-25 12:27:21  --------------------------
emerg: screen: get_event failed: No such process (3) - line:4480	(screen_event:5)
emerg: screen: get_event failed: No such process (3) - line:4480	(screen_event:5)
emerg: screen: get_event failed: No such process (3) - line:4480	(screen_event:5)
emerg: screen: get_event failed: No such process (3) - line:4480	(screen_event:5)
emerg: screen: get_event failed: No such process (3) - line:4480	(screen_event:5)
emerg: screen: get_event failed: No such process (3) - line:4480	(screen_event:5)
emerg: screen: get_event failed: No such process (3) - line:4480	(screen_event:5)
emerg: screen: get_event failed: No such process (3) - line:4480	(screen_event:5)
emerg: screen: get_event failed: No such process (3) - line:4480	(screen_event:5)
emerg: screen: get_event failed: No such process (3) - line:4480	(screen_event:5)
emerg: screen: get_event failed: No such process (3) - line:4480	(screen_event:5)
emerg: screen: get_event failed: No such process (3) - line:4480	(screen_event:5)
emerg: screen: get_event failed: No such process (3) - line:4480	(screen_event:5)
emerg: screen: get_event failed: No such process (3) - line:4480	(screen_event:5)
emerg: screen: get_event failed: No such process (3) - line:4480	(screen_event:5)
emerg: screen: get_event failed: No such process (3) - line:4480	(screen_event:5)
emerg: screen: get_event failed: No such process (3) - line:4480	(screen_event:5)
emerg: screen: get_event failed: No such process (3) - line:4480	(screen_event:5)
emerg: screen: get_event failed: No such process (3) - line:4480	(screen_event:5)
emerg: screen: get_event failed: No such process (3) - line:4480	(screen_event:5)
emerg: screen: get_event failed: No such process (3) - line:4480	(screen_event:5)
emerg: screen: get_event failed: No such process (3) - line:4480	(screen_event:5)
emerg: screen: get_event failed: No such process (3) - line:4480	(screen_event:5)
emerg: screen: get_event failed: No such process (3) - line:4480	(screen_event:5)
emerg: screen: get_event failed: No such process (3) - line:4480	(screen_event:5)
emerg: screen: get_event failed: No such process (3) - line:4480	(screen_event:5)
emerg: screen: get_event failed: No such process (3) - line:4480	(screen_event:5)
emerg: screen: get_event failed: No such process (3) - line:4480	(screen_event:5)
emerg: screen: get_event failed: No such process (3) - line:4480	(screen_event:5)
emerg: screen: get_event failed: No such process (3) - line:4480	(screen_event:5)
emerg: screen: get_event failed: No such process (3) - line:4480	(screen_event:5)
emerg: screen: get_event failed: No such process (3) - line:4480	(screen_event:5)
emerg: screen: get_event failed: No such process (3) - line:4480	(screen_event:5)
emerg: screen: get_event failed: No such process (3) - line:4480	(screen_event:5)
emerg: screen: get_event failed: No such process (3) - line:4480	(screen_event:5)
emerg: screen: get_event failed: No such process (3) - line:4480	(screen_event:5)
emerg: screen: get_event failed: No such process (3) - line:4480	(screen_event:5)
emerg: screen: get_event failed: No such process (3) - line:4480	(screen_event:5)
emerg: screen: get_event failed: No such process (3) - line:4480	(screen_event:5)
emerg: screen: get_event failed: No such process (3) - line:4480	(screen_event:5)
emerg: screen: get_event failed: No such process (3) - line:4480	(screen_event:5)
emerg: screen: get_event failed: No such process (3) - line:4480	(screen_event:5)
emerg: screen: get_event failed: No such process (3) - line:4480	(screen_event:5)
emerg: screen: get_event failed: No such process (3) - line:4480	(screen_event:5)
emerg: screen: get_event failed: No such process (3) - line:4480	(screen_event:5)
emerg: screen: get_event failed: No such process (3) - line:4480	(screen_event:5)
emerg: screen: get_event failed: Bad file descriptor (9) - line:4480	(screen_event:5)
emerg: screen: get_event failed: Bad file descriptor (9) - line:4480	(screen_event:5)
emerg: screen: get_event failed: Bad file descriptor (9) - line:4480	(screen_event:5)
emerg: screen: get_event failed: Bad file descriptor (9) - line:4480	(screen_event:5)
emerg: screen: get_event failed: Bad file descriptor (9) - line:4480	(screen_event:5)
emerg: screen: io-winmgr appears dead, shutting down	(screen_event:5)

 here is the code:

			var dlg:PromptDialog = new PromptDialog();
			{
				dlg.title = title;
				dlg.message = prompt;
				dlg.text = text;
				
				var cancel:int = dlg.addButton( Global.bundle.getResource( "alert-cancel" ) );
				var create:int = dlg.addButton( Global.bundle.getResource( "alert-ok" ) );
				
				dlg.defaultButtonIndex = create;
				
				dlg.addEventListener( Event.SELECT, btnClicked );
				
				dlg.show();
				
				function btnClicked( e:Event ):void
				{
					var d:PromptDialog = e.target as PromptDialog;
					{
						d.removeEventListener( Event.SELECT, btnClicked );
						
						if ( d.selectedIndex == create && d.text.length > 0 )
						{
							handler( d.text );
						}
					}
				}
			}

 

Developer
Developer
Posts: 227
Registered: ‎01-17-2012
My Device: PB
My Carrier: ATT

Re: BB10 PromptDialog

UPDATE:

 

Simulator also crashes (on pressing (physical) keyboard Enter), but with console stack trace:

 

TypeError: Error #1009: Cannot access a property or method of a null object reference.
	at qnx.fuse.ui.text::EditableText/get spellCheck()[E:\hudson\workspace\BB10_1_X-AIR_SDK_API\src\qnxui\src\qnx\fuse\ui\text\EditableText.as:336]
	at qnx.fuse.ui.text::EditableText/canSpellCheck()[E:\hudson\workspace\BB10_1_X-AIR_SDK_API\src\qnxui\src\qnx\fuse\ui\text\EditableText.as:2306]
	at qnx.fuse.ui.text::EditableText/focusOut()[E:\hudson\workspace\BB10_1_X-AIR_SDK_API\src\qnxui\src\qnx\fuse\ui\text\EditableText.as:1158]
	at flash.display::NativeWindow/close()
	at IowWindowImpl/destroy()[E:\hudson\workspace\BB10_1_X-AIR_SDK_API\src\qnxui\src\qnx\fuse\ui\window\IowWindowImpl.as:224]
	at QNXWindow/destroy()[E:\hudson\workspace\BB10_1_X-AIR_SDK_API\src\qnxui\src\qnx\fuse\ui\window\QNXWindow.as:92]
	at qnx.fuse.ui.managers::WindowManager/teardownWindow()[E:\hudson\workspace\BB10_1_X-AIR_SDK_API\src\qnxui\src\qnx\fuse\ui\managers\WindowManager.as:1281]
	at Function/http://adobe.com/AS3/2006/builtin::apply()
	at caurina.transitions::Tweener$/updateTweenByIndex()[E:\hudson\workspace\BB10_1_X-AIR_SDK_API\src\qnxui\src\caurina\transitions\Tweener.as:865]
	at caurina.transitions::Tweener$/updateTweens()[E:\hudson\workspace\BB10_1_X-AIR_SDK_API\src\qnxui\src\caurina\transitions\Tweener.as:656]
	at caurina.transitions::Tweener$/onEnterFrame()[E:\hudson\workspace\BB10_1_X-AIR_SDK_API\src\qnxui\src\caurina\transitions\Tweener.as:992]

 

Developer
Posts: 210
Registered: ‎05-18-2009
My Device: NA
My Carrier: NA

Re: BB10 PromptDialog

Does it still do it when you remove your event handler?

 

You do your dialog buttons different than I do

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

Re: BB10 PromptDialog

I just tested and didn't run into any issues.

 

Looking at your sample code it appears you have a function within a function. If I remember correctly you can't remove a listener using this approach. Try placing your event function outside the function you create your dialog. It is not good practice to have functions in functions in as3. 

 

if thats not the case are you able to provide me with the class that your testing with?

 

Thanks,

Dustin

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

Re: BB10 PromptDialog

I'm very surprised to hear that inner functions are not good practice in AS3: my code uses them extensively and I can't imagine a better approach.  Is this advice documented somewhere?

 

In this case, I did try moving the SELECT handler outside and it doesn't make a difference.

 

The class that uses this function is quite big - you'd need the whole app to test.  Here's a bit more context:

 

		private function renamePlaylist( p:PlaylistItem ):void
		{
			Alert.getNewName( bundle.getResource( "newPlaylist-title" ), bundle.getResource( "newPlaylist-prompt" ), haveName, p.label );
			
			function haveName( name:String ):void
			{
				saveLocalPlaylist( p, false, name );				
				updateDirectory( myPlaylistsFolder, myPlaylistsFolder.children );
			}
		}

 handler is inner function

 

		public static function getNewName( title:String, message:String, handler:Function, text:String="" ):void
		{
			var dlg:PromptDialog = new PromptDialog();
			{
				dlg.title = title;
				dlg.message = message;
				dlg.text = text;

				var cancel:int = dlg.addButton( Global.bundle.getResource( "alert-cancel" ) );
				var create:int = dlg.addButton( Global.bundle.getResource( "alert-ok" ) );
				
				dlg.defaultButtonIndex = create;

				dlg.addEventListener( Event.SELECT, btnClicked );
				
				dlg.show();
			}

			function btnClicked( e:Event ):void
			{
				dlg.removeEventListener( Event.SELECT, btnClicked );

				trace( "type:", e.type, "hasListener:", dlg.hasEventListener( e.type ) );
				
				if ( dlg.selectedIndex == create && dlg.text.length > 0 )
				{
					handler( dlg.text );
				}
			}
		}
		

 When run, trace indicates that the listener WAS removed.

 

Moreover, everything works fine when I select OK rather than Enter to complete the PromptDialog.

 

Regards,

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

Re: BB10 PromptDialog

For some reason as far back as I can remember I've never used a nested function in AS3 (someone told my not to) so I want to disclaimer this as some of this may be wrong.

 

I can think of a few reasons why you don't want to nest functions.

 

First - everytime you call the parent function, any nested functions you have within that function get created again and again. So if you called "renamePlaylist" 5 times you would have 5 "haveName" functions in memory.

 

Second - Scoping. If I wanted to call "haveName" from another class I wouldn't be able to. To reuse code as much as possible and keeping OOP in mind this isn't the best use. (my own personal opinion)

 

Third - Readability of code. Separating out your functions just makes reading code much easier. (my own personal opinion)

 

Anyway I took some of your code and created a class to test. Give this a try and modify it for me for your use case.

 

package
{
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageQuality;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	
	import qnx.fuse.ui.dialog.*;
	
	public class DialogTest extends Sprite
	{
		private var cancel:int;
		private var create:int;
		
		public function DialogTest()
		{
			stage.quality = StageQuality.LOW;
			stage.align = StageAlign.TOP_LEFT;
			stage.scaleMode = StageScaleMode.NO_SCALE;	

			addEventListener(Event.ADDED_TO_STAGE,handleAddedToStage);
		}
		
		private function handleAddedToStage(e:Event):void
		{
			init();
			
			removeEventListener(Event.ADDED_TO_STAGE,handleAddedToStage);
		}
		
		private function init():void
		{
			var dlg:PromptDialog = new PromptDialog();
			
			dlg.title = "title";
			dlg.message = "prompt";
			dlg.text = "text";
			
			cancel = dlg.addButton( "alert-cancel" );
			create = dlg.addButton( "alert-ok" );
			
			dlg.defaultButtonIndex = create;
			
			dlg.addEventListener( Event.SELECT, btnClicked );
			
			dlg.show();
			
		}
		
		private function btnClicked( e:Event ):void
		{
			trace("Okay!!");
			var d:PromptDialog = e.target as PromptDialog;
			{
				d.removeEventListener( Event.SELECT, btnClicked );
				
				if ( d.selectedIndex == create && d.text.length > 0 )
				{
					trace("Yeah!!");
					//handler( d.text );
				}
			}
		}
		
	}
}

 

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

Re: BB10 PromptDialog

As you indicate, coding style is subjective: a web search finds lots of argument both for and against this pattern.

 

My view is that, for asynchronous flows, it is preferred:

 

First: you should NOT have multiple copies of the activation in memory as long as you remove the last reference (in the event listener).

 

Second: the inner function is a callback and should never be called from another class.  If there is a need for reuse, the class would provide a public member function which could then be called by the callback.

 

Third: For me, its better to encapsulate things to make the sequence clear.

 

Fourth: Context. In order to pass the context to the callback, you need to define and set member variables explicitly or define new events which contain the context.  It seems much more error prone.

 

Finally:

I managed to reproduce the symptoms using your example if I call the PromptDialog from a contextMenu handler so it seems that inner functions are not guilty - at least in this case. Smiley Happy

 

Thanks for your help and I look forward to the next AIR SDK arriving soon.

 

Regards,

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

Re: BB10 PromptDialog

Hi Mark,

 

I just tested the sample you sent and it worked for me without issue. I believe this may be a bug that has already been fixed (I'm testing on our latest internal beta build). The next OS release will have this fix in it.

 

Apologies for any issues this may have caused.

 

Regards,
Dustin

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

Re: BB10 PromptDialog

That's good to know - any idea when we might see the update?

 

Also: the same sample demonstrates another problem.

 

Selecting the Delete action from the context menu causes the action to be invoked twice.  Hopefully this is also fixed in the beta...

 

Its simple to work around, but could be indicative of other issues.

 

Regards,

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

Re: BB10 PromptDialog

Pretty sure ones coming in March for the US release. Not sure of any dates though. 

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