A Simple UcompOS Shared Object Impementation Example

The new Shared Object implementation in the UcompOS Rich Productivity Framework provides an additional model for achieving inter-application and sub-application communication and data exchange in a manner that is grounded in the MVC (Model-View-Controller) Design Pattern.

The term Shared Object in the context of the UcompOS RPF is similar in principle to the concept of the Local Shared Object infrastructure that has been in the Flash Player since the days of Flash 4 but in our case, the UcompOS RPF Shared Object is a run-time Object that does not get saved locally (unless you of course configure your own implementation to do so).

In the UcompOS Portal is an Object that gets instantiated into the application’s run-time memory upon authentication.

This Object is then freely available for all UcompOS entities to access using the GlobalManager.setSharedObject, GlobalManager.getSharedObject, and GlobalManager.getSharedObjects public API methods sponsored by the UcompOS Portal.

The UcompOSGlobalManagerProxy class in the UcompOS SDK has an API to these methods in the public methods of the class as indicated  below:

public function setSharedObject(key:String, value:Object):void
public function getSharedObject(key:String):void
public function getSharedObjects(keys:Array):void

One of the more important aspects of the Shared Object implementation is that the UcompOS Portal dispatches a Continuum Event of type SDKEvent.SHARED_OBJECT whenever a property of the Shared Object changes.

A Continuum Event is an event dispatched to every entity in the UcompOS Continuum.

An entity can attach a listener to the UcompOSGlobalManagerProxy Singleton listening for SDKEvent.SHARED_OBJECT events.

The event Object will have a key and a value property representing the property on the Shared Object that was just modified and its associated value.

As a very simple example of what we can do with this, I set up a basic UcompOS implementation.

The implementation involves a UcompOS background application that launches a UcompOS Window with a text area.  Upon initialization, this application launches another UcompOS Window with a sub-application in it next to the initial window  This sub-application also has a text area.

When text is entered in the primary application window’s text area, the text is instantly displayed in the sub-application window’s text area.

The mechanics for this employ the UcompOS Shared Object.

I’ll share the code below so you can get an understanding of how it was configured:

The Dock Manifest

<applications>
 <application background="true">
  http://desktop.ucompass.com/Shared_Object/manifest.xml
 </application>
</applications>

The Application Manifest

<application selfLoading="true" width="500" height="500" x="0" y="100">
 <source>
 <base>http://desktop.ucompass.com/Shared_Object/windowA.html</base>
 </source>
 <titles>
 <title locale="en_US">Shared Object Example</title>
 </titles>
</application>

The Application Code

<html>
<head>
<title>Window A</title>
<script type="text/javascript" src="/UcompOSSDK.js"></script>
<script type="text/javascript">
 
 var g;
 var w;
 
 function start()
 {
  g = new UcompOSGlobalManagerProxy();
  w = new UcompOSWindowProxy();
  w.add("http://desktop.ucompass.com/Shared_Object/windowB.html","Echo",500,500,510,100);
 }
 
 function echo()
 {
  // pause for 1/100th of a second as the onkeypress event is dispatched before the textarea is updated
  setTimeout(function() { g.setSharedObject("echo",document.getElementById('text').value); },10);
 }
 
</script>
</head>
<body>
<u>Enter some text</u><br/>
<textarea id="text" style="width: 400px; height: 400px;" onkeypress="echo();"></textarea>
</body>
</html>

The Sub-Application Code

 
<html>
<head>
<title>Window B</title>
<script type="text/javascript" src="/UcompOSSDK.js"></script>
<script type="text/javascript">
 
 var g;
 var w;
 
 function start()
 {
  g = new UcompOSGlobalManagerProxy();
  g.addEventListener(g.SHARED_OBJECT,echo);
 }
 
 function echo(data)
 {
  switch(data.key)
  {
   case "echo":
    document.getElementById('text').value = data.value;
   break;
  }
 }
 
</script>
</head>
<body>
<u>What you're saying in the other window</u><br/>
<textarea id="text" style="width: 400px; height: 400px;"></textarea>
</body>
</html>

About Edward Mansouri
Edward Mansouri is the CEO and Founder of Ucompass.com, Inc., a company focused on building scalable and profitable e-Learning enterprises. His expertise is in building e-Learning software, as well as in building visual frameworks such as the Enrich Content Enrichment System and the newly announced UcompOS Rich Experience Framework. He has been working with Flash since 1998, building Flash applications since 2002, and working with Adobe AIR since its private alpha release in 2006. He authored the site AIRApps.net (later renamed to O2Apps.com) dedicated to providing leadership in building Adobe AIR applications. In 2010, he is building and releasing a new e-Learning platform called Educator 2 which is built entirely upon the UcompOS Rich Experience Framework. Since 1999, over 1,000,000 students have taken courses served with his original e-Learning platform, Educator 1.

Comments are closed.