background image

Using the Flash Remoting ActionScript API in the CustomerInfoExampleAPI application

51

Establishing the connection in the HTML file enables you to change it without needing to 
republish the application. 

After creating the 

custService

 Service object, 

CustomerInfoFormAPI()

 calls the c

ustService.

getCatergories()

 function to retrieve a record set of all categories, sets the alignment for the 

Total Sales label on the DataGrid component, and assigns a RelayResponder object to the 

responder

 property of the 

pc

 PendingCall object for the call to 

getCategories(). 

The 

RelayResponder specifies the object (

this

), the result handling method (“

onCategoryData

”), 

and the fault handling method (“

onCategoryFault

”) that will handle the result or fault 

condition returned by the 

getCategories()

 function. RelayResponder calls 

addEventListener()

 to register the 

onReveal()

 method, the method to call when a 

reveal

 

event occurs.

onReveal()

The 

onReveal()

 function performs initialization tasks for the CustomerInfoFormAPI class if the 

initialization

 variable is not equal to 

true

. These tasks include defining the columns (

"ID"

"Active"

"Name"

, and "

TotalSales"

) for the DataGrid component that displays the customer 

information returned from the customer’s database. The next line, shown here, registers the 

onCustGrid_Change()

 function as the event handler to be called if a change occurs in the 

customers_grd

 DataGrid component.

customers_grd.addEventListener( "change", onCustGrid_Change );

Next, the 

onReveal()

 function aligns text for the Total and the Total Sales labels and sets the 

initialized

 variable to 

true

.

updateDetails()

The 

updateDetails()

 function updates the data displayed in the Customer Details section 

when the customer selected in the DataGrid component changes. This information includes the 
customer description, the Total Sales amount, and the logo. This function is called by the 

onCustGrid_Change()

 function.

refreshCustomerData()

The 

refreshCustomerData()

 function calls the 

getCustomers()

 function of the customerData 

service (referenced as 

custService

) to retrieve the customers for the selected item in the 

Category ComboBox component.

This function calls the RelayResponder constructor to establish the 

onCategoryData()

 function 

as the function to receive the results of this call, and the 

onCategoryFault()

 function as the 

function to receive an error or fault condition.

onCustGrid_Change()

The 

onCustGrid_Change()

 function is the event handler that is called when the selection in the 

DataGrid component changes. This function calls the 

NetDebug.trace()

 function to 

documents the call to this function. Then it calls the 

updateDetails()

 function to update the 

Customer Details section.

Summary of Contents for FLASH REMOTING MX

Page 1: ...Using Flash Remoting for Flash MX 2004 ActionScript 2 0...

Page 2: ...ncluding internationally Third Party Information This guide contains links to third party websites that are not under the control of Macromedia and Macromedia is not responsible for the content on any...

Page 3: ...Script 2 0 22 Making the minimum changes to your application for ActionScript 2 0 22 Taking full advantage of Flash Remoting for Flash MX 2004 ActionScript 2 0 23 Migrating the DataGrid application to...

Page 4: ...ector in the CustomerInfoExampleCon application 57 onReveal 60 updateDetails 61 onCustGrid_Change 61 onCustomerData 61 onCategoryData 61 onCustomerDataFault 61 onCategoryDataFault 61 CHAPTER 4 Using F...

Page 5: ...termining the Flash service name 105 Returning results to ActionScript 106 Passing parameters to ColdFusion components 106 Accessing ActionScript objects 108 Using component metadata with the Flash Re...

Page 6: ...ng an XML object from Java to Flash 141 Viewing Flash Remoting log entries 141 CHAPTER 8 Using Flash Remoting for Microsoft NET 143 Flash Remoting for Microsoft NET 143 Where Flash Remoting fits into...

Page 7: ...setDefaultGatewayUrl method 164 Authenticating a user to the application server 165 Creating the service object 166 Handling results for a Connection object 167 Directing all results for a service to...

Page 8: ...8 Contents...

Page 9: ...ho have previous experience with Flash MX or Flash MX 2004 and an application server including Macromedia ColdFusion MX Java or Microsoft NET If you are not familiar with Macromedia Flash MX or Macrom...

Page 10: ...s a new component that allows you to work directly with the new data binding features in Flash MX 2004 Professional Simply drag the RemotingConnector onto the Stage and use the Component inspector to...

Page 11: ...2 0 on page 22 Developer resources Macromedia is committed to setting the standard for customer support in developer education documentation technical support and professional services The Macromedia...

Page 12: ...velopment including online discussion groups Knowledge Base technical papers and more www macromedia com go devnet Macromedia Alliance Connection with the growing network of solution providers applica...

Page 13: ...s channel between Flash applications and remote services Remote services consist of application server technologies such as JavaBeans a Macromedia ColdFusion component or page an ASP NET page or a web...

Page 14: ...vice in ColdFusion MX Depending on the application server platform Flash Remoting on the server contains a series of filters that perform logging error handling and security authentication as well as...

Page 15: ...model represents the data of an application and the processing of that data and other logic In a web application this typically consists of the application server program and the database View The vie...

Page 16: ...nguages ActionScript and the programming language of your application server Therefore building Flash applications with Flash Remoting demands knowledge of at least two different development environme...

Page 17: ...ort mx remoting Service import Service class import mx rpc FaultEvent import FaultEvent class import mx remoting PendingCall import PendingCall clsas import mx rpc ResultEvent import ResultEvent class...

Page 18: ...t to your remote services To connect to a service by writing ActionScript code 1 From the Window menu in Flash select Other Panels Common Libraries Remoting 2 From the Library panel drag the RemotingC...

Page 19: ...services using Flash Remoting 1 In the Flash authoring environment create a new Flash file and save it as serviceTest fla 2 Drag the RemotingClasses library onto the Stage as described in Connecting...

Page 20: ...e service what methods handle result and fault conditions pc responder new RelayResponder this serviceFunctionName_Result serviceFunctionName_Fault function serviceFunctionName_Result result ResultEve...

Page 21: ...ck functions named serviceFunctionName_Result or serviceFunctionName_Fault If the call to the service function succeeds the _Result function is called and it processes the result If the service functi...

Page 22: ...your application for ActionScript 2 0 1 Drag the RemotingClasses library to the Stage as described in the section Connecting to a service on page 18 If you use the NetDebug class in your program you m...

Page 23: ...4 returned true The Object constructor property must appear only on prototype objects 8 Change calls to the NetServices setDefaultGatewayURL function to NetServices setDefaultGatewayUrl Note the case...

Page 24: ...the new Remoting API Do not use Flash MX components Make sure your code is consistent in the use of uppercase and lowercase characters ActionScript 2 0 is case sensitive The DataGrid example uses Flas...

Page 25: ...tablish a reference to a remote service and set up a Responder object to call for result handling and fault handling The old version of the program calls three functions to accomplish these tasks NetS...

Page 26: ...ibes an alternate way to create a reference to a service in the new API 6 Invoke a service method and establish result and fault handler methods Old API invoke a service method catalogService getCateg...

Page 27: ...on The example uses this approach using a RelayResponder object to specify the result handling and fault handling methods for the getCategories service function 7 Register a listener for the combo Com...

Page 28: ...date the details TextArea gridChange new Object gridChange change function evt when the selectedIndex changes in DataGrid a change event will be fired The details should be updated details text evt ta...

Page 29: ...pter also contains two extended examples CustomerInfoExampleAPI and CustomerInfoExampleCon that are different versions of the same application The CustomerInfoExampleAPI example uses the Flash Remotin...

Page 30: ...e As with web services and RPCs data from the remote service is converted from the native data type of the remote service such as a Java or C data type to a representation that is used to transfer the...

Page 31: ...Service import mx services Log import mx rpc RelayResponder import mx remoting PendingCall import mx remoting RecordSet import mx rpc ResultEvent import mx rpc FaultEvent Remove the slashes in the fol...

Page 32: ...h components such as ListBox or ComboBox that have labels with associated data The DataGlue bindFormatStrings and DataGlue bindFormatFunction methods specify a RecordSet object to use to populate the...

Page 33: ...about the record set sort the record set define an object to receive notifications when the record set changes and set the way the record set is delivered from the server For more information on usin...

Page 34: ...nnections and services Connection addHeader call clone close getService setCredentials trace Log onlog RemotingConnector gatewayUrl serviceName methodName multipleSimultaneousAllowe d suppressInvalidC...

