Friday, April 8, 2011

The Flash App Odyssey: Saving Data

This is my story: back in November, I was tasked with developing an app for ETLO using Flash. I was eagerly anticipating the addition of Flash CS5 for my machine, but while I waited, my group hatched the idea of a simple checklist app that participants in our courses could use to store the tasks they had accomplished on a given day. I loved the idea, but in the back of my mind I knew that the big issue was getting Flash to store the checklist data after the app had been closed or the phone had been turned off.

After getting through a hectic winter, I was finally able to start working in earnest on the iPhone app, and developed most of its functionality. This week, after an all-out brawl with my PC, I was finally able to get certified as an app developer (with the help of my wife's Mac, of course. Thank goodness for those macs.) That in itself was an odyssey. It paid off the next day, though, when I was able to publish my application as an .API file and dump it on my phone for testing. Running to the cubicle of my colleague next door, I excitedly showed her the clunky beta version of my new app. However, there was still the issue of getting it to save data - a frontier I had not yet explored.

Sure, I had looked at a few tutorials and had some sample code sitting in .as files on my machine, but I had yet to get anything to work in that vein. And in my mind, Flash was a program with little long-term memory - all the applets I had designed up 'till now simply did not store persistent data. This makes today a landmark day, as I have been working on getting the iPhone app to do just that. Last night, I gave it a try using some simple code, and like most first tries, it didn't work. No surprise there. I was trying it with the actual app I had developed, which had grown into a pretty complex animal for testing this type of functionality - so I woke up this morning with the intent of designing a very simple app that would simply store a name and an age. Using a tutorial I found here, I wrote up a quick app that could save, load, and delete data. This worked on my local machine - when I published the app as a web page and entered "Frodo" and "33," I would be able to close the page, open the browser again, and call the data back up by pressing 'load.'

The next test would be to get it to work on the iPhone. I first took my code and saved it as a class file, then created the same app in iPhone format. I published the thing, dragged it into iTunes, moved it onto my phone... and...

BAM!

it kept the data after closing the app. The next test was turning the iPhone off and turning it on again. Ran the test and...

BAM!

worked again.

So now, we have a simple app that will save objects. The next task will be using similar code in my actual checklist app. But oh, the possibilities!

No comments: