Tools for building Pocket PC Flash applications

Daily Newsletters

Sign up to ZDNet UK's daily newsletter.

Flash remoting
Flash remoting is one of the main methods used for connecting Flash applications to Web backends. It allows Flash applications to send and receive data to Web services regardless of the server side technology (.NET, ColdFusion, J2EE, etc.). Flash remoting replaces the use of sending XML files back and forth and having to parse them manually. Once Flash remoting support is installed on your application server, you are all set.

For this application, I will connect to a ColdFusion Web service designed to accept a blog (Weblog) entry from a flash application on a pocket PC device. Since this application is merely a learning project, there isn't a great deal of security or robustness within the Web service or the app.

The next example shows the basic code needed to connect to an outside resource with Flash remoting. First, you establish your gateway, and then connect to it. Once connected to your gateway, that connection is available to the entire swf file for as long as that file is open. Once you've established the connection, you access your Web service (in my case http://website/blog/uploader.cfc is the ColdFusion component that makes up my Web service). You'll notice I don't use the ( / ) when providing the path to the blog/uploader Web service. Web service calls use dot notation where each ( / ) is replaced with a ( . ).

Lastly, you pass your data to the Web service just like any local function in your application.
NetServices.setDefaultGatewayUrl
("http://wwwmysite.com/flashservices/gateway");
gatewayConnection = NetServices.createGatewayConnection();
Myservice = gatewayConnection.getService("blog.uploader" , this);

Myservice.UpdateBlog({subject:blogTitle, CatSelect:blogCategory, newentry:blogBody,
entrydate:blogDate, passcode:"XXXX"});

ColdFusion components are a different article but the gist of this Web service is a database query that inserts the passed variables to the database and returns a status message.

Flash form elements
Flash form elements are specially built components for Flash to use in Pocket PC applications to help keep file sizes to a minimum. Using these elements, you have access to all of the standard form elements: drop-down lists, text boxes, radio and check boxes, etc. The Flash Device UI components are part of the Flash for Pocket PC Developer Kit available for free from Macromedia.

There's a variety of UI components available in the kit, though you're in no way limited to just these components. You can use any of the Flash form element components that come with Flash MX, but they can adversely affect the file size of your Flash application and its usability on the Pocket PC platform.

The real work starts now
The bulk of the work in this application takes place in the SubmitBlog() function (Listing A). SubmitBlog() takes the form data from the front end and either submits it via Web service to the blog site or, if the device isn't connected, stores it for later upload. Because the shared object contains an array, you can store multiple entries, holding each one until a network connection is established.

The function starts by creating two arrays; they'll be the working data stores. I create a date/time variable that will help the offline posts show the date they were recorded. (This is not implemented yet; work in progress, 'ya know). Next, I check to see if the Pocket PC device is connected to a network. This is done elsewhere, setting the ConnectStatus variable earlier in the application.

That Flash remoting connection I established earlier is used here. I could establish the connection within the SubmitBlog() function; as far as I know, there's no performance impact either way. The actual submitting to the server is pretty unremarkable, a single call to UpdateBlog. The last step of the update is to display a status message to the user so that he knows the update was successful. One thing to note, this message is displayed no matter what the status of the update. Flash remoting provides functionality to return results from the Web service, but this application doesn't utilize that functionality yet.

Now, let's assume that the Pocket PC device is not connected to any network, you're in the car or on a plane, or in the supermarket -- the SubmitBlog() function moves over to storage mode. You start by taking the data stored in the shared object and putting it into one of the local temp arrays. This preserves any entries that might be in the shared object already. Then you populate the other temp array with the form data for the new entry. Finally, you push the new entry array to the array containing the existing shared object data, then put it all back in to the Shared object.

One last bit of code
The last bit of code for the application is the auto upload feature. When the application loads, it checks to see if it is connected to a network and that there are blog entries to upload. If so, it resubmits them to the SubmitBlog() function.
var ArLen = MyBlog.data.Blog.length
if (ConnectStatus == "Online" && ArLen >= 1)
{
for (var i = 0; i < ArLen; i++)
{
Data2Submit = MyBlog.data.Blog.pop();
//trace(i + " " + Data2Submit + "--- Length: " + Data2Submit.length);
SubmitBlog(Data2Submit[0], Data2Submit[1], Data2Submit[2], Data2Submit[3]);
//trace("blogTitle: " + Data2Submit[0]);
//trace("blogCategory: " + Data2Submit[1]);
//trace("blogBody: " + Data2Submit[2]);
//trace("blogDate: " + Data2Submit[3]);
//trace("-----------------------------");
ResultStatus = "Stored Entries have been uploaded.";
}
}

Whenever the blog entry application is loaded, the code above pops each entry out of the shared object and submits it for upload. It loops as many times as there are entries to be uploaded.

This application is pretty simple -- not very robust or secure, but that's okay. It's just a beginner application, to get you started on the road to Pocket PC Flash applications. A more advanced example of the application would include using the result() function provided by Flash remoting to handle errors and confirm completions of the process. And security would be more than a four-character passcode sent along with the data. But it's a starting point for building your own Pocket PC Flash applications.

