Tuesday, May 14, 2002

stringUtils.as

Simple library that adds useful methods to the String object. You can view the documentation here. This is provided as is, but please post any errors, corrections or suggestions in the comments below.

/*
String Utility Component version 1.5
Mike Chambers
thanks to Branden Hall, Ben Glazer, Christian Cantrell, Nik Schramm
*/
/*
 This allows user to check from other include files whether or not the stringUtils
 library has been included.
 Example:
 if(!String.stringUtilsDefined)
 {
  trace("stringUtils.as not found");
 }
*/
String.prototype.constructor.stringUtilsDefined = true;
String.prototype.constructor.stringUtilsVersion = 1.5;
/**
* This methods trims all of the white space from the left side of a String.
*/
String.prototype.ltrim = function()
{
 var size = this.length;
 for(var i = 0; i < size; i++)
 {
  if(this.charCodeAt(i) > 32)
  {
   return this.substring(i);
  }
 }
 return "";
}
/**
* This methods trims all of the white space from the right side of a String.
*/
String.prototype.rtrim = function()
{
 var size = this.length;
 for(var i = size; i > 0; i--)
 {
  if(this.charCodeAt(i) > 32)
  {
   return this.substring(0, i + 1);
  }
 }
 return "";
}
/**
* This methods trims all of the white space from both sides of a String.
*/
String.prototype.trim = function()
{
 return this.rtrim().ltrim();
}
/**
* This methods returns true if the String begins with the string passed into
* the method. Otherwise, it returns false.
*/
String.prototype.beginsWith = function(s) {
 return (s == this.substring(0, s.length));
};
/**
* This methods returns true if the String ends with the string passed into
* the method. Otherwise, it returns false.
*/
String.prototype.endsWith = function(s) {
 return (s == this.substring(this.length - s.length));
};
 

String.prototype.remove = function(remove)
{
 return this.replace(remove, "");
}
String.prototype.replace = function(replace, replaceWith)
{
 sb = new String();
  found = false;
 for (var i = 0; i < this.length; i++)
    {
     if(this.charAt(i) == replace.charAt(0))
        {   
         found = true;
            for(var j = 0; j < replace.length; j++)
            {
             if(!(this.charAt(i + j) == replace.charAt(j)))
                {
                 found = false;
                    break;
                }
   }
            if(found)
            {
             sb += replaceWith;
                i = i + (replace.length - 1);
                continue;
            }
  }
        sb += this.charAt(i);
 }
    return sb;
}
10:54:38 AM    comment []  Google It!  

Config.as

Simple class that loads config files. You can view the documentation here. This is provided as is, but please post any errors, corrections or suggestions in the comments below.

#include stringUtils.as
/*
 Config.as v1.0
 created by mike chambers : mesh@macromedia.com
 requires stringUtils.as which can be downloaded from:
 http://radio.weblogs.com/0106797/files/stringutils/
*/

if(!String.stringUtilsDefined)
{
 trace("Warning : The stringUtils.as file was not loaded. This library is required " +
  "by the Config.as file. Please make sure that the stringUtils.as file is " +
  "either in the same directory as the Config.as file, or is included in the " +
  "Flash MX include path.");
}
if(String.stringUtilsVersion < 1.5)
{
 trace("Warning : Config.as requires the stringUtils.as version 1.5 or higher. " +
  "You are using version : " + String.stringUtilsVersion +
  " Please upgrade your stringUtils.as file.");
}

/*
 Constructor that takes the path to the config file as an argument
 
 Path can be any valid relative or absolute file or url path. Although if
 running from a browser,  Flash's security restrictions apply.
*/
_global.Config = function(fileName)
{
 this.fileName = fileName;
}
 
/*
 Method that allows you to set the path to the config file.
 Path can be any valid relative or absolute file or url path. Although if 
 running from a browser,  Flash's security restrictions apply.
*/
Config.prototype.setFileName = function(fileName)
{
 this.fileName = fileName;
}
 
/*
 Returns a string of the path to the current config file.
 If a config file has not been specified, then it returns null;
*/
Config.prototype.getFileName = function()
{
 return this.fileName;
}
 
/*
 Method which takes a boolean value that indicates whether
 or not double quotes surrounding names and values should be removed.
 Default is false.
*/
Config.prototype.setStripQuotes(strip)
{
 this.stripQuotes = strip;
}
 
