AddThis Social Bookmark Button
 Creating desktop applications with Flash Creating desktop applications with Flash (part 1)

Flash is mainly known as a program dedicated to producing animations and applications for the web that run in a web browser. This situation has evolved over the past few years with a couple of programs known as SWF wrappers, Flash wrappers or SWFtoEXE programs, that open the door of desktop application development to a lot of Flash developers and Flash designers. In this article I will mention five of these programs : Zinc from MDM, SWF studio from Northcode, Screenweaver (a now open source project), Jugglor from Flashjester and SWFKit from TopCMM Technologies.

When you create a projector or stand alone application from an SWF, there isn't much you can do to interact with the outside world, local file systems, external databases, server side applications..etc. You are just left with a few fscommand like fullscreen, quit, allowscale and a few others but not much to get excited about really. This is where our Flash wrappers come in handy.

So how does it work ? Basically and to simplify, when you develop your Flash application you incorporate some extra code in your actionscript that is going to be talking to the wrapper in some specific circumstances. For example after pressing a button you would like to be able to change the screen resolution or send an email directly from the application itself or event insert some data into a distant database. The wrapper application is listening for those specific commands coming from the embedded SWF and execute them synchronously("ready" as soon as it's called) using a callback function or asynchronously if the syntax is using fscommand. The first versions of SWFtoEXE programs started by extending the number of fscommand's available. The problem with the fscommand is that every call to the wrapper was asynchronous therefore a lot of coding tricks were necessary to glue everything together.

Most SWFtoEXE applications have now mostly given up the fscommand asynchronous syntax coupled with callbacks and work in a more synchronous way.


A tiny desktop application

To give you a more precise idea of what these SWFtoEXE applications are and can do let's have a look at a simple example application. I created a Flash file and incorporated some commands in the actionscript that will talk to the wrapper and allow the user to select any file from their system. The path to the file is then sent back to the embedded SWF and displayed in the text field above the button. (fig1)



fig1
 

In MDM Zinc v2.5 you would write:
myButton.onRelease = function(){
var myFile = mdm.Dialogs.BrowseFile.show();
filePath.text = myFile;
}

In Screenweaver 3 open source you would write:

swInterface.init();

myButton.onRelease = function(){
swSystem.Dialogs.BrowseForFile_Open("",["All Files", "*.*"],"","Open File",onOpenFile);
}

function onOpenFile(success,file){
filePath.text = file;
}


In Jugglor 2.2 you would write :

function EncodeForJugglor(x) {

Result = "";
trace(x);
for (i=0; i<x.length; i++) {
c = x.substr(i, 1);
if ((c == '.') or (c>='a') and (c<='z') or (c>='A') and (c<='Z')) {
Result += c;
} else {
s=ord(c).toString(16);
if (ord(c)<16) s='0'+s;
Result += '_'+s;
}
}
return Result;
}

myButton.onRelease = function(){
fscommand("exec",'j:sy:SelectFile:Open,"",FileName')
myOnLoad = setInterval(function(){if(FileName!=""){filePath.text = FileName;}},55)
}


In SWFKit 3.0 you would write :

import SWFKit.*;

myButton.onRelease = function(){
var myFile = Dialogs.fileOpen("All files(*.*)|*.*|");
filePath.text = myFile;
}


In SWF studio 3.0 You would write it

myButton.onRelease = function(){
var myFile = ssCore.FileSys.fileOpen({path:"",caption:"Choose a file",filter:"All Files|*.*||"},{callback:"onOpenFile"});
}

function onOpenFile(myFile){
filePath.text = myFile.result;
}

I am not going to discuss in detail the specific code related to these four SWFtoEXE applications but if you have some basic knowledge of OOP, functions and callback functions you will understand that creating desktop applications is not more tedious than creating Flash only applications, the only learning curve is related to the syntax of the scripting language used by the wrapper you are using.

You will notice that if you are writing code for Screenweaver and SWFKit you need to initialize explicitly the communication between the SWF and the wrapper using respectively swInterface.init and import SWFKit this just needs to be done once.

Continue to next page...
AddThis Social Bookmark Button
If you think this page is providing useful information, don't hesitate to leave a comment.
flashvalley
 
Copyright ©2006-2008 flashvalley.com - All rights reserved