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
shaan_softwaredvlpr
Posts: 172
Registered: ‎01-17-2011
My Device: 9500 series
My Carrier: Airtel
Accepted Solution

qnx.callExtensionMethod Call back

Hi All, 

Is there any one who successfully got call back from QNXStageWebView. 

 

I tried mostly everything to get the call back but no luck. 

 

web_view = new QNXStageWebView() ; 
			web_view.stage = sp.stage ; 
			web_view.viewPort = new Rectangle(0 , 100 , 768 , 1180 ) ;
			web_view.enableJavaScript = true ;
			web_view.enablePlugins = true ; 
			web_view.addEventListener(JavaScriptCallbackEvent.JAVA_SCRIPT_CALLBACK , onCallBack ) ;
			web_view.loadString("<script type=\"text/javascript\">function displayDate(){document.getElementById(\"demo\").innerHTML=Date();}function closed(){qnx.callExtensionMethod(\"testsaas\" , \"ascas\" , \"ascas@\" );}</script><input value='Bold' width='200px' height='200px' type='button' onClick='Bold();'/>" +
				"<div id=\"content\" contenteditable=\"true\" style=\"height:768px;font-size: 26pt;  \">") ;

 

i have written qnx.callExtensionMethod in closed function , which i am calling by using execute javascript.

 

web_view.executeJavaScript('closed();') ;

 

But i am not able to get call back on my call back listener.

 

As i used 

 

JavaScriptCallbackEvent.JAVA_SCRIPT_CALLBACK 

Thanks in advance

Please use plain text.
Developer
osus
Posts: 213
Registered: ‎04-26-2012
My Device: Z10
My Carrier: Vodafone

Re: qnx.callExtensionMethod Call back

The callback is invoked from javascript, you don't have to expect any authomatic callback, you have to call it from javascript&colon;

 

From your javascript&colon;

 

qnx.callExtensionMethod("eventName", param1, param2);

 

on your event handler on as3:

private function javaScriptCallbackHandler(event:JavaScriptCallbackEvent):void{
    myTrace("JS EVENT "+event.name); //eventName
    myTrace("trace js: "+event.params[0]); //param1
    myTrace("trace js: "+event.params[1]); //param2

}

 

 

My apps for Playbook: PlayEpub Book Reader with epub and FB2 support, Google Reader, ReaditLater - Net Files Share Explorer Get access to your network shared files- FFSync Sync your Firefox bookmarks and passwords
Please use plain text.
Developer
shaan_softwaredvlpr
Posts: 172
Registered: ‎01-17-2011
My Device: 9500 series
My Carrier: Airtel

Re: qnx.callExtensionMethod Call back

what do you mean by javascript & colon :

 

Will you please like to provide me code snippet , that how can i do so. 

In your provided code snippet , you have mentioned eventName i.e. registered functiojn name or String value of JAVA_SCRIPT_CALLBACK

 

Thanks

Please use plain text.
Developer
osus
Posts: 213
Registered: ‎04-26-2012
My Device: Z10
My Carrier: Vodafone

Re: qnx.callExtensionMethod Call back

You have to parts dealing with javascript callbaks, as3 and javascript. Both allows communication between AS3 and Webview.

 

From AS3 you can call any javascript function thrrough:

 

wk.executeJavaScript("yourFunction()");

 

and your javascript function loaded on webview will be triggered.

 

Now you need the other side, from JS to AS3.
 This is done throw (on javascript):

qnx.callExtensionMethod("eventName", param1, param2);

 

 

Suppose this function on your javascript code:

 

function yourFunction(){

     ...do some stufff

      qnx.callExtensionMethod("yourFunctionReturn", param1, param2);

}

 

From your AS3 you call your js:

 

wk.executeJavaScript("yourFunction()");

 

and on your JavaScriptCallbackEvent on AS3 you will receive the response launched from nx.callExtensionMethod("yourFunctionReturn", param1, param2);

 

 

My apps for Playbook: PlayEpub Book Reader with epub and FB2 support, Google Reader, ReaditLater - Net Files Share Explorer Get access to your network shared files- FFSync Sync your Firefox bookmarks and passwords
Please use plain text.
Developer
shaan_softwaredvlpr
Posts: 172
Registered: ‎01-17-2011
My Device: 9500 series
My Carrier: Airtel

Re: qnx.callExtensionMethod Call back

HI Osus. 

I dont know what i am missing here. 

Please go thorugh my code & let me know , if i am missing something. 

I will be very thankful.

 

web_view = new QNXStageWebView() ; 
			web_view.stage = sp.stage ; 
			web_view.viewPort = new Rectangle(0 , 100 , 768 , 1180 ) ;
			web_view.enableJavaScript = true ;
			web_view.enablePlugins = true ; 
			web_view.addEventListener(JavaScriptCallbackEvent.JAVA_SCRIPT_CALLBACK , onCallBack ) ;
			web_view.loadString("<script type=\"text/javascript\">function displayDate(){document.getElementById(\"demo\").innerHTML=Date();}function closed(){qnx.callExtensionMethod(\"onCallBack\" , \"ascas\" , \"ascas\" );}</script>") ;

 

private function onBoldClick(e : MouseEvent) : void
		{
			web_view.executeJavaScript("closed()") ;
		}
		private function onCallBack(e : JavaScriptCallbackEvent) : void
		{
			var alert : AlertDialog = new AlertDialog() ; 
			alert.message = "Call back completed";
			alert.addButton("Ok") ; 
			alert.show() ; 
		}

 