Post your comment

In order to post a comment you need to be registered and logged in.

You can also log in with Facebook. Log in or create your ZDNet UK account below

  • Login

Will not be displayed with your comment

By signing up for this service, you indicate that you agree to our Terms and Conditions and have read and understood our Privacy Policy. Questions about membership? Find the answers in the Community FAQ

Get ZDNet UK's daily newsletter

Enter your email address to sign up

ZDNet UK Live

songmaster

SHleG: Do you remember building a clockwork scorpion kit (I'm pretty sure I have a photo of it somewhere) — I think it was called something like...

2 hours ago by songmaster on Software with everything
Chris Wortman

Good I love Yahoo! Their search engine is getting better than Google as of late. I find more of what I want on the first page, and usually within...

2 hours ago by Chris Wortman via Facebook on Linux Mint 13 ramps up for KDE release
PatrickG

openhgs has made the point for Windows 8 multiple monitors without realising it! With Windows 7 you have to switch the mouse and so your focus...

4 hours ago by PatrickG on Windows 8 could speed multi-monitor uptake
Leslie Satenstein

Mozilla has threatened to stop supporting Linux. I guess that UBUNTU is going with another browser. I indicated that if Mozilla stops supporting...

5 hours ago by Leslie Satenstein via Facebook on Firefox rapid release improves Fedora Linux
Andy Bolstridge

Much as I abhor Microsoft's licensing practices, this is almost certainly down to purchasing IT equipment via 3rd party consultants - you get the...

6 hours ago by Andy Bolstridge via Facebook on 6 million wasted licences and £1,200 PCs: welcome to government IT
Jack Schofield

@openhgs Windows users have had multiple desktops since Linus started writing Linux. They just haven't shipped as standard because not enough...

22 hours ago by Jack Schofield on Windows 8 could speed multi-monitor uptake
Jack Schofield

@Phil at Cloud4 What, Microsoft gets £1,200 per PC and £1,622 per server? Gosh, I'm amazed....

22 hours ago by Jack Schofield on 6 million wasted licences and £1,200 PCs: welcome to government IT
craigsc

You guys have no idea what is going on at Autonomy. Autonomy could have been a much more profitable organization. The sales operations at Autonomy...

24 hours ago by craigsc on HP cuts 27,000 staff as Autonomy chief Lynch leaves
Moley

How does this impact on dual or multi booting? Seems to me to more or less prohibit this, from Windows 8 anyway. Will Grub 2 recognise Windows 8,...

24 hours ago by Moley on Windows 8 start-up speed forces USB boot workaround
apexwm

I don't understand why there cannot be a slight pause during the boot process so the user can press a key. Many operating systems do this, even if...

1 day ago by apexwm on Windows 8 start-up speed forces USB boot workaround
Gavin Goodman

You can now buy the Xi3 modular computer in the UK at http://www.ocdistribution.com . This can be bought with the Tand3m software, pricing and...

1 day ago by Gavin Goodman on CES 2012: Xi3 microSERV3R
Phil at Cloud4

I agree: Mike Lynch can clearly build a business and manage strategy. I suspect the exit of Mike is more likely the end of a planned handover...

1 day ago by Phil at Cloud4 on HP cuts 27,000 staff as Autonomy chief Lynch leaves
Phil at Cloud4

This is unbeleivable government wastage with only one winner... Microsoft 1 - Tax payer Nil!

1 day ago by Phil at Cloud4 on 6 million wasted licences and £1,200 PCs: welcome to government IT
Mispam

So what do you do when you can't boot into windows? Why can't I just hold Shift while I power up instead of having to boot into windows and click a...

1 day ago by Mispam on Windows 8 start-up speed forces USB boot workaround
apexwm

I've also seen that Mac OS X for Intel machines is supposed to run in VirtualBox, which would also be a nice solution. I've never tried it though.

1 day ago by apexwm on xTreme Triple Booting: Linux, Mac & Windows
dave heasman

What I wonder is why when companies are caught bang to rights in not providing contracted services, people bend over to smear the customers? Surely...

1 day ago by dave heasman on Virgin throttles broadband for high-speed customers
pjc158

Strange statement from HP regarding Mike Lynch and not capable of scaling a company. Autonomy was a $7bn purchase which started as a small company...

1 day ago by pjc158 on HP cuts 27,000 staff as Autonomy chief Lynch leaves
lojolondon

Or - possibly, they will destroy business by ensuring people do not invest where there is no return. Another socialist idea, well beyond it's...

1 day ago by lojolondon on Open Data Institute will act as biz incubator
J.A. Watson

Good stuff Jake, very interesting. Thanks. jw

1 day ago by J.A. Watson on xTreme Triple Booting: Linux, Mac & Windows
openhgs

"the cost of a second LCD screen is about the same as one day of an office worker's time, so this should soon be recouped in extra productivity."...

2 days ago by openhgs on Windows 8 could speed multi-monitor uptake