Page 35: ...lumnNames items length addItem addItemAt clear contains filter getColumnNames getEditingData getItemAt getItemID getIterator getLength getLocalLength getNumberAvailable getRemoteLength isEmpty isFully...

Page 36: ...thout first importing the class you can add the following statement to your code before creating a connection mx remoting debug NetDebug initialize import mx remoting NetServices Deprecated Methods in...

Page 37: ...create an instance of a RemotingConnector component For more information see Flash Remoting ActionScript classes on page 32 Create a Service object creating a gateway at the same time that you create...

Page 38: ...nternet Explorer specify the gateway URL as a flashvars parameter in an HTML PARAM tag inside the OBJECT tag body To specify the gateway for Netscape specify the gateway URL as a flashvars attribute t...

Page 39: ...e ways that you can specify service names for the supported service types Service type Service name Example Web services accessed through ColdFusion or NET servers URL of the WSDL file for the service...

Page 40: ...you can call the setCredentials method any time after creating the gateway connection object If you created the gateway object using the Service object you can access the connection object through th...

Page 41: ...oldFusion see Securing access to ColdFusion from Flash Remoting on page 116 Using authentication in JRun 4 Authentication in JRun 4 is only meaningful for EJBs where you can use the setCredentials met...

Page 42: ...ervice connection setCredentials myUserName myPassword call service function var temp_pc PendingCall petMarketService getCategories en_US getCatergories_Result and getCategories_Fault are result fault...

Page 43: ...service or for specific server function calls In both cases you specify a responder object The responder object can be any ActionScript object that implments the mx rpc Responder interface The Respon...

Page 44: ...t specify a RelayResponder object for the responder parameter when you create the Service object For example the responder parameter which is the last parameter of the following Service constructor sp...

Page 45: ...etMarketService object The return value is a PendingCall object temp_pc The code assigns a RelayResponder object to the responder property of temp_pc The constructor for the RelayResponder object spec...

Page 46: ...Name ID custCat_cmbo addEventListener change onCustCat_Change refreshCustomerData For more information about the ResultEvent class see the ResultEvent class in Flash Remoting ActionScript Dictionary H...

Page 47: ...Files Macromedia Flash MX 2004 en First Run RemotingSamples Server See the Readme htm and RemotingCustomerExamplesWalkthrough htm files in the RemotingSamples folder for information on how to set up...

Page 48: ...TextArea import mx remoting DataGlue import mx screens Form import mx controls TextInput import mx controls Label import mx controls Loader import mx controls Alert class CustomerInfoFormAPI extends...

Page 49: ...nt category selected function refreshCustomerData Void var pc PendingCall custService getCustomers custCat_cmbo selectedItem data pc responder new RelayResponder this onCustomerData onCustomerDataFaul...

Page 50: ...rt OK this mx remoting debug NetDebug trace level None message There was a problem fault fault faultstring private var custService Service private var customers_grd DataGrid private var custCat_cmbo C...

Page 51: ...e The next line shown here registers the onCustGrid_Change function as the event handler to be called if a change occurs in the customers_grd DataGrid component customers_grd addEventListener change o...

Page 52: ...in the current category onCustomerData The onCustomerData function handles the results of the call to the custService getCustomers function in the refreshCustomer function This function assigns the r...

Page 53: ...applications of data binding are to gather input parameters from various UI components to send to a service function and to display the results of a service function call You can find the RemotingCon...

Page 54: ...ema you can bind the items to a variety of UI controls to provide values for the parameters or to display the results of the web service For more information see Working with schemas in the Schema tab...

Page 55: ...f this component to share a single connection as long as they all use a common gatewayUrl suppressInvalidCalls Boolean Advanced If this parameter has the value true the trigger function does not perfo...

Page 56: ...ton a Select the Params Object item in the Schema tab b Select the Add Field button and set the field name property to state There is no need to change String as the default data type c Select the Par...

Page 57: ...folder for information on how to set up and use this sample application You can access the Flash and ActionScript files for this example in the Client subfolder if you want to make changes to it The...

Page 58: ...l initializes the display function onReveal Void initialize stuff if initialized var col DataGridColumn new DataGridColumn ID customers_grd addColumn col col new DataGridColumn Active col width 80 cus...