/*
 Method which takes a boolean value that indicates whether
 or not values that contain commas should be exploded into
 an array of values.
 If set to true, calling get() on the name will return an Array.
 If set to false, calling get() on the name will return a string.
 The default is false.
*/
Config.prototype.setExplodeValues(explode)
{
 this.explodeValues = explode;
}

Config.prototype.onData = function(data)
{
 if(this.parse(data))
 {
  this.onConfigLoad(true);
 }
 else
 {
  this.loaded = false;
  this.onConfigLoad(false);
 }
 
}
 
/*
 This is a convenience method that allows you to pass a string
 representing a config file to be parsed.
 It returns true if the parsing succeeded, and false if it did not.
 Note, since the method returns immediately, you may access
 the data in the object immediately after it has returned true.
 For example: 
 var c = new Config();
 var s = "foo=bar\n";
 s += "name = mike\n";
 if(c.parse(s))
 {
  trace(c.get("foo"));    //traces "bar"
 }
 If the config object has already parsed data, then the new data will be added 
 to the config object, overwriting any duplicate values that already exist.
*/
Config.prototype.parse = function(data)
{
 var rows = data.split("\n");
 var rLength = rows.length;
 var tArray = new Array();
 var rString;
 var tName;
 var tString;
 var c;
 for(var i = 0; i < rLength; i++)
 {
  rString = rows[i];
  c = rString.charAt(0);
  if(c == ";" || c == "#" || 
   c == "[" || c == "/")
  {
   continue;
  }
  tArray = rString.split("=");
  if(tArray.length != 2)
  {
   continue;
  }
  tName = tArray[0].trim();
  tValue = tArray[1].trim();
  //maybe write custom loop to strip the quotes in one pass.
  if(this.stripQuotes)
  {
   if(tValue.beginsWith("\""))
   {
    tValue = tValue.substring(1);
    if(tValue.endsWith("\""))
    {
     tValue = tValue.substring(0, tValue.length - 1);
    }
   }
   if(tName.beginsWith("\""))
   {
    tName = tName.substring(1);
    if(tName.endsWith("\""))
    {
     tName = tName.substring(0, tName.length - 1);
    }
   }
  }
  if(this.explodeValues)
  {
   if(tValue.indexOf(",") > 0)
   {
    //we jsut changed tValue from a string to array;
    tValue = tValue.split(",");
   }
  }
  this.configArray[tName] = tValue;
  tValue = null;
  tName = null;
 }
 
 this.loaded = true;
 return true;
}
 
/*
 Takes a string and returns the value for that name in the config file.
 For example:
 config.ini
 foo=bar
 name=mike
 var c = new Config("config.ini");
 c.onConfigLoad = function(success)
 {
  trace(c.get("foo"));         //traces "bar"
  trace(c.get("name"));     //traces "mike"
 }
*/
Config.prototype.get = function(hash)
{
 return this.configArray[hash];
}
 
/*
 Returns an associative array containing the name value
 pairs contained within the object.
*/
Config.prototype.getArray = function()
{
 return this.configArray;
}
/*
 This method loads the config file specified in the constructor or
 setConfigFile() method, and then parses it.
 Once it has been parsed, the onConfigLoad() method will be
 called and passed a boolean value indicating whether the
 file was able to be parsed.
 The onConfigLoad method should be over ridden in order to
 allow the developer to know when the data has loaded and been parsed.
*/
Config.prototype.loadConfig = function()
{
 this.loaded = false;
 this.load(this.fileName);
}
 
/*
 Default values for internal variables within the object.
*/
Config.prototype.configArray = new Array();
Config.prototype.stripQuotes = false;
Config.prototype.explodeValues = false;
/*
 this indicates whether or not the data has loaded. you should be
 able to register with with a watch method.
*/
Config.prototype.loaded = false;
Config.prototype.fileName = null;
/* Extending the LoadVars object. */
Config.prototype.__proto__ = LoadVars.prototype;
Config.prototype.superClass = LoadVars.prototype.constructor;
Config.prototype.constructor.configDefined = true;
Config.prototype.constructor.configVersion = 1.0;
 
10:53:05 AM    comment []  Google It!  


Friday, May 10, 2002

Flash Remoting and Web Services : Retrieving Stock Quote Information

This is a simple Flash example that calls a Stock quote web service via Flash Remoting. You can find more info on the web service being used below at xmethods.net.

1. Download and install the ColdFusion MX preview release.

2. Download and install the Flash Remoting add-ons for Flash MX.

