DekGenius.com
[ Team LiB ] Previous Section Next Section

28.4 Making the Scheduler Application Available Online

The scheduler application that you have created thus far retains a user's schedule only when it is run consistently from the same computer. This is because the schedule data is stored in a local shared object. However, with just a few small changes, you can adapt this application so it can be accessed online from any computer. In the next two sections, you can choose from three different alternatives for how to do this.

28.4.1 Using Remote Shared Objects

The easiest way to convert the scheduler application to make it available online is to store the data in a remote shared object instead of a local shared object. However, this option is available only if you have access to a FlashCom server.

To modify the application to use a remote shared object, complete the following steps:

  1. Create a new FlashCom application on the server. Name the application schedulerApp.

  2. Edit the Schedule component code, as shown in the following code block. Most of the code remains the same, so only the code that changes is shown. Modifications are shown in bold.

    #initclip
    
    function Schedule(  ) {
      this.items = new Object(  );
      this.notifiers = new Object(  );
    
      // Create a new net connection and connect to the FlashCom application.
      var myConnection = new NetConnection(  ); 
      myConnection.connect("rtmp:/schedulerApp"); 
      // Create a remote shared object and connect to it. When the shared object date
      // is retrieved, call the setValues(  )  method.
      this.so = SharedObject.getRemote("mySchedule", myConnection.uri, true); 
      this.so.connect(myConnection); 
      this.so.schedule = this; 
      this.so.onSync = function(  ) { 
        this.schedule.setValues(  ); 
      } 
      this.runNotify(  );
      this.interval = setInterval(this, "runNotify", 600000);
    }
    
    Schedule.prototype = new MovieClip(  );
    
    // setValues(  )  is called when the remote shared object data is retrieved. The
    // code within the method body is the same code that was previously in the
    // constructor method.
    Schedule.prototype.setValues = function (  ) { 
      if (this.so.data.schedules != undefined) {
        for (var i in this.so.data.schedules) {
          var dt = this.so.data.schedules[i].siDate;
          this.addItem(dt);
          this.items[dt].setValues(this.so.data.schedules[i]);
        }
        this.notifiers = this.so.data.notifiers;
      }
    }
    
    // The remainder of the code does not change.

28.4.2 Using Flash Remoting

The second option for saving the scheduler data on a server is to use Flash Remoting. Obviously, this option works only if you have access to a Flash Remoting server. However, you can use this method without Flash Remoting by using the FauxSharedObject class from Chapter 27. You need to have the FauxSharedObject class ready to include in your Flash document and to also have the ColdFusion Component on the server, as per the instructions from Chapter 27. Once you have that code in place, you can quickly modify your schedule application by changing a small amount of code in the schedule component. The following shows the relevant code with the changes in bold:

#initclip
// Include the FauxSharedObject class from Chapter 27.
#include "FauxSharedObject.as"

function Schedule (  ) {
  this.items = new Object(  );
  this.notifiers = new Object(  );
  // Use a FauxSharedObject in place of the local shared object. Set the load handler
  // to the new setValues(  ) method and load the data.
  this.so = new FauxSharedObject("mySchedule", 
            "http://localhost:8500/flashservices/gateway");
  this.so.setLoadHandler("setValues", this);
  this.so.load(  );
  this.runNotify(  );
  this.interval = setInterval(this, "runNotify", 600000);
  this.saveInterval = setInterval(this, "save", 5000);
}

Schedule.prototype = new MovieClip(  );

// The code in setValues(  ) was previously included in the constructor.
Schedule.prototype.setValues = function (  ) {
  if (this.so.data.schedules != undefined) {
    for (var i in this.so.data.schedules) {
      var dt = this.so.data.schedules[i].siDate;
      this.addItem(dt);
      this.items[dt].setValues(this.so.data.schedules[i]);
    }
    this.notifiers = this.so.data.notifiers;
  }
}

// The remainder of the code does not change.
    [ Team LiB ] Previous Section Next Section