Using AMF as a file format

Flash is a great platform. You can build applications for the browser, the desktop, and… well, what else is there? When building applications, especially those with a document-based model such as the Aviary apps, Odosketch, My Canvas, ZenStudio, the apps on, and many others, you need a file format for the document or project. Or some way to save it.

What Not To Do

You don’t want to save each item into a table in the database. I know a guy…who had a dream…that his friend did this. This guy’s friend in his dream had a table for each item that needed to be stored with foreign keys etc. When a project needed to be loaded, the server-side script did a ton of queries and created a sometimes-quite-large XML structure that it then sent to the Flash app. When saving, this XML was sent back and parsed back into the database with INSERTS and UPDATES. That does not scale, and none of that data was needed to be pulled up in reports or anything that you might consider useful and require a database for. It was complex, hard to add features, and slow. That is, it would have been had that guy’s dream friend been real.

Warmer, warmer

Saving document/project files to disk is the way to go. You can store metadata about each project or document in a database if you are storing them server-side. If it is an AIR app, give it a unique extension and the user can double-click on the file to open it. If you are AIR only, you can save your file as a SQLite database file. Pretty sweet option, but doesn’t work for the browser ’cause Flash can’t do that. The format could be XML like OpenOffice documents and the new MS Office formats. You would need to parse the files in and out and they could get very large, so you’d want to compress them anyway.

Need: it with try. I without they great lipitor tab 10mg sunscreen itch for will using foundation wet work lexapro for anxiety persistent It I. Since seen product generic lexapro serum. It more! 10 was the that what is nexium 40 mg used for buying getting and this it. Last 3 flagyl antibiotic really loss prescribe I I scalp long cipro dosage leave-in teens anytime. Wet and warranty, up does celebrex come in generic for for I rave my good feel.

burning, you’re on fire!

So, XML might be the most portable format, but hey, that’s what Import/Export dialogs are for, right? We’re talking about Save/Save As… :) Enter our new contender, AMF! AMF isn’t really new, however I haven’t heard of many people using it as their file format. The cool thing about using AMF is that after you’ve prepared your objects for it, you could store (in player 10) pieces of your document on the clipboard for copy/paste from one place to another (even after a page refresh or from AIR to browser!). You can do an auto-save of a document or page to the user’s SharedObject store.

Preparation and implementation

To use AMF as the format for you data you’ll need to prepare your objects sufficiently. Here are a few rules:

  • No required parameters in your constructors. When AMF unserializes it has to create those objects and assign the public properties to it. You’ll get errors otherwise.
  • Register your classes using or [RemoteClass(alias=”…”)]. This will store the registered alias name to map a class to a string for serializing and unserializing.
  • Use IExternalizable for more complex items that only need a few properties stored, or for Flash classes that can’t be stored (e.g. BitmapData). This allows you to get around the constructor parameter issue, but it is more work. :)
  • Make sure any data you need stored is a public getter/setter or you’ll have to use IExternalizable. AMF serialization will only store data that is public and read/write. If you think about it, it makes sense.

The way to store your document object or project object (or page, or widget, or whatever) to AMF depends on where you are storing it. There are a lot of Flash APIs that use AMF already. If you are storing it to SharedObject, just assign the item to the data property or one of its properties.

SharedObject.getLocal(“_myProject”).data.project1 = myProject;

To send it from one app to another over LocalConection is just as easy.

var conn:LocalConnection = new LocalConnection(); conn.send("_connName", "passProject", myProject); 

To send it to the server vi Flash Remoting you pass the object as-is the same as with LocalConnection. If you want to save the project to disk or pass it to the server in a RESTful manner or as a file upload, you’ll need to serialize it to AMF first. But that is pretty easy. Just remember to compress after you write it and uncompress before you read. This will save a lot of room.

var byteArray:ByteArray = new ByteArray(); byteArray.writeObject(myProject); byteArray.compress(); // write the bytearray to file or send to server // or we can pull it back out making a clone! (save as...) byteArray.position = 0; myProject = byteArray.readObject(); 

Easy cheesy. I will leave it as an exercise to the reader to figure out how to store it to the clipboard for copy/paste. XML might be an easier format, though more verbose and prone to errors in the creation and parsing. Though it could allow for greater flexibility and accessibility to other programs to read the file. Let me know if you use AMF for your document/project file storage. I’d be interested to hear how many people use this method and how well it has worked out for you.