3. Create a new Flash movie and enter the the following code in the first frame of the movie.

#include "NetServices.as"
var params = new Object();
//this is always 0, and is specific to the web service.
params.LicenseKey = "0";
//stock symbol we want information about
params.StockSymbol = "macr";
//create an object to catch the response from the web service
var result = new Object();
//data is an object which contains properties with information about the stock.
result.onResult = function(data)
{
 //loop through all of the properties and print them out
 for(var x in data)
 {
  trace(x + " : " + data[x]);
 }
}
 
//this gets called if an error occurs.
result.onStatus = function(error)
{
 //print out the error
 trace("Error : " + error.description);
}
//the path to the web service's WSDL file.
var webServiceWSDL = "http://ws.cdyne.com/delayedstockquote/delayedstockquote.asmx?wsdl";
var gw = NetServices.createGatewayConnection("http://localhost:8500/flashservices/gateway/");
var service = gw.GetService(webServiceWSDL, result);
//call a method on the web service, passing params.
service.GetQuote(params);
Test the movie. You should see the data from the web service print in the Output window. 
5:20:10 PM    comment []  Google It!  

Finding more info on the CF object in ServerSide ActionScript

Joey Lott sent the following information to me.

When using ServerSide ActionScript there is an object available called CF with includes methods to make database queries and http requests. However, it also contains a number of other properties and methods which are undocumented, but could prove to be useful. Remember though, use undocumented features at your own risk as they may be changed or removed in future versions of the product.

Below is some code that shows how to find all of the properties and methods of the CF object on the server.

First create a file called Names.asr in the <cfinstall>/wwwroot/com/test directory and add the following code:

function getCF()
{
 var cfStuff = "";
 for(i in CF)
 {
  cfStuff += i + "\n";
 }
 return cfStuff;
}

Next, create a new Flash movie and add the following code:

#include "NetServices.as"
var o = new Object();
o.onResult = function(data)
{
 trace(data);
}
var gwURL = "http://localhost:8500/flashservices/gateway";
var gw = NetServices.createGatewayConnection(gwURL);
var names = gw.getService("com.test.Names", this);
names.getCF();

Test your movie, and you should see the following output in your Output window:

removeAttribute
include
getSession
servletContext
page
setAttribute
request
response
toString
initialize
wait
getClass
exception
http
hashCode
popBody
getAttributeNamesInScope
pushBody
getException
class
notify
getRequest
getAttributesScope
release
equals
getPage
getOut
session
getAttribute
getServletConfig
forward
servletConfig
out
findAttribute
notifyAll
handlePageException
getServletContext
query
getResponse

Pretty cool, heh? If you find some good uses for some of the properties, post them in the comments. Thanks again to Joey Lott who figured this out.

11:30:10 AM    comment []  Google It!  


Tuesday, May 07, 2002

Creating a Proxy for Flash using Flash Remoting and ServerSide ActionScript

This is a simple example that shows how to make a proxy using Flash Remoting and ServerSide ActionScript. The proxy will allow you to load XML and other data into Flash from domains other that the one the Flash movie was loaded from.

1. Download and install the ColdFusion MX preview release.

2. Download and install the Flash Remoting add-ons for Flash MX.

Create a file called Proxy.asr in the:

<cfhome>/wwwroot/com/macromedia/proxy

directory.

Add the following code the Proxy.asr file

function getURL(url)
{
 var stream = CF.http(url).get("Filecontent");
 return stream;
}

This takes a URL as a parameter and retrieves it using CF.http(). The remote data is retrieved by calling get("Filecontent") and stored in a variable named stream. The variable and its data is then returned to the Flash movie.

Next, open Flash, and add the following code to the first frame of the movie:

#include "NetServices.as"
#include "NetDebug.as"
Result = function(){};
Result.prototype.onResult = function(data)
{
 trace("Data : " + data);
}
Result.prototype.onStatus = function(error)
{
 trace("Error : " + error.description);
}
var remoteURL = "http://www.macromedia.com/desdev/resources/macromedia_resources.xml";
var gw = NetServices.createGatewayConnection("http://localhost:8500/flashservices/gateway");
var proxy = gw.getService("com.macromedia.proxy.Proxy", new Result());
proxy.getURL(remoteURL);

Test the Flash movie in the authoring environment. You should see the Macromedia XML Resource feed printed out in the debug window. If an error occurs, a description should be printed in the Debug window (or you can check the NetConnection Debugger Window > NetConnection Debugger).


 

