ActionScript performance tests
Auto Snapshot Extension
Central Apps
Buzzword Bingo
Blog
News
Contact


Unicode in FlashMX

Not caching SWFs

JavaScript/Flash w/Firefox and Opera

Books

This relies on your knowing something about Macromedia Central.. if you haven't heard of it, you can find info here.

I was exploring how LCService connections work and also looking at the new regular expression commands back in early September and came up with this little example application. I named it FiRe.. short for "Find Replace".. As far as functionality it certainly isn't a "killer app" by any stretch of the imagination, as all it really does is Find and Replace and a few other text manipulations. However, since creating it I've found some pretty good uses for it.

Anyway, the interesting thing that it shows is one way an Agent can be used in Central. Basically an Agent is a SWF that is packaged with a Central application that sends or receives data from either Central Applications or Central Pods. It can also be used to connect to external data sources such as web services. The Agent can call functions within the Apps and Pods, and likewise the Apps and Pods can make function calls to the Agent. There are security measures you can put in place to restrict which functions on the Agent the Apps and Pods can call, and you can also set the Agent up so that it can receive and send data to or from any app (even one from someone elses application). In this way you can create sort of a local server (or web service) running on the client system that your Apps can use as a centralized repository of functions and data. Agents run all the time in the background, and can be used to schedule tasks such as retrieving stock quotes every hour. The result is when an app or pod loads it can make a request to the Agent, and the Agent already has all the data ready to send back to the App or Pod.

So, the FiRe app I created uses the Agent to store the settings for what text you are finding and replacing, as well as how you want it transformed (remove all tabs, remove all spaces, remove carriage returns, etc). When the user clicks the Find/Replace button in either the App or the Pod the App or Pod sends the original text string to the Agent. The Agent then processes the string and returns the result. At the same time it saves the settings (text in find and replace boxes, and transformation settings) to a Local Shared Object on the client system (an LSO is a Flash version of a cookie, only the data is stored as native Flash objects).

Here's a screenshot (click it to see it full sized..) I've blocked out the icons for the other Apps I have installed.. since Central is still in Beta..

 

You can install it on your system by clicking the Install button below.
Please remember that not only is Central still in Beta (so it's not in a finalized form) but my little FiRe application is a serious Beta product.. don't be at all surprised to find a bug or two.

 

Once you get it installed, try a Find and Replace and change what you are finding and replacing. Open a Pod (or two) and notice that as you do a Find/Replace all of the Apps and Pods will update to the most recent settings.

e-mail me if you are interested in the FLA for this app.. if there's enough interest I'll clean up my code and post it.

Features List (as if it's a real application.. hehe)

  • Strip carriage returns
  • Strip tabs
  • URLencode/URLdecode text
  • Strip JavaScript, ActionScript, PHP style comments ( //   or   /* asdf asdf */ )
  • Remove tabs and spaces from between XML (and HTML) elements
  • Convert plaintext to (crude) HTML..
  • Regular Expression Find/Replace

 

some bits of code..

interfaces.as
(this is #included in the App, Pod, and Agent).. it basically creates the LCService so they can all communicate, and tells which functions each one can call on the others.
spellerLCService = {};
spellerLCService.name = "spellerName";
spellerLCService.interfaces = new Array();

// functions that the agent can call on apps and pods
spellerLCService.interfaces.Client =["refreshPods", "resetSettings"];

// functions that apps and pods can call on the agent
spellerLCService.interfaces.Server =["saveSettings","gimmeSettings","transform","echo"];

 

Agent.fla
When the Agent is initialized I need to create the connection to the LCService, and in this case it's going to be a server..

spellServer = Central.LCService.createServer( spellerLCService,this, true);

And when one of the Apps or Pods calls for the settings I can return those settings (actually they get broadcast out to all Apps and Pods in this case) by calling spellserver.resetSettings(settingsArray); Also notice that with the LCService your functions can return values..
// gimmeSettings is called when a pod/app initializes
function gimmeSettings (client) {
      settingsArray = settingsSo.data.settingsArray;
      spellServer.resetSettings(settingsArray);
      return settingsArray;
}

 

Pod.fla
When the Pod is initialized I need to create the connection to the LCService, and in this case it's going to be a client..

myAgent = Central.LCService.createClient( spellerLCService, fClientID, this, true );

And if I want to call the gimmieSettings() function in the Agent then I simply use this..
myAgent.gimmeSettings(fClientID);

The Agent receives the call for gimmieSettings()
(See the code in the Agent.fla box above.. )
and in the gimmieSettings function there is a call to spellServer.resetSettings(settingsArray). Basically this call does a broadcast call of the resetSettings() function on all clients connected to the server.
So.. the Pod has the following function in it to handle that function call. In this case it just sets the Find and Replace textboxes to what was contained in the settingsArray.

function resetSettings(sArray){
     this.find_txtbx.setValue(sArray[0]);
     this.replace_txtbx.setValue(sArray[1]);
}

 

 

Changelog:

10/26/03:

  • Fixed a few problems that were keeping the App from loading up the settings from the Agent. Now when you start the App it should correctly load the settings from the last time you did a Find/Replace and set all of the checkboxes, etc. to their correct value