one of the vital cool new facets of Macromedia ColdFusion MX is Macromedia Flash Remoting. Macromedia Flash Remoting permits you to use ColdFusion MX performance to your Macromedia Flash films simply using regular Macromedia Flash syntax and objects.
today, we’ll stroll through a simple Macromedia Flash Remoting instance. The SWF will use Macromedia Flash Remoting to name a ColdFusion MX part (also known as a CFC) on the server. The ColdFusion element will return a string, which should be loaded into Macromedia Flash and displayed.Getting started
1. download the educational info.
all of the data you’ll need can also be downloaded here (35 KB).
Create a folder at cf_webrootcommacromediatest. Unpack the ZIP file into the verify folder. observe that throughout the academic, we’ll seek advice from cf_webroot Your cf_webroot varies in accordance with your installation place.
2. installation the required application
The software we’ll use throughout the tutorial comprises:
which you could down load trial models of the application listed here. observe the installing wizards to make certain that all software is correctly put in.creating the Server-side Code
The server-side code is a simple ColdFusion part. It’s included within the file HelloWorld.cfc in the com/macromedia/check folder, and be aware that the file name HelloWorld.cfc also determines the carrier identify for the part. So in this case, the provider identify is HelloWorld. in case you open HelloWorld.cfc in a textual content editor, you’ll see this:<cfcomponent identify="HelloWorld">
<cffunction name="sayHello" entry="far flung"> <cfreturn "good day World"> </cffunction>
As that you could see, it’s relatively fundamental to create a basic component â€“ they easily use the cfcomponent tag. besides the fact that children the component represents a Macromedia Flash Remoting carrier, it does nothing with the aid of itself.
in order to make the element characteristic, they add the cffunction tag — which is a way — to it. for that reason, the part now includes a cffunction tag named "sayHello," through which the cfreturn tag is nested. And when you name this element, it returns a "HelloWorld" string to whichever URL or provider etc. called the system. that you can have as many features as you’d like inner a part, but for this illustration, we’ll include simply the one.
note also that the access attribute price is "faraway" inside the cffunction tag. This attribute is required in case you want Flash motion pictures (or different remote capabilities) to entry the component methods.
And that’s it! We’ve successfully created a part. word that the corresponding file is found herecoldfusionmx_webrootcommacromediatestHelloWorld.cfc
Why did I coach you to region the information in that folder? smartly, components aren’t observed simply through identify â€“ they’re additionally observed through place (during this case, coldfusionmx_webrootcommacromediatest). So with the aid of inserting your part within the commacromediatest folder, you:
and eventually, you’ve probably observed by way of now that com/macromedia is readily macromedia.com in reverse. Likewise, be sure you use your own domain identify for the add-ons that you create, reminiscent of web/foo in case your web site’s called foo.net.
So, what’s next? At this point you may start building Macromedia Flash code to entry your part, however first, let’s make a simple ColdFusion web page to make certain that the element basically works. If they look at various it now, it’ll be less complicated to debug any problems that may additionally arise than it might be to debug once we’d begun working with Macromedia Flash MX.
in the cfusionmx_webroot/com/macromedia/examine/ listing, there's a file named test.cfm which includes the following code:<cfoutput> <cfinvoke component="com.macromedia.test.HelloWorld" method="sayHello" returnVariable="message" /> #message# </cfoutput>The file test.cfm uses the cfinvoke tag to call the component and then print the component's output with the cfoutput tag. Let's now take a quick appear at the cfinvoke tag's attributes to consider what's occurring. The code which reads: element="com.macromedia.look at various.HelloWorld" specifies which element can be known as. The path, com.macromedia.examine.HelloWorld points to the commacromediatestHelloWorld file relative to cf_webroot folder. right here code: formulation="sayHello" specifies the feature or system it is to be finished in the component. The next area: returnVariable="message" specifies the variable identify we'll use to keep any records lower back from the element. they will use this variable to return the string from the component formula, and the cfoutput tag to display the variable in the web browser. save the ColdFusion page, look at various.cfm, and consider it in an internet browser, at https://killexams.com/vendors-exam-list (alternate the area name, or add a port number as indispensable for your selected set up). The message "good day World" should still screen. If it would not, otherwise you acquire an error, examine your element code, the CFML verify web page, and the URL for typos. you have got simply experienced the energy of add-ons! They can help you create modular code that can be used in many approaches, and even by means of dissimilar classes (during this case, ColdFusion MX and Macromedia Flash MX). Now you are able to connect with your part with Macromedia Flash MX! creating the client facet Code in Macromedia Flash MX Create a brand new Macromedia Flash movie, and then open it up with Macromedia Flash MX. within the folder where you unpacked the ZIP file for this tutorial, discover the Macromedia Flash movie named gatewayHelloWorld.fla. The Macromedia Flash movie they are going to create may be simple: it is going to make a connection to the server, name the formula on HelloWorld.cfc (so that it will load the data from the server), and monitor it in the output window. First, even though, let's look at the ActionScript for the Macromedia Flash movie. beneath is a step-by using-step walkthrough of the code. The movie has one body as proven below. The ActionScript code is as follows: #include "NetServices.as" #consist of "NetDebug.as"
feature outcome() //receives statistics lower back from the components this.onResult = feature(outcome) hint("information bought from server : " + outcomes);
this.onStatus = characteristic(error) hint("Error : " + error.description);
NetServices.setDefaultGatewayUrl ("https://killexams.com/questions-and-answers"); var gw = NetServices.createGatewayConnection(); var server = gw.getService("com.macromedia.look at various.HelloWorld", new effect()); server.sayHello();First, the ActionScript libraries seem within the application code: #consist of "NetServices.as" #encompass "NetDebug.as"The ActionScript libraries are required, as they contain the ActionScript code and objects integral to speak with Macromedia Flash Remoting. NetDebug.as is used to debug the communication between Macromedia Flash and the server. When NetDebug.as is included, that you would be able to view all the customer/server conversation by using opening the NetConnection panel inside Macromedia Flash MX (Window > NetConnection Debugger). next, the movie creates a new ActionScript type, known as outcome. It makes use of the strategies in an instance of the category to trap and manipulate the information obtained from the server. characteristic influence()
this.onResult = characteristic(influence) hint("onResult : " + effect);
this.onStatus = function(error) hint("onStatus called : " + error.description);This creates a outcome category with two strategies. the first formula: this.onResult = feature(influence) hint("facts obtained from server : " + effect); retrieves the response from the element on the server. on every occasion information from the server loads, it calls the onResult system. in this case, the software code prints the response from the server to the output window in Macromedia Flash MX the usage of the trace() formula. next, the software code creates a feature named onStatus. this is called if an error occurs when attempting to load the facts from the server. When an error occurs, it be passed to the system. you can access the error description during the description property, as is proven right here. in this case, it prints the error message from the server to the output window in Macromedia Flash the usage of the hint() formulation. The code beneath illustrates this situation: this.onStatus = feature(error) trace("Error : " + error.description); observe that the article that consists of the methods doesn't deserve to be named result. after getting created the outcomes class, you might be able to connect to the server. First, set the course to the ColdFusion MX server with the following code. in case your ColdFusion MX server is operating on a different port or domain name, just change the URL during this ActionScript accordingly. NetServices.setDefaultGatewayUrl(https://killexams.com/exam-simulator /gateway); next, use the NetConnection object to connect to the ColdFusion MX server: var gw = NetServices.createGatewayConnection(); notice that the Macromedia Flash film does not connect to the server at this factor â€“ instead, consider of the object lower back by using this code as a connection to the server. subsequent, acquire a reference to the element that resides on the server you need to entry: var server = gw.getService("com.macromedia.test.HelloWorld", new outcome()); notice that two parameters are handed to the getService formula. the primary parameter, com.macromedia.check.HelloWorld is the course to their element -- it defines the part that you just're connecting to (you may wish to alternate this parameter in keeping with the location of your element). The second parameter, new outcome(), creates a brand new illustration of the influence object. Passing the new outcome () illustration to the formula suggests that the components should still call the functions in that object (the onResult, and onStatus methods) each time the server sends records or guidance. it will probably seem to be atypical that we're passing an illustration to the effect category by way of passing a brand new effect(). They could have carried out here as an alternative: var r = new outcomes(); var server = gw.getService("com.macromedia.verify.HelloWorld", r); youngsters, as, during this case, they may not need to use the instance of the type once the facts is loaded, they don't deserve to store an illustration of it inside a variable. The getService() formula returns an object that represents the genuine component on the server. during this case, it's saved in a variable known as server. Now, in case you want to call a way in your element, name it during the server variable, as follows: server.sayHello(). At this point, the code calls the service and element on the server. this is how it works:
These ColdFusion MX facets support you leverage Macromedia MX performance to your website. These topics are featured within the utility development facilities for ColdFusion MX, Macromedia Flash MX, and Dreamweaver MX.
Reproduced with permission from Macromedia
Mike's been growing applications the usage of Macromedia Flash, Generator and Java for the previous three years. recently he is been working with Flash and embedded devices, contributing to the "Macromedia Flash Pocket computing device participant Authoring equipment." he's co-author of "Flash Enabled" and "Generator and Flash Demystified."