10:18:57 PM    comment []  Google It!  


Sunday, May 05, 2002

Example : Integrating Flash MX and Radio

This tutorial demonstrates a simple example of integrating Radio with Macromedia Flash MX.

If you have visited this site before, you may or may not have noticed that the heading at the top of all of my pages is actually a Flash 6 movie. The movie displays the title (left), data from the Macromedia XML Resource Feed (right), and the date that the site was last updated (center). The last updated information actually comes from a Radio macro, and is a good example of a simple way to integrate data from Radio within a Macromedia Flash 6 movie.

First, lets look at the basic HTML required to display a Flash movie within an HTML page:

<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" 
 codebase=
 "http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0"
 WIDTH="100%" HEIGHT="40">    
 <PARAM NAME=movie VALUE="movie.swf">    
 <PARAM NAME=quality VALUE=high>         
 
 <EMBED src="movie.swf"  WIDTH="100%" HEIGHT="40" 
  TYPE="application/x-shockwave-flash" 
  PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer">
 </EMBED>
</OBJECT>

Notice that there is EMBED tag within the Object tag. The OBJECT tag is used for browsers that use the ActiveX version of the Flash player, and the EMBED tag is used for all other browsers.

The code should be pretty self explanatory. The Flash movie to be loaded is specified in the movie attribute of the PARAM tag, and the SRC attribute of the EMBED tag. Note that you can use either relative or absolute paths to specify the Flash movie (.swf).

In Flash 5, you could pass name / value pairs to the Flash movie by appending them to the end of the path to the Flash movie, like so:

<PARAM NAME=movie VALUE="movie.swf?foo=bar">

This technique still works in Flash 6, but has the limitation that the amount of data you can send varies depending on the browser it is running in.

Flash 6 offers a better solution, FlashVars, which allows you to send large amounts of data (i believe it is 64kb) into the Flash movie at runtime. The data is sent as a URL encoded query string of name / value pairs to the Flash movie.

Here is an example:

<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
 codebase=
 "http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0"
 WIDTH="100%" HEIGHT="40">    
 <PARAM NAME=movie VALUE="movie.swf">    
 <PARAM NAME=FlashVars VALUE="foo=bar&bim=bam%20bam">    
 <PARAM NAME=quality VALUE=high>         
 
 <EMBED src="movie.swf" 
  WIDTH="100%" HEIGHT="40" 
  flashvars = "foo=bar&bim=bam%20bam"
  TYPE="application/x-shockwave-flash" 
  PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer">
 </EMBED>
</OBJECT>

Notice that we have added a flashvars attributes to both the OBJECT and EMBED tags. When the Flash movie loads, the name / value pairs passed through the FLASHVARS attributes will then be available to the Flash movie on the main timeline.

So, how do we get data from Radio to Flash? Remember that Radio macros are processed on the server side. If you look at the main template for Radio, you will see that the code that creates the HTML to display the last updated date is:

<%if radioResponder.flStaticRendering {return (searchEngine.stripMarkup(now))} else {return ("")}%>

This will output the last date and time that the weblog was updated.

In order to get that data into Flash, we need to specify it in the FlashVars attribute, and we need to URL Encode the data. Here is the code that displays the Flash movie at the top of my pages:

<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
 codebase=
 "http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0"
 WIDTH="100%" HEIGHT="40"
 id="header" ALIGN="">    
 <PARAM NAME=movie VALUE="/0106797/images/header.swf">    
 <PARAM NAME=quality VALUE=high>    
 <PARAM NAME=bgcolor VALUE=#002039>    
 <param name="flashvars"
  value="u=<%if radioResponder.flStaticRendering {
   return (string.urlencode(searchEngine.stripMarkup(now)))}
   else {return ("")}%>">
   
 <EMBED src="/0106797/images/header.swf" 
  quality=high bgcolor=#002039  
  WIDTH="100%" HEIGHT="40" 
  NAME="header" 
  flashvars="u=<%if radioResponder.flStaticRendering {
   return (string.urlencode(searchEngine.stripMarkup(now)))}
   else {return ("")}%>" 
  ALIGN="" TYPE="application/x-shockwave-flash" 
  PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer">
 </EMBED>
</OBJECT>

The code (for the OBJECT tag) that passes the data from Radio to Flash is:

<param name="flashvars" 
 value="u=<%if
  radioResponder.flStaticRendering {
  return (string.urlencode(searchEngine.stripMarkup(now)))}
  else {return ("")}%>">