Thanks 

Please use plain text.
Developer
osus
Posts: 213
Registered: ‎04-26-2012
My Device: Z10
My Carrier: Vodafone

Re: qnx.callExtensionMethod Call back

It looks good, but you are never calling closed() function on javascript&colon;

 

 

<script type="text/javascript">
function displayDate(){
    document.getElementById("demo").innerHTML=Date();
}
function closed(){
    qnx.callExtensionMethod("onCallBack" , "ascas" , "ascas" );
}
</script>

 So you never receive the callback.

callExtensionMethod does only requiere first param, all others are on your own, you can add 0..N params. For your sample would be enough with

qnx.callExtensionMethod("onCallBack" );

 

So try this:

 

<script type="text/javascript">
function displayDate(){
    document.getElementById("demo").innerHTML=Date();
closed(); } function closed(){ qnx.callExtensionMethod("onCallBack" , "ascas" , "ascas" ); } </script>


displayDate() works? does what it's supposed to do?

Keep into account that if you have any javascript error you will no notice.

My apps for Playbook: PlayEpub Book Reader with epub and FB2 support, Google Reader, ReaditLater - Net Files Share Explorer Get access to your network shared files- FFSync Sync your Firefox bookmarks and passwords
Please use plain text.
Developer
shaan_softwaredvlpr
Posts: 172
Registered: ‎01-17-2011
My Device: 9500 series
My Carrier: Airtel

Re: qnx.callExtensionMethod Call back

 

I tried it , but still no luck.. 

 

web_view.loadString("<html><body><script type=\"text/javascript\">function displayDate(){ document.getElementById(\"freeflownote\").innerHTML=Date();alert(\"asdkasjd\");closed();}function closed(){qnx.callExtensionMethod(\"onCallBack\");}function Bold(){ document.execCommand('bold', false, null); }</script><input value='Bold' width='200px' height='200px' type='button' onClick='Bold();'/>" +
				"<div id=\"freeflownote\" contenteditable=\"true\" style=\"height:768px;font-size: 26pt;  \"></body></html>") ;

 

web_view.executeJavaScript("displayDate()") ;

 

I am able to get the alert of displaydate function , but not getting any call back. is it something missing. 

 

Can you provide me any running example of it. 

 

I am testing it on BB10 dev alpha device. OS version is 10.9.10.35

 

Thanks

 

Please use plain text.
Developer
osus
Posts: 213
Registered: ‎04-26-2012
My Device: Z10
My Carrier: Vodafone

Re: qnx.callExtensionMethod Call back

Ahh ok, it seems qnx javascript is not loaden when injecting code. You have to load from url.

 

Try this concept:

 

package
{
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	import flash.filesystem.File;
	import flash.geom.Rectangle;
	
	import qnx.events.JavaScriptCallbackEvent;
	import qnx.events.WebViewEvent;
	import qnx.media.QNXStageWebView;
	
	public class TestWeb extends Sprite
	{
		private var wk:QNXStageWebView;
		public function TestWeb()
		{
			super();
			
			// support autoOrients
			stage.align = StageAlign.TOP_LEFT;
			stage.scaleMode = StageScaleMode.NO_SCALE;
			
			this.addEventListener(Event.ADDED_TO_STAGE, init);
		}
		
		protected function init(e:Event):void{
			wk=new QNXStageWebView("test");
			wk.stage=this.stage;
			wk.viewPort=new Rectangle(0, 0, stage.stageWidth, stage.stageHeight);
			wk.addEventListener(JavaScriptCallbackEvent.JAVA_SCRIPT_CALLBACK, callback);
			wk.addEventListener(WebViewEvent.DOCUMENT_LOADED, doLoaded);
			wk.loadURL("file://"+File.applicationDirectory.nativePath+"/index.html");
			
		}
		protected function doLoaded(e:WebViewEvent):void{
			wk.executeJavaScript("displayDate()") ;
		}
		protected function callback(e:JavaScriptCallbackEvent):void{
			trace("CALLBACK RECEIVED "+e.name);
		}
	}
}

 

And create your html file on src folder:

<html>
<script type="text/javascript">
function displayDate(){ 
	document.getElementById("freeflownote").innerHTML=Date();
	alert("asdkasjd");
	closed();
}
function closed(){
	qnx.callExtensionMethod('onCallBack');
}
function Bold(){ 
	document.execCommand('bold', false, null); 
}
</script>

<body>
	<input value='Bold' width='200px' height='200px' type='button' onClick='Bold();'/>
	<div id="freeflownote" contenteditable="true" style="height:768px;font-size: 26pt;  ">
</body></html>

 

 

 

 

 

 

 

 

My apps for Playbook: PlayEpub Book Reader with epub and FB2 support, Google Reader, ReaditLater - Net Files Share Explorer Get access to your network shared files- FFSync Sync your Firefox bookmarks and passwords
Please use plain text.
Developer
shaan_softwaredvlpr
Posts: 172
Registered: ‎01-17-2011
My Device: 9500 series
My Carrier: Airtel

Re: qnx.callExtensionMethod Call back

Thanks a ton Man.. !!! 

You make my Day.. 

 

I really dint know.. This can be a issue.. 

Thanks a ton..

Please use plain text.