If you are using Internet Explorer, please remove blackberry.com from your compatibility view settings.

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
New Developer
Charly_P
Posts: 10
Registered: ‎11-26-2010
My Device: Not Specified
Accepted Solution

Async method call.

Is it possible to do an async method call ?

What do I mean with that : when a view is loaded I would like to first show the interface to the user and when the data is retrieved from the web server load the data into the view. So the user doesn't has to wait until the data is retreived to see the view. For this first step how do we do that? And as a second step I would like to knwo if it is possible to to an async call to create the view and load the data so that even this could make the app quicker.

Please use plain text.
Developer
JRab
Posts: 2,462
Registered: ‎11-04-2010
My Device: Bold 9700

Re: Async method call.

hey charly,

 

you should be able to accomplish this using the URLLoader objects load() method. When loading content from a web page, the load method does so asyncronously. Based on the status of the load() method you can check to see if its operation is complete using the Event.COMPLETE event. Like this:

 

 

package
{
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	import flash.text.TextFieldAutoSize;
	
	import qnx.ui.buttons.LabelButton;
	import qnx.ui.text.Label;
	
	[SWF(width="1024", height="600", backgroundColor="#CCCCCC", frameRate="30")]
	public class URLLoaderTest extends Sprite
	{
		private var loader:URLLoader;
		private var request:URLRequest;
		private var myTextField:Label;
		private var myBtn:LabelButton;
	
		public function URLLoaderTest()
		{
			super();
			
			// support autoOrients
			stage.align = StageAlign.TOP_LEFT;
			stage.scaleMode = StageScaleMode.NO_SCALE;
			
			request = new URLRequest("http://www.digg.com");
			
			loader = new URLLoader();
			loader.load(request);
			loader.addEventListener(Event.COMPLETE, handleData);
			
			myTextField = new Label();
			myTextField.setSize(100, 50);
			myTextField.setPosition(10,10);
			myTextField.textField.autoSize = TextFieldAutoSize.LEFT;
			
			myBtn = new LabelButton();
			myBtn.label = "This will already be here";
			myBtn.setSize(200, 70);
			myBtn.setPosition(10, 50);
			
			addChild(myTextField);
			addChild(myBtn);

		}
		private function handleData(e:Event):void
		{
			myTextField.text = "Complete!";
		}
	}
}

 as you'll see everything loads on to the screen even though the website isnt full loaded via the URLLoader object. After that operation is complete it calls the function handData() and the Label object is populated with the words 'complete'. the same concept will apply to any situation involving the URLLoader.

 

 

hope that helps. good luck!

J. Rab (Blog) (Twitter)
--
1. If you liked my post or found it useful please click on the thumbs up and provide a Like!
2. If my post solved your problem please click on the Accept as Solution button. Much appreciated!

Approved Apps: OnTrack | ssShots | Hangman
Please use plain text.
New Developer
Charly_P
Posts: 10
Registered: ‎11-26-2010
My Device: Not Specified

Re: Async method call.

Thank you for the information.

Please use plain text.
New Developer
Charly_P
Posts: 10
Registered: ‎11-26-2010
My Device: Not Specified

Re: Async method call.

I was thinking about to implement this with an DAO and MODEL in as.

 

The MODEL will call the DOA that will do the URLLoader request. So I assume that the DOA will need to notify the MODEL or the View that it is complete? 

Please use plain text.
Developer
JRab
Posts: 2,462
Registered: ‎11-04-2010
My Device: Bold 9700

Re: Async method call.

hey charly,

 

im a little rusty on the whole concept of Model-View-Controller. But i'll give it a shot. since you are loading your data into the model you just need an intermediary to receive a response from the model that the data has been loaded and then have that intermediary notify the view that there was a change and the data is ready. then the view can load it on to the screen to where it needs to be seen. The intermediary can be your controller i presume. Let me know if that made any sense hah.

J. Rab (Blog) (Twitter)
--
1. If you liked my post or found it useful please click on the thumbs up and provide a Like!
2. If my post solved your problem please click on the Accept as Solution button. Much appreciated!

Approved Apps: OnTrack | ssShots | Hangman
Please use plain text.
New Developer
Charly_P
Posts: 10
Registered: ‎11-26-2010
My Device: Not Specified

Re: Async method call.

[ Edited ]

What you said makes sence, I use the MVC with asp.net but there Microsoft implemented it direclty and you are not involved in some aspects like the event handling. So I will skip this currently.

 

Maybe another approach, simpler, is needed.

 

EDIT: 

I just read that as 3 has nu threading support , so I could not do a multi-threading approach.

Please use plain text.
Developer
JRab
Posts: 2,462
Registered: ‎11-04-2010
My Device: Bold 9700

Re: Async method call.

hey charly,

 

yeah it doesnt have threading (at least not public ones - ive read they do internally in some places) but they do have ASync methods that mimic the approach. The URLLoader class and File class are two examples of some. It's not true multi-threading but it gets the job in most places.

 

also on a side note there was a thread posted here about an MVC approach that you may or may not be interested in. here's the link:

 

http://supportforums.blackberry.com/t5/Tablet-OS-SDK-for-Adobe-AIR/New-PureMVC-AIR-Demo-HelloPlayboo...

 

good luck!

J. Rab (Blog) (Twitter)
--
1. If you liked my post or found it useful please click on the thumbs up and provide a Like!
2. If my post solved your problem please click on the Accept as Solution button. Much appreciated!

Approved Apps: OnTrack | ssShots | Hangman
Please use plain text.
Developer
jtegen
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10
My Carrier: Verizon

Re: Async method call.

There are several MVC frameworks available in AS3 that does a lot of the work for you.  I personally avoid them because they enforce one methodology, but for many applications, others swear by them.

Please use plain text.
Developer
fnicollet
Posts: 85
Registered: ‎10-25-2010
My Device: Not Specified

Re: Async method call.

Hi,

here is a nice implementation that don't use any framework. It's pretty clean and get the job done,that what i use in my projects:

http://unitedmindset.com/jonbcampos/2009/08/18/flex-best-practices-models-views-and-controllers/

 

Hope this helps,

Fabien

Hope this helps,
Fabien

--
1. If you liked my post or found it useful please click on the white star and provide a Kudo!
2. If my post solved your problem please click on the Accept as Solution button. Much appreciated!
Please use plain text.