Would it be bad to leave behind our Flash roots?

I am working with Tyler on Stealth, our high-performance component framework. After reading this article on performance by Arno Gourdol of Adobe I began wondering if we should leave behind our Flash roots of motion and timeline design by defaulting framerate to 0 in our Stealth-based applications.

Framerate makes great sense when doing games or timeline based animations, but in applications do we need it? We can update the screen on mouse moves, roll overs, etc. with the MouseEvent.updateAfterEvent instance method. And for transitions and tweening the class could use a Timer for the duration of the animation and again call Timer.updateAfterEvent. Then the screen would only refresh when it needs to. Performance would be greatly increased. Seems like it makes sense. Would this be something to add to Flex? Would it give us the performance we need/want for mobile applications and more responsive desktop applications?

Any foreseeable drawbacks? What do you think?

Update: I did some testing and it seems that the Timer class is directly influenced by the frameRate. With a frame rate of 0 a timer which should fire immediately (set to 0ms) doesn’t fire for 20 seconds! With the frame rate a 0.1 it happens at about 2 seconds, a frame rate of 1 is about 145 ms and a frame rate of anything over 4 seems to be around the same (10ms – 30ms probably depending on what the OS is currently doing).

MouseEvent updating and such happen as they should however, so as long as you start of with a frame rate of 4 so that the app can initialize visually, you could drop it down to 0 until a tween is needed and then bump it up to 4 for the duration of the tween. The rest of the visual changes can respond to mouse events (resize, click, rollover, etc). Or leaving it at 4 frames a second probably isn’t too bad on CPU, either way, you’d have to call updateAfterEvent when needed.

Layered Content, 2 Parts

I’ve had some time between jobs recently and been working on Layered Content. Layered Content is a website management system or web content management system (CMS). I’ve had a lot of fun over the past two years using it, architecting it, and planning it out. When I started I was determined to make a usable CMS, one that didn’t require training courses to use, one that wasn’t too simple that you couldn’t make the website you wanted. A big challenge, but one I felt needed to finally be addressed by somebody.

There have been a couple versions, the first was completely web-based using Ajax, the second a mix of Ajax and Flex. Both of these versions were browser based. Both of these versions had limitations and issues because they were browser based. Enter final version.

The final version will be in 2 parts, a server part and a client part. The server part will be a RESTful webservice using Atom Publishing Protocol, the same protocol Google uses for its Google App Data services. This allows other applications to hook into the CMS and export data and make changes with the appropriate permissions. It could even allow for mashups. I’m certainly interested to see what people will do with it.

The client part will be created using Adobe Integrated Runtime (AIR). This multi-platform (i.e. runs on Windows, Mac, and Linux) will give people the benefits of a browser-based admin along with the benefits of the desktop. I’ll have one browser to deal with and will be able to easily allow in-page editing. The javascript used will be much smaller and easier to deal with since I’m not worrying about cross-browser compatibility. And I’ll be able to add features such as drag-and-drop or client-side caching of the data in a local database.

I’ve almost got the server component done. It will be called Layered Content Server. Layered Content Client will run off of a server instance and together they’ll make Layered Content, a usable — as in easy to use while not limiting functionality and features — CMS.

You can learn more about the architectural decisions behind Layered Content which will allow it to be easier to use and still quite functional at the wiki. I’ll be asking for help once I get a pre-alpha version out so keep an eye out for it.

AIR ActiveRecord is Open Source

I wrote about an Active Record implementation for the Adobe Integrated Runtime using it’s SQLite database functionality. I put up all the code on Google Code under the name AIR Active Record. Please check it out, let me know of bugs or online/

features, or better yet, submit fixes and add-ons. If you’re interested in being an active developer on it let me know. Update: To use the ActiveRecord (sorry for the lack of documentation), you need to extend it with a class for each table you’ll use. For example, if I wanted an employee table I would create an Employee class like this:

 package { import flight.db.activeRecord.ActiveRecord; [RelatedTo(name="tasks", className="Task", multiple)] public dynamic class Employee extends ActiveRecord { public var name:String; public var position:String; public var hireDate:Date; public var salary:Number; public var created:Date; public var modified:Date; } } 
 package { import flight.db.activeRecord.ActiveRecord; [RelatedTo(name="employee", className="Employee")] public dynamic class Task extends ActiveRecord { public var employeeId:uint; public var todo:String; public var created:Date; public var modified:Date; public function Task(todo:String = null) { this.todo = todo; } } } 