Notice that we embed a Radio macro within the HTML code.

Two other things to note. First, we are storing the last updated string in a variable called u (which, btw is a bad naming convention on my part). Secondly, we URL encode the string using the radio string.urlencode function.

There is one problem with the code above though. If there are any line returns with the OBJECT tags, Radio will place HTML formating, which will break the tags. Because of this, you must remove all line returns from the HTML code, which in essence places it all on one line. 

Update : Dave Winer sent along this link, which shows how to workaround the issue of Radio inserting HTML markup into your code.

<param name="flashvars" value="u=5%2F5%2F2002;%209%3A21%3A42%20PM">

which is a URL encoded string of the last updated date / time.

Within our Flash movie, we have a text field with an instance name of "updated" that will be used to display the last updated time.

Here is all of the code necessary to place the data in the field:

updated.text = "Updated : " + u;

This says that the text in the updated field should be the string "Updated " plus the value of the variable u (which was passed in through the flashvars tag).

Pretty simple, heh? Of course, this is a very simple example, but using this technique, you could theoretically create an entire weblog in Flash that is  managed by Radio (although I am not sure that you would want to).

If you have any comments, corrections or suggestions, please post them in the comments section.

Update : Thanks to Greg Burch for pointing out an error (its flashvars and not flashvar).

10:37:23 PM    comment []  Google It!  

Getting Started with Flash Remoting and Java within ColdFusion MX

This is an addendum to the following article:

Getting Started with ColdFusion MX and Flash Remoting article

that uses a Java class deployed in ColdFusion MX to create a service that can be called from Flash via Flash Remoting. Note, currently you must have ColdFusion MX installed in order to use Flash Remoting. However, we will be releasing separate versions for Java servers very soon.

This article assumes that you are familiar with Java and Java concepts.

1. Open the above article in your web browser.

2. Download and install the ColdFusion MX preview release.

3. Download and install the Flash Remoting Addons for Flash MX.

4. Create HelloWorld.java in the com.macromedia.test package.

HelloWorld.java should contain the following code:

--------HelloWorld.java------------

package com.macromedia.test; 

 
public class HelloWorld

 public String sayHello()
 {
  return "Hello World";
 }
}

---------------------------------------

compile this into the <cfinstall>\runtime\servers\default directory.

There are no changes required in the Flash code. Open the example file in Flash MX and test your movie.

Note : If you have done any of the other versions of the tutorials, you need to rename the wwwroot\com\macromedia\test directory (to ensure that the Java class is called and not the code in the folder).

Of course, this is a really simple example. Play around with passing more complex data such as Arrays, HashMaps and ResultSets. Ill post more information later on how to pass more complex datatypes.

9:12:13 PM    comment []  Google It!  


Tuesday, April 30, 2002

Example : loading data from a data base into Flash MX with Flash Remoting and ServerSide ActionScript

First, view the following tutorial / example:

Example : loading data from a data base into Flash MX with Flash Remoting and CF MX

we will use the same Flash MX code in that example, and just change the server side code.

Instead of creating a ColdFusion component called DbTest.cfc, create a file called DbTest.asr. Make sure that you rename the DbTest.cfc to something else if you did the first tutorial.

Add the following to the DbTest.asr file:

function getData()
{
 /**create an object to hold our parameters**/
 var queryData = new Object();
 
 /**set the DSN name pointing to the database**/
 queryData.datasource = "CompanyInfo";
 /**setup our SQL Query**/
 queryData.sql = "select * from Employee";
 /**Execute the query, and store the results in a variable**/
 var rs = CF.query(queryData);
 
 /**return the RecordSet to flash**/
 return rs;
}

You don't need to change anything in the Flash code. Create the Flash movie according to the directions in the tutorial and test your movie.

10:11:17 PM    comment []  Google It!  


Monday, April 29, 2002

Example : loading data from a data base into Flash MX with Flash Remoting and CF MX

Below is sample code that shows how to load data from a data base from Flash MX using Flash Remoting and ColdFusion components.

Download and install the ColdFusion MX preview release.

Download and install the Flash Remoting Addons for Flash MX.

You can download the files here.

First create a new ColdFusion component, name it DbTest.cfc and save it in wwwrootcommacromediadbtest

Here is the component code:

<cfcomponent>
 <cffunction name="getData" access="remote" returntype="query">
  <!-- CompanyInfo is a DSN name for an example DB that CFMX sets up by default -->
  <cfquery datasource="CompanyInfo" name="result">
    select * from Employee
  </cfquery>
  <cfreturn result />
 </cffunction>