Page 59: ...essage onCustGrid_Change eventObj target _parent updateDetails handles the result of the call to the getCustomers service function function onCustomerData re Object Void _parent customers_grd selected...

Page 60: ...nitial call to the onReveal method which performs initialization tasks for this class The addEventListener function registers the onReveal method as the event handler for a reveal event onReveal The o...

Page 61: ...to update the Customer Details section onCustomerData The onCustomerData function handles the results of a request to retrieve Customer data and populate the DataGrid component It sets the selection...

Page 62: ...62 Chapter 3 Using the RemotingConnector component Flash Professional only...

Page 63: ...t on page 64 Converting from ActionScript to application server data types on page 65 Converting from application server data types to ActionScript on page 67 ColdFusion to ActionScript data conversio...

Page 64: ...or the ActionScript object model Using AMF Flash Remoting encodes data types back and forth between the Flash application and the remote service over HTTP Modeled on the Simple Object Access Protocol...

Page 65: ...C data type Converted Visual Basic data type Converted SOAP data type Converted ColdFusion MX data type null null null Nothing null null not defined ColdFusion uses a null value internally but report...

Page 66: ...shgateway io ASObject FlashGateway IO ASObject FlashGateway IO ASObject Complex type For a CFML page the Flash scope with the object key names being the scope variables For more information see Using...

Page 67: ...associative arrays In these cases it converts the numeric indexes to keys with numbers as the strings for example 0 1 2 Converting from application server data types to ActionScript Flash Remoting aut...

Page 68: ...Pageable ResultSet Paged RecordSet FlashGateway IO ASObject System Exception FlashGateway IO ASObject System Exception Complex type A Java object as listed in the next column flashgateway i o ASObject...

Page 69: ...dFusion data and ActionScript data Boolean data in ColdFusion If a ColdFusion page or CFC returns Boolean values it represents these values as strings Flash does not have rules for converting strings...

Page 70: ...etNumber access remote cfset foo Val 2 cfreturn foo cffunction If you call either of these getNumber functions from Flash the ActionScript getNumber_Result function in the previous example displays th...

Page 71: ...lass myClass extends Object myClass super value1 Test1 Register the class definition Object registerClass testClass myClass public var value1 String Send instance of registered class to a Flash Remoti...

Page 72: ...CFML code is the equivalent to the Java code cffunction access remote name getFlashObject cfobject type JAVA class flashgateway io ASObject name myOb action CREATE cfset myobj setType MyFlashObject cf...

Page 73: ...by explicitly calling the getMessage method but directly from the properties returned from the Flash gateway on the server About working with RecordSet objects Using Flash Remoting you can return Reco...

Page 74: ...a structures for use in Flash UI Components For more information on using RecordSet methods see RecordSet methods on page 75 You access record set rows using the row index much like in an array Record...

Page 75: ...columns of a RecordSet object RecordSet getIemAt Returns a record if the index is valid and the record is available RecordSet getItemID Returns the record ID of a record RecordSet getIterator Returns...

Page 76: ...the getItemAt method For example the following line gets the third record in a record set myRecord myRecordSet getItemAt 2 To get the value of a specific field in a record use the column name as a pro...

Page 77: ...tion RecordSet contains Indicates whether the record set contains the specified record RecordSet getColumnNames Returns an array of the names of the columns of a RecordSet object RecordSet getItemID R...

Page 78: ...ject you use the replaceItemAt method To replace a specific field in a record in a RecordSet object use the editField method For example the following code replaces the contents of the third record in...

Page 79: ...perty are addItems allRows fetchRows sort removeItem removeItems and updateItems Depending on the value of eventName the following properties might provide additional information firstItem lastItem re...

Page 80: ...es In this example cust_ListBox represents a ListBox UI component in the Flash application In the rs sortItemsBy method it sorts the records according to the contents of the TotalSales column in desce...

Page 81: ...ordSet object The Contact_grid component s dataProvider property receives a filtered copy of myRecordSet object generated by the myRecordset filter method as the data for the contact_grid ListBox Note...

Page 82: ...g RecordSet service page When you use the getItemAt method to access a record the RecordSet object fetches data one or more pages at a time You specify the number of records per page when you set the...