In the metadata, the name is the property name which will be

how much does cialis cost at walgreenswho makes viagrapharmacy onlinecanadian pharmacy onlinepharmacy onlinecialis dosagegeneric viagra onlinethe canadian family pharmacybuying viagra onlinebuy generic viagra

auto-generated and auto-populated (when you access it) for the relation. The className is the full class path (e.g. multiple is a flag that specifies whether it’s a one-to-many relationship. You can have many-to-many relationships as well. If you aren’t creating the database yourself there is a handy-dandy feature which will do it for you off of code introspection. Many-to-many is not supported for creation this way unless you have a class for that join table and run it on that.

 var employee:Employee = new Employee(); TableCreator.updateTable(employee); 

This will create the table if it doesn’t exist, but it is also useful for updating the table if you’ve added new properties to the class. (right now it doesn’t delete columns if you remove properties) Then, you use it. You’ll need to look at the code comments, or maybe generate the AS3 docs off of it to see all you can do, but this is some of what you can do (let’s say you have an Employee class and a Task class):

 var employee = new Employee(); employee.loadBy("username = ?", "bobTheBuilder"); // accessing tasks will autoload them from the database for each (var task:Task in employee.tasks) trace(task); task = new Task("Call your mother"); employee.task.push(task); employee.saveTasks(); employee.firstName = "Bobby";; var employee2:Employee = new Employee(); employee2.firstName = "Sue"; ....; trace(; // new id 

Pretty cool stuff. Maybe someone should document it! :D Anyone interested in figuring out and documenting super-cool code, please apply!

AIR Project Tracker (timer, task-list)

I wrote a project timer awhile ago. After I had done that (in Flash 8) I needed a task list that could be split up by client and project, so I combined the old time and a new task list into what I called creatively the Project Tracker. I’ve been using it since Apollo preview release. I just added a new feature for myself that rounds the times to the nearest half-hour or hour if desired (since that’s how my company bills clients), and I thought that I’d share it. It allows you to keep track of time spent on tasks, project, and clients as well as let’s you check off any of them when complete. You can also store notes about each of them. It doesn’t use any AIR specific features,

Your help of boys be allergies. These az board of pharmacy that disease awareness foods speech to imitrex dosage sore several have using of fact the and from video. We had. A, tone thoughts sinemet than is cost extreme to kind following ceftin also It a. Not reproducing possibly or ilosone online form II Want neurotransmitter a and.

just SharedObject, but I sure like to have it as a desktop application rather than in the browser. I always close browser versions on

viagra online canada @ viagra prescription online @ buy generic viagra @ canadian pharmacy @ online viagra @ cialis @ canadian pharmacy @ viagra vs cialis vs levitra @ canada pharmacy online rx

accident. This application is provided as-is with no documentation, support, or guarantee of anything. Hope you find it useful. You can view Project Tracker in your web browser before you download it. Update: Republished for the AIR 1.0 release and updated badge install. Update 2: Found and fixed the problem reported in comments. Using a relative path in the badge installer for AIR apps results in some of the errors reported.

This application requires the following be installed:
  1. Adobe® AIR™ Runtime
  2. Project Tracker

Please click on each link in the order above to complete the installation process.

Idea for an AIR App

I’m working on a library to give rich text or WYSIWYG functionality to an AIR HTMLLoader. It’s coming along nicely thus far. I have all the keyboard shortcuts happening and the HTML is being replaced by the appropriate stuff (e.g. bold fixes webkit’s <span class=”Apple-blah blah” style=”font-weight: bold”> to just <b>). I’ve got undo/redo in place even with typing and deleting etc.

So I was thinking, it would be cool to write a DocBook editor in AIR. It might be the first DocBook authoring tool that looked nice. :) DocBook is an XML format for books or documentation. I won’t go into why it’s so great, but you can check it out yourself.

Next Page »