One-way communication

One-way communication in Flash is the process of sending data to a Web server and not looking or caring if a response comes back. This is mostly used to open a URL, but could also be used to update a file with no intention of handling the result. This type of communication is often used for simply firing off an event or running some sort of cleaning system.

For example, if your site needs periodic file cleaning (deleting, renaming, moving), it is a good idea to attach this to the front-end system because your server resources will only be in use when they are already providing content for that user. This would be started by a one-way communication behind the scenes.

F The update by viewing concept should not be used for backup solutions because a slow viewing could result in missing backups.

Here is an example of one-way communication in Flash:

var serverFile:String = "http://localhost/callLink.php";

var urlRequest:URLRequest = new URLRequest(serverFile);

navigateToURL(urlRequest);

The navigateToURL function accepts two parameters. The first parameter is the URLRequest instance, and the second parameter is the window or target. By default, the window is _self, which means the new page will load into the current browser if one exists.

However, in some cases, you may want to open a new browser window, which you can do by adding the second parameter.

var serverFile:String = "http://localhost/callLink.php";

var urlRequest:URLRequest = new URLRequest(serverFile); navigateToURL(urlRequest, "_blank");

The window parameter can accept one of the following strings, as shown in Table 3.1.

TABLE 3.1

Window Targets for Links

"_self"

Current frame in the current window

"_blank"

New window

"_parent"

Parent of the current frame

"_top"

Top-level frame in the current window

The window parameter can also accept a custom name, such as the name of a frame or specific window. For example, assuming you want to send a link to the window named "childWindowBox", the code would look like the following block:

var serverFile:String = "http://localhost/callLink.php";

var urlRequest:URLRequest = new URLRequest(serverFile);

navigateToURL(urlRequest, "childWindowBox");

You substitute the prebuilt window names and add your custom name. Although this is a small change, it offers some great added functionality.

Opening a new or existing window is just one of the possibilities for connecting with other data.

Another type of one-way communication in Flash can be performed by using sendToURL().

The sendToURL() is used to silently communicate with a script. Silent communication is a form of one-way communication which does not load a separate Web page. This form of communication offers the ability to send data to a server without interfering with the user's browsing experience.

Here is the previous example, with the new function added, along with some basic error handling to manage invalid and unavailable requests.

var serverFile:String = "http://localhost/callLink.php"; var urlRequest:URLRequest = new URLRequest(serverFile);

sendToURL(urlRequest);

// handle error here

0 0

Post a comment

  • Receive news updates via email from this site