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

Web and WebWorks Development

Reply
Developer
Posts: 164
Registered: ‎08-26-2010
My Device: Not Specified

Re: Initialize BrowserField object in JS Extension

 


sondang wrote:
anyone can help me pleaseee


Thanks
Sondang

 

looks like you did a mistake scripts,

you should be refer to the Solution post by tneil above...

Contributor
Posts: 21
Registered: ‎04-23-2011
My Device: 9700
My Carrier: xl

Re: Initialize BrowserField object in JS Extension

[ Edited ]

This make me stress Im using bb os 6  and i make simple code: but still no luck

 

public final class SocketFunction extends ScriptableFunction {
	
	 private BrowserField _browserField;
	   public Object invoke(Object obj, Object[] args) throws Exception
	   {
		 
		   
	       if (args.length == 1) {
	        	
		         ScriptableFunction socketMessagex = (ScriptableFunction)args[0];
		         socketMessagex.invoke(socketMessagex, null);
		         
	          }
	         

		   return UNDEFINED;
	   }
}

	

 im using jquery and webwork environment

 

 

Contributor
Posts: 21
Registered: ‎04-23-2011
My Device: 9700
My Carrier: xl

Re: Initialize BrowserField object in JS Extension

 Tneil can you give me full example extension of di code??

New Member
Posts: 1
Registered: ‎08-04-2011
My Device: Storm
My Carrier: Vodafone

Re: Initialize BrowserField object in JS Extension

I have modified sampeljavascript extension to make it work with callback function

 

in SampleExtension class

 

 

    public void loadFeature(String feature, String version, Document doc, ScriptEngine scriptEngine) throws Exception    {        if (feature.equals("sample.alert"))         {         

  scriptEngine.addExtension("sample.alert", new AlertSample(_browserFieldForFutureUse));     

  }   

}
    public void register(WidgetConfig widgetConfig, BrowserField browserField)    {     

  _widgetNameForFutureUse = widgetConfig.getName();     

  _browserFieldForFutureUse = browserField; 

  }

 

Alert Sample

 

    public AlertSample(BrowserField _browserFieldForFutureUse) {   

_callVibrate = new Vibrate(_browserFieldForFutureUse);    }

 

In Vibrate Class

 

BrowserField _browserFieldForUse;public Vibrate(BrowserField _browserFieldForFutureUse){//samplExt=new SampleExtension();_browserFieldForUse=_browserFieldForFutureUse;}

 

in invoke method of vibrate class
        String url = "javascript:add('12', '13')";        _browserFieldForUse.executeScript(url);

Highlighted
Contributor
Posts: 41
Registered: ‎07-21-2011
My Device: Superberry
My Carrier: Rogers

Re: Initialize BrowserField object in JS Extension

That is not a good approach. Holding a reference to the BrowserField in your extension will prevent it from getting unloaded, causing massive memory leaks. 

 

Please have a look at tneil's example, and invoke the callback function directly. 

 

References should not be held to the BrowserField as a best practice.

----------------------------------------------------------------------------------------------
I kode for cudos! Or was it the other way around?