</cfcomponent>

Open Flash, and place a Combo Box component on the stage, and give it an instance name of "dataBox"

add the following ActionScript to the first frame of the Flash movie:

#include "NetServices.as"
#include "NetDebug.as"
/** we will use an instance of the Result class to capture
 the data from the server **/
Result = function()
{
}
/** onResult is called when data is loaded from the server.
 In this case, a RecordSet object will be passed to it **/
Result.prototype.onResult = function(rs)
{
 trace("Data Received : " + rs.getLength() + " rows.");
 
 //data box is a simple combo box on the stage.
 dataBox.setDataProvider(rs);
}
/** onStatus is called if any errors occur when communicating
 with the server **/
Result.prototype.onStatus = function(error)
{
 trace("Error : " + error.description);
}
/** set the location of the Flash Remoting gateway **/
NetServices.setDefaultGatewayURL("http://localhost:8500/flashservices/gateway");
var gw = NetServices.createGatewayConnection();
/** get a reference to the service on the server
 First param is the path to the service on the server
 Second param is the object to send the server response too **/
var server = gw.getService("com.macromedia.dbtest.DbTest", new Result());
/** call the remote method **/
server.getData();


Save your Flash movie, and test. You should see all of the data displayed in the combo box. If it is formatted weird, then make the combo box wider.

If you get any errors, open the NetConnection Debugger (Windows > NetConnection Debugger) and then retest your movie. This will show all of the communication between Flash and the server.

This is just a simple example, but shows how easy it is to do some pretty complex stuff in Flash MX with Flash Remoting.

11:15:52 PM    comment []  Google It!  

Getting Started with ColdFusion MX and Flash Remoting : ServerSide ActionScript

This is an addendum to the following article:

Getting Started with ColdFusion MX and Flash Remoting article

that uses ServerSide ActionScript instead of a ColdFusion component.

1. open the above article in your web browser.

2. download and install the ColdFusion MX preview release.

3. Download and install the Flash Remoting Addons for Flash MX.

4. create HelloWorld.asr (the tutorial will tell you where) and add the following code:

function sayHello()
{
 return "Hello World";
}

open the example file in Flash MX and test your movie.

Of course, this is a really simple example. Play around with passing more complex data such as Arrays and RecordSets. Ill post more information later on how to make database calls, and load remote and local files into ServerSide ActionScript.

1:22:36 PM    comment []  Google It!  

Catching server timeout errors when using Flash Remoting

When calling remote services / methods via Flash Remoting, any errors that occur will trigger the onStatus method to be called:

onStatus = function(error)
{
     trace("Error : " + error.description);
}

However, if Flash cannot connect to the server (network or server is down) onStatus will not be called. Using XML and LoadVars you have to manually keep a timer in order to time out the connection, however you do not have to do this using Flash Remoting. Just create a method like the following:

_global.System.onStatus = function(info)
{
trace("details : " + info.details);
trace("description : " + info.description);
trace("code : " + info.code);
trace("level : " + info.level);
}

This method will be called if Flash MX cannot connect to the Flash Remoting server.

Here is an example output (when the server is not running):

details: http://localhost:8500/flashservices/gateway/
description: HTTP: Failed
code: NetConnection.Call.Failed
level: error

Couple of notes :

  • The exact messages may depend on the browser.
  • This will only works when connecting to the server via Flash Remoting. It will not work when using the XML or LoadVars object.
9:05:57 AM    comment []  Google It!  


Sunday, April 28, 2002

Calling Web Services from Flash MX

There has been a lot of discussion within the Flash Community concerning calling web services from Macromedia Flash. This seems to have been prompted by google making available a web service for their search engine.

So i thought i would give a quick sneak peek of calling web services from Flash using Flash Remoting. The example linked below calls the google web service to do a search (i'll let the code speak for itself).

The example is commented. Post any questions / comments in the comments section.

View Flash / Web Services example.

11:25:57 PM    comment []  Google It!  


© Copyright 2002 Mike Chambers.
 
July 2002
Sun Mon Tue Wed Thu Fri Sat
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31      
May   Aug

MX Examples

Macromedia MX

Resources

Flash MX

Click here to visit the Radio UserLand website.

Subscribe to "Examples" in Radio UserLand.

Click to see the XML version of this web page.

Click here to send an email to the editor of this weblog.