Page 83: ...abel and data information These components use Flash DataProvider objects to supply the following information Label values that appear to the user Corresponding data values that are available by using...

Page 84: ...consumer The function must take a record as an argument and returns an object that consists of two entries a label field and a data field The function has full flexibility in using the record contents...

Page 85: ...ication uses ActionScript XML objects and methods to generate and manipulate XML as needed Your decision as to which method to use should depend on whether it is preferable in your environment to do m...

Page 86: ...t2_txt text firstElement appendChild secondElement xmlDocument appendChild firstElement Call the service function and pass it the XML document trace xmlDocument Result Handler to handle the results re...

Page 87: ...applications you use the NetConnection Debugger in the Flash authoring environment The NetConnection Debugger shows calls and responses from the following software components Flash Player Flash Remot...

Page 88: ...ebug class at the beginning of the ActionScript code for your Flash application import mx remoting debug NetDebug 4 Call the NetDebug initialize method at the beginning of your code prior to establish...

Page 89: ...emoting application 1 Press Control L to open the Library panel 2 Select the RemotingDebugClasses library and delete it 3 Remove debugging statements from your code in the Actions panel if you like Th...

Page 90: ...on Server uses RTMP Flash Remoting does not use RTMP The default value is true app_server Information about events on the application server This category includes activities reported by the server it...

Page 91: ...n Server events This option is not used for debugging Flash Remoting applications The default value is true Note The user interface uses the term flashcomm_server In ActionScript you must use realtime...

Page 92: ...s method HeaderName The type of header being sent such as Credentials MustUnderstand A Boolean value that specifies whether the server must understand and process this header before the server can han...

Page 93: ...emoting client This event occurs for each HTTP request AmfHeaders The contents of the AMF headers sent in the response if any The gateway returns a header if the client does not support cookies and UR...

Page 94: ...tion event For more information on ColdFusion debugging information see Developing ColdFusion MX Applications with CFML Flash Communication Server events If you enable Flash Communication Server flash...

Page 95: ...he NetDebug initialize method see the NetDebug class in the Flash Remoting ActionScript Dictionary in Help For information about the CustomerInfoExampleAPI sample application see Using the Flash Remot...

Page 96: ...ript to display debugger output For information on using the Filters panel see Flash Help In ActionScript you configure NetConnection Debugger output for each connection individually As a result if yo...

Page 97: ...ActionScript on page 111 Calling web services from Flash Remoting on page 115 Securing access to ColdFusion from Flash Remoting on page 116 Handling errors with ColdFusion on page 117 Using Flash Rem...

Page 98: ...elloWorld_Fault To specify subdirectories of the web root directory or a virtual directory use package dot notation If helloWorld cfm is in the directory web_root helloExamples ColdFusion you can use...

Page 99: ...access these parameters using Flash Params as follows cfset p1 Flash Params 1 cfset p2 Flash Params 2 cfset p3 Flash Params 3 The following ActionScript code calls a ColdFusion page to execute a quer...

Page 100: ...y array1 0 zero array1 1 one myService myMethod array1 You access the elements in the array in your ColdFusion page using ColdFusion array notation as follows cfset arrayElement1 Flash Params 1 1 cfse...

Page 101: ...rray new Array struct1 zero banana struct1 one orange myService myMethod x array1 y struct1 Collection ActionScript example Notes Strict array var myArray Array new Array myArray 0 zero myArray 1 one...

Page 102: ...record set returned from a ColdFusion query For more information about converting data types between ColdFusion and Flash see Chapter 4 Using Flash Remoting Data in ActionScript on page 63 The followi...

Page 103: ...urrent date function helloWorld_Fault fe FaultEvent Void Within the result handler of the helloWorld method you access the structure returned by ColdFusion Returning record sets to Flash A Flash appli...

Page 104: ...box Returning record sets in increments ColdFusion lets you return record set results to Flash in increments For example if a query returns 20 records you can set the Flash Pagesize variable to retur...

Page 105: ...returned to a Flash list box the list box requests more rows as the user scrolls through the list box Using Flash Remoting with ColdFusion components ColdFusion components require little modification...

Page 106: ...sets in increments from a component The component executes once and returns all the results to the Flash Remoting gateway The Flash application then requests subsequent records from the gateway as req...

Page 107: ...ers Collection ActionScript example Notes Strict array var myArray Array new Array myArray 0 zero myArray 1 one myService myMethod myArray The Flash Remoting service converts the array argument to a C...

Page 108: ...e Flash application 3 Save the file The following ActionScript example calls this function import mx remoting Service import mx remoting PendingCall var CFCService Service new Service http localhost f...

Page 109: ...se it is split into named arguments However an ActionScript array does not Passing objects from ActionScript lets you use the Arguments scope within a component function The Arguments scope works the...

Page 110: ...ent In this example the description attribute of the cffunction tag supplies a short text description of the component method 2 Save the file 3 Open the Flash authoring environment and open the Servic...

Page 111: ...r side ActionScript function definition returns a RecordSet object function basicQuery var mydata CF query datasource customers sql SELECT FROM myTable return mydata Using CF http The CF http ActionSc...

Page 112: ...Boolean value that indicates whether the specified URL location contains text data Charset The character set used by the document specified in the URL HTTP servers normally provide this information or...

Page 113: ...The positional argument approach supports a subset of CF http arguments but it lets you code in a more succinct and efficient style The schema for the positional argument style is as follows CF http u...

Page 114: ...ments it allows a more compact coding style that is appropriate for simple expressions of the CF query function The CF query function accepts the following arguments using the named argument style CF...

Page 115: ...e complexity associated with programming web services is removed Invoking web service methods using Flash Remoting The following example shows an example of a Service constructor for accessing a web s...

Page 116: ...just as you control access to any ColdFusion page In this way you can grant Flash applications access to only selected ColdFusion code ColdFusion security is based on a username and password Flash Re...

Page 117: ...les admin manager cfargument name filepath required yes cffile action DELETE file arguments filepath cffunction cfcomponent In the example the cffunction tag includes the roles attribute to specify th...

Page 118: ...fset tag fails because it causes a divide by zero error The message attribute of the cfthrow tag describes the error ColdFusion returns this attribute to the Flash application For more information on...

Page 119: ...ensions JMX MBeans available in Macromedia JRun 4 only Macromedia JRun 4 also lets you call functions on server side ActionScript which can in turn call methods on server side Java objects This chapte...

Page 120: ...dapters for JavaBeans Java classes EJBs JMX MBeans and server side ActionScript Where Flash Remoting fits into the Java application architecture A design pattern is a solution to a recurring problem M...

Page 121: ...un com blueprints patterns j2ee_patterns session_facade index html Calling Java classes or JavaBeans from ActionScript This section describes how to call a JavaBean or Java class from Flash using Flas...

Page 122: ...ge 37 Application server Classpath information Sun ONE Web Server In the Web Server Administration Server console add classes to the Classpath field in the Configure JVM Attributes page of the Java pa...

Page 123: ...ons The first parameter this specifies that the results of the service function call are returned to those methods in this object If the result handling methods were contained in a different object yo...

Page 124: ...blic class FlashJavaBean implements Serializable private String message private int count public FlashJavaBean message Hello World From JavaBean count 0 public boolean testBoolean boolean b return b p...

Page 125: ...rt mx rpc import mx controls class init_Categories extends mx screens Form function init_Categories super mx remoting debug NetDebug initialize initialize the debugger establish the gateway and obtain...

Page 126: ...Message_Result setMessage_Fault function getMessage var gm_pc PendingCall flashtestService getMessage gm_pc responder new RelayResponder this getMessage_Result getMessage_Fault function testBoolean if...

Page 127: ...sultEvent Void boolOutput text result re result function testBoolean_Fault fe FaultEvent Void boolOutput text status fe fault faultstring function testDate_Result re ResultEvent Void flashDate re resu...

Page 128: ...a period Note There are several other ways to specify the gateway URL For more information see Chapter 2 Configuring Flash Remoting on page 36 Invoking EJB methods in ActionScript Unlike JavaBeans and...

Page 129: ...mber principalInput text number monthsInput text number rateInput text cal_pc responder new RelayResponder this calculate_Result calculate_Fault To handle the function results you use a result handler...

Page 130: ...sivate throws RemoteException public void setSessionContext SessionContext context throws RemoteException sessionContext context public double calculate double principal int months float rate if rate...

Page 131: ...is create_Result create_Fault Business Methods Calculate payment based on data user enters in principalInput monthsInput and rateInput text fields Function arguments must be numbers Java method expect...

Page 132: ...FlashServlet class and implement the following abstract method public Object service ServletRequest req ServletResponse resp List arguments Getting a reference to a web application in ActionScript Bef...

Page 133: ...tion servers you can define a JSP as a servlet by specifying a JSP filename in a JSP file element rather than a servlet class in a servlet class element Request arguments sent from Flash as parameters...

Page 134: ...t Service constructor Service functions are methods defined in the MBean s manageable interface The following sections describe how to get a reference to a JMX MBean object and call its methods To gra...

Page 135: ...example you could use the following ActionScript code to invoke the getEARs method of the jrunDeployerMBean MBean to get a list of JMX object names for deployed enterprise applications function getEAR...

Page 136: ...and name of the ASR file relative to a web application context root In this example flash is the context root of the web application script is a directory under the context root and FlashSample is th...

Page 137: ...and private properties are available as ActionScript properties For example the following method in a Java class called Loan calculates loan payments and returns an instance of a JavaBean called LoanI...

Page 138: ...blic LoanInfo double principal int months float rate double monthlyPayment String message this principal principal this months months this rate rate this monthlyPayment monthlyPayment this message mes...

Page 139: ...ly the EJB adapter supports authorization After a user is authenticated the user s role is associated with any EJBs the user may access and the security permissions established in EJB deployment descr...

Page 140: ...XML objects For more information about ActionScript XML objects see the Flash documentation set For more information about the Java org w3c dom Document interface see the Java 2 Platform Standard Edi...

Page 141: ...xt contained in the first child element of the XML document root is displayed in a Flash dynamic text field called output The text matches whatever text the user initially entered in the Flash text fi...

Page 142: ...142 Chapter 7 Using Flash Remoting for Java...

Page 143: ...SP NET pages web services and assembly methods A Flash developer writes ActionScript that uses a library of functions to connect to a remote NET server get a reference to the remote service and invoke...

Page 144: ...nctionality To assist you in planning your Flash applications a design pattern represents a solution to a frequently experienced problem and provides a way to standardize coding practices across a com...

Page 145: ...ontext in the application This pattern reduces network traffic and makes it easier to support different types of clients change the enterprise data model or change the server implementation For more i...

Page 146: ...d application for you named flashremoting You can find the flashremoting folder in your IIS webroot such as C Inetpub wwwroot flashremoting When creating the directory structure for your own ASP NET a...

Page 147: ...xample if the page was called GetResources aspx and the web root folder for your installation was C Inetpub wwwroot you would find the GetResources page in the following location C Inetpub wwwroot fla...

Page 148: ...erence to the ASPX page you can use ActionScript functions to invoke it For example the following ActionScript code invokes the ASPX page GetResources aspx assuming that aspxService represents your re...

Page 149: ...addition to passing simple strings you can write code in a NET supported language that accesses parameters passed from Flash and returns processed results to Flash The Flash Remoting custom server co...

Page 150: ...ctive references a code behind file myASPPage aspx vb Using the Flash Remoting namespace in code behind files In ASP NET applications you can separate business logic from user interface code using cod...

Page 151: ...ash Remoting Flash Remoting supports ASP NET cookie based state management which maintains a user session using HTTP header information Flash Remoting maintains the session ID automatically by passing...

Page 152: ...e Using ASP NET exception handling To return custom ASP NET exceptions to Flash you use the throw statement You can throw exceptions in the context of a try catch statement an if else statement and so...

Page 153: ...pen create the SQL statement String selectCountry SELECT DISTINCT Country FROM Customers ORDER BY Country ASC query the database SqlDataAdapter countryAdapter new SqlDataAdapter selectCountry sqlConne...

Page 154: ...Page_Load method definition in a code behind file that performs the same operation as the previous code example Private Sub Page_Load ByVal sender As System Object ByVal e As System EventArgs Handles...

Page 155: ...moting custom server control using the Flash DataBind method and returned to Flash Displaying a RecordSet object in Flash with ActionScript To display a RecordSet object in a Flash UI component you ca...

Page 156: ...local web service proxy to interact with web services After you create the proxy the ActionScript in your Flash application can then invoke web service methods through the proxy which handles sending...

Page 157: ...ing makes web services easy To call this method in ActionScript you use the method name in the context of the flashService Service object as the following ActionScript example shows flashService getMe...

Page 158: ...vice As with local web services Flash interacts with remote web services by using the NET framework s WSDL Tool wsdl exe to create web service proxies dynamically in the form of assemblies with the dl...

Page 159: ...use an assembly or class method name On the server you must place your DLL and class files in the local assembly cache Calling assemblies from Flash In the class file you specify the using directive...

Page 160: ...can describe the data being passed with the ASType property of the ASObject class The following sections describe both how to create and populate the custom ActionScript object from the server and how...

Page 161: ...ar dataService Service new Service http localhost flashremoting gateway aspx null FlashRemoting ObjectTests ObjectClass null null Ask the server for some raw data var pc PendingCall dataService return...

Page 162: ...1 Registration The following table lists the Flash Remoting registry keys Registry key Description Log File Size Maximum number of bytes that the flash log file can reach before Flash Remoting stops...

Page 163: ...ng the Service object For more information see the Service class in Flash Remoting ActionScript Dictionary Help To create a Flash Remoting Connection object you first specify the gateway URL and then...

Page 164: ...to configure a connection to a specific gateway For example import mx remoting Connection import mx remoting NetServices farther in the application var gatewayConnection Connection NetServices create...

Page 165: ...user authentication a user name and password before you can use a service Flash Remoting provides the setCredentials method of the Connection class to allow you to specify authentication credentials...

Page 166: ...ion on considerations for specifying a Flash responder see Handling results for a Connection object on page 167 The following example shows the getService method for the remoteservices service which c...

Page 167: ...der object to receive the results howdyService gatewayConnection getService remoteservices new HelloResponder responder You can direct results to a specific method in the result handler by providing a...

Page 168: ...ce howsItGoin uses default result handler Directing results for a service to specific responder objects You can also specify a responder object to handle the results of a specific service function To...

Page 169: ...ject can be used for multiple service functions function general_Result this onResult function result trace result is result call service functions howdyService helloWorld new helloWorld_Result howdyS...

Page 170: ...service function call Flash Remoting returns the status to that object s onStatus method When you use this technique the responder object must also have an onResult method to handle the result 3 If th...

Page 171: ...on fails due to a time out it might be appropriate for the Flash application to try the request a second time If the request fails a second time the SWF file could then display a message to the user a...

Page 172: ...ect can be used for multiple service functions function general_Result this onResult function result trace result is result this onStatus function error trace result is error description call invalid...

Page 173: ...ervice 16 AddHeader client event message 92 ADO NET objects using with Flash Remoting MX 153 AMF debugging messages 90 understanding 64 amf app_server event type 90 amfheaders app_server event type 90...

Page 174: ...methods 34 RecordSet 33 RelayResponder 33 RemotingConnector 33 Service 33 client event type 90 NetConnection Debugger event messages 92 Close client event message 92 code behind files using the Flash...

Page 175: ...18 using RemotingConnector 18 controller model view controller pattern 15 createGatewayConnection NetServices object method specifying gateway in 164 credentials resetting 41 165 custom server contro...

Page 176: ...ation structure 30 architecture 14 building Flash applications with 16 building the Flash application 19 configuring 36 custom server control using in ASPX pages 149 development environment 16 for NET...

Page 177: ...classes 35 incremental record sets 104 Information app_server event message 93 Internet Explorer gateway for 38 J Java converting data to ActionScript 67 converting data types from ActionScript 65 Fla...

Page 178: ...tion 33 importing 36 notifications using with RecordSet objects 78 numeric data in ColdFusion 70 O objects using in Flash Remoting applications 70 P pageable record sets 82 104 PendingCall class descr...

Page 179: ...rs 54 using 53 57 RemotingConnector componen usingt 53 RemotingDebugClasses library accessing 30 RemotingSamples folder 47 57 Result client event message 92 result handler example 31 relationship to s...

Page 180: ...vent type 90 Flash Communication Server event type 91 NetConnection object method 96 NetDebug object method 95 Trace client event message 92 typed objects using ActionScript 71 U URL determining the g...

Reviews: