Summary of FLASH REMOTING MX-USING FLASH REMOTING FOR FLASH MX 2004 ACTIONSCRIPT 2.0

  • Page 1

    Using flash remoting for flash mx 2004 actionscript 2.0

  • Page 2

    Trademarks add life to the web, afterburner, aftershock, andromedia, allaire, animation powerpack, aria, attain, authorware, authorware star, backstage, bright tiger, clustercats, coldfusion, contribute, design in motion, director, dream templates, dreamweaver, drumbeat 2000, edje, ejipt, extreme 3d...

  • Page 3: Contents

    3 contents introduction: about flash remoting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 who should read this book . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 about flash remoting documentation . . . . . . . . . . . . . . . . . . . ....

  • Page 4

    4 contents handling service results and errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 using the relayresponder object for a service . . . . . . . . . . . . . . . . . . . . . . . . . 44 using pendingcall and relayresponder objects for a specific service function . ...

  • Page 5

    Contents 5 chapter 5: the netconnection debugger . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87 using the netconnection debugger . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87 enabling debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ....

  • Page 6

    6 contents calling enterprise javabeans (ejbs) from flash. . . . . . . . . . . . . . . . . . . . . . . . . . 128 getting a reference to an ejbhome object in actionscript. . . . . . . . . . . . . . . 128 invoking ejb methods in actionscript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ...

  • Page 7

    Contents 7 appendix a: using netservices and connection classes . . . . . . . . . . . . . . . . 163 creating a gateway connection using the netservices object . . . . . . . . . . . . . . . . 163 specifying the gateway in the netservices creategatewayconnection() method . . . . . . . . . . . . . . . ...

  • Page 8

    8 contents.

  • Page 9: Introduction

    9 introduction about flash remoting macromedia flash remoting for flash mx 2004 actionscript 2.0 provides a communications channel between macromedia flash applications and a wide range of business logic and data from coldfusion, microsoft ® .Net, java, and simple object access protocol (soap)-based...

  • Page 10

    10 introduction: about flash remoting use the following sources to help you understand and use the tools and technologies that flash remoting encompasses. • flash mx 2004 help is the comprehensive information source for all flash mx 2004 features. To open flash mx 2004 help in your browser, either s...

  • Page 11

    Developer resources 11 ■ a new connection class that helps you create and use flash remoting connections. Note: the connection class supersedes the former netconnection class. ■ a new pendingcall object returned on each call to a service method that is invoked using the service object. The pendingca...

  • Page 12

    12 introduction: about flash remoting one of the best ways to solve particular programming problems is to tap into the vast expertise of the flash and application server developer communities on the macromedia online forums at www.Macromedia.Com/go/flash_forum . Other developers on the forum can hel...

  • Page 13: Chapter 1

    13 chapter 1 getting started macromedia flash remoting for flash mx 2004 actionscript 2.0 is an application server gateway that provides a network communications channel between flash applications and remote services. In this chapter, you learn the basics of flash remoting, including the flash remot...

  • Page 14

    14 chapter 1: getting started • extensibility flash remoting is designed to integrate with established application design patterns and best practices to build well-designed flash applications. When compared to traditional html-based browser applications, flash applications provide unique abilities t...

  • Page 15

    About flash remoting 15 once the application server or web service satisfies the service request, it returns the result to flash remoting, which in turn encapsulates the data in an actionscript object, and returns it as an amf message to the flash application. In this example, the available seats ar...

  • Page 16

    16 chapter 1: getting started for more information about using software design patterns with flash remoting, see software design patterns for flash remoting on the macromedia website at www.Macromedia.Com/ devnet/mx/flashremoting/articles/facades.Html . Understanding the flash remoting service adapt...

  • Page 17

    Building flash applications with flash remoting 17 using flash remoting like a web browser request for an html page, a flash application that uses flash remoting connects to a remote service and makes a service function call. The service function call is a client-initiated event. The flash applicati...

  • Page 18

    18 chapter 1: getting started connecting to a service the fundamental step in using flash remoting in your flash application is connecting to a remote service. In flash remoting for flash mx 2004 actionscript 2.0, you can connect to a remote service either by using the remotingconnector component or...

  • Page 19

    Building flash applications with flash remoting 19 building the remote service flash remoting supports java, asp.Net, and coldfusion-based remote services. For a simple hello world application, the following table lists the application server code by platform and specifies where to save the file to ...

  • Page 20

    20 chapter 1: getting started 4. Highlight the text field and in the property inspector, name the text field messagedisplay and select dynamic text in the menu. 5. Open the actions panel and insert the following actionscript code, replacing variables that appear in italics with the values that corre...

  • Page 21

    Building flash applications with flash remoting 21 ■ the servicename , which is the name of the remote service. To select the appropriate value for this example, see the table that follows this section. ■ the two null values represent the connection and responder parameters, which are not used in th...

  • Page 22

    22 chapter 1: getting started migrating existing applications to flash remoting for flash mx 2004 actionscript 2.0 if you are a new flash remoting user who has not yet written any flash remoting applications, you can skip this section. If you have written flash remoting applications using actionscri...

  • Page 23

    Migrating existing applications to flash remoting for flash mx 2004 actionscript 2.0 23 5. Adjust for and adhere to case sensitivity in actionscript 2.0. Actionscript 2.0 is case sensitive. For example, myvar and myvar were treated as the same variable in actionscript 1.0 but they are treated as two...

  • Page 24

    24 chapter 1: getting started for more information on using flash remoting for flash mx 2004 actionscript 2.0 features, see chapter 2, “using flash remoting actionscript,” on page 29 and flash remoting actionscript dictionary help. For a simple example of a flash remoting application, see “building ...

  • Page 25

    Migrating existing applications to flash remoting for flash mx 2004 actionscript 2.0 25 3. In the actionscript code in the actions panel, change # include statements to import statements: // old api #include "netdebug.As" #include "netservices.As" // new api import mx.Remoting.*; import mx.Rpc.*; th...

  • Page 26

    26 chapter 1: getting started the service constructor both establishes the gateway url and creates a reference to the remote service that is being accessed. The service constructor passes the following parameters in this order: ■ the gatewayurl, which in this case is "http://localhost:8100/flashserv...

  • Page 27

    Migrating existing applications to flash remoting for flash mx 2004 actionscript 2.0 27 // maps result fields to the combobox dataprovider; name is the label // field and categoryid is the data field. Dataglue.Bindformatstrings(combo, result.Result, "#name#", "#categoryid#"); // dispatch a change ev...

  • Page 28

    28 chapter 1: getting started 8. Set up datagrid’s listener object to update 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.Target.S...

  • Page 29: Chapter 2

    29 chapter 2 using flash remoting actionscript this chapter explains how to write actionscript 2.0 code that uses macromedia flash remoting for flash mx 2004 to access application services. It explains how to configure connection information, call service functions, and handle the results that the s...

  • Page 30

    30 chapter 2: using flash remoting actionscript note: flash remoting applications require that macromedia flash player 6 (6.0.79.0), or later, is installed in the client browser. For information on how to detect the version of flash player that a user is using and how to respond accordingly, see con...

  • Page 31

    Flash remoting application structure 31 5. Configure flash remoting (create a gateway and a reference to a remote service). 6. Call service functions and pass parameters. 7. Handle the results and error status information returned to flash in result event-handler routines. The following actionscript...

  • Page 32

    32 chapter 2: using flash remoting actionscript although a more complex application might be structured differently, the preceding example shows the fundamental elements of a flash remoting application. Flash remoting actionscript classes the flash remoting actionscript classes provide methods to co...

  • Page 33

    Flash remoting actionscript classes 33 netservices (deprecated) creates a gateway connection, sets a default gateway, and establishes a connection object for the gateway. The gateway is established by the flash remoting software that resides on the application server. Use the netservices.Creategatew...

  • Page 34

    34 chapter 2: using flash remoting actionscript properties and methods the following table shows the flash remoting related actionscript classes and their properties and methods. Notice that the connection class includes methods in two categories: creating and using connections and services, and deb...

  • Page 35

    Flash remoting actionscript classes 35 importing flash remoting actionscript classes before you can import flash remoting classes in your application, you must first place the required flash remoting libraries on the stage. For more information, see “connecting to a service” on page 18 . Use the imp...

  • Page 36

    36 chapter 2: using flash remoting actionscript configuring flash remoting before you can call a remote service, you must configure flash remoting, which consists of completing the following tasks. Note: the client does not access the remote server when you configure flash remoting. The client first...

  • Page 37

    Configuring flash remoting 37 establishing the flash remoting gateway connection the specific format of the url that you use to specify the gateway depends on the application server to which you are connecting: • if you are connecting to a java server or to macromedia coldfusion mx, use the followin...

  • Page 38

    38 chapter 2: using flash remoting actionscript you use the constructor for the service class to create a new service object. The following example shows how to create a service object ( new service() ) while simultaneously creating a gateway connection (" http://localhost:8300/flashservices/gateway...

  • Page 39

    Configuring flash remoting 39 note: if you specify the flash remoting gateway in the web page, the actionscript import mx. Remoting.Service; directive must be on the flash timeline, not in a swf file. When you specify the gateway connection in a web page, you specify the gatewayurl parameter as an e...

  • Page 40

    40 chapter 2: using flash remoting actionscript for example, to create a service object for the macromedia pet market catalog web service, specify a line similar to the following: petmarketcatalogservice = gatewayconnection.Getservice("petmarket.Api. Catalogservice”, this); authenticating a user to ...

  • Page 41

    Calling service functions 41 flash supplies the login credentials with each service request; therefore, your actionscript should log the user out of the application server and reset the credentials when the user logs out of your flash application. To log out the user and reset the credentials: 1. Ca...

  • Page 42

    42 chapter 2: using flash remoting actionscript in this example, the service function passes two parameters, a language specification (en_us), and a type of category ( "accessories" ). Note: parameters must be in the order required by the service function. Import mx.Remoting.Service; import mx.Remot...

  • Page 43

    Handling service results and errors 43 note: calling web services using flash remoting is supported only in flash remoting for asp.Net and in the flash remoting support included with coldfusion mx. Flash remoting for java and the flash remoting support in jrun do not support calling web services usi...

  • Page 44

    44 chapter 2: using flash remoting actionscript if you create a relayresponder object at the time that you create a service object, the result and fault handling methods must handle the result and fault outcomes for all functions that you call on that service. Flash remoting returns a fault event in...

  • Page 45

    Handling service results and errors 45 mx.Remoting.Debug.Netdebug.Trace({level:"none", message:"there was a problem: " + fault.Fault.Faultstring }); } when you specify a relayresponder object for a service, results for all service functions are relayed to the specified result and fault handling meth...

  • Page 46

    46 chapter 2: using flash remoting actionscript handling the result object requires knowledge of the service function. The service function could return a simple string, as shown in the following helloworld_result() method: function servicefunctionname_result(result:resultevent) { // display success...

  • Page 47

    Using the flash remoting actionscript api in the customerinfoexampleapi application 47 using the flash remoting actionscript api in the customerinfoexampleapi application the customerinfoexampleapi application uses the actionscript api to connect to the customerdata remote service. This application ...

  • Page 48

    48 chapter 2: using flash remoting actionscript the actionscript code for this example imports the service, log, relayresponder, faultevent, resultevent, pendingcall, and recordset classes for flash remoting. In addition, it imports the appropriate classes for the user interface components. The appl...

  • Page 49

    Using the flash remoting actionscript api in the customerinfoexampleapi application 49 col = new datagridcolumn( "totalsales" ); col.Width = 80; col.Textalign = "right"; customers_grd.Addcolumn( col ); customers_grd.Addeventlistener( "change", oncustgrid_change ); // setup remaining totalrec_txt.Set...

  • Page 50

    50 chapter 2: using flash remoting actionscript // handles the results from the request to getcustomers() method of the service function oncustomerdata( re:resultevent ):void { // update customer grid var rs:mx.Remoting.Recordset = mx.Remoting.Recordset( re.Result ); rs.Setdeliverymode( "ondemand" )...

  • Page 51

    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. Getc...

  • Page 52

    52 chapter 2: using flash remoting actionscript the onreveal() function calls the addeventlistener() function to establish this function as the event handler for the customers_grd datagrid component . Oncustcat_change() the oncustcat_change() function is the event handler that is called when the sel...

  • Page 53: Chapter 3

    53 chapter 3 using the remotingconnector component (flash professional only) the remotingconnector component, along with the webserviceconnector component and the xmlconnector component, implements the remote procedure call (rpc) component api, which is a set of methods, properties, and events that ...

  • Page 54

    54 chapter 3: using the remotingconnector component (flash professional only) flash remoting uses the schema of a remotingconnector component to specify the characteristics of both the parameters that a remote service function requires and the results that it returns. You specify the schema values o...

  • Page 55

    55 these parameters can take the following values: parameter type category description multiplesimultaneousallowed boolean general if it has the value true , this parameter allows the trigger() method to be invoked even if results have not yet been returned from a previous invocation. If it has the ...

  • Page 56

    56 chapter 3: using the remotingconnector component (flash professional only) creating an instance of the remotingconnector component you can create an instance of the remotingconnector component in your flash application by dragging it to the stage, defining the schema, and binding the service para...

  • Page 57

    Using the remotingconnector in the customerinfoexamplecon application 57 the following section presents a sample application that uses the remotingconnector component. Using the remotingconnector in the customerinfoexamplecon application the customerinfoexamplecon application, which this section des...

  • Page 58

    58 chapter 3: using the remotingconnector component (flash professional only) the actionscript code for this example imports the remotingconnector class and the appropriate classes for the user interface components, and creates the customerinfoformcon class, which extends the form class. The section...

  • Page 59

    Using the remotingconnector in the customerinfoexamplecon application 59 categorydata_con.Trigger(); initialized = true; } } // updatedetails will update the details textarea, textinput and the // loader present on the screen changes will be updated when the selection // in datagrid changes function...

  • Page 60

    60 chapter 3: using the remotingconnector component (flash professional only) // handles the display of the fault information related to the category data // request to the user function oncategorydatafault( status:object ):void { // notify the user of the problem if( status.Code == "fault" ) { aler...

  • Page 61

    Using the remotingconnector in the customerinfoexamplecon application 61 finally, the onreveal() function calls the trigger() method for the categorydata_con remotingconnector object to connect to the service, retrieve the category data for the combobox component, and execute the data bindings to po...

  • Page 62

    62 chapter 3: using the remotingconnector component (flash professional only).

  • Page 63: Chapter 4

    63 chapter 4 using flash remoting data in actionscript this chapter explains how to handle data that your actionscript sends to and receives from service functions. It discusses how macromedia flash remoting for flash mx 2004 actionscript 2.0 converts data types, type-specific data handling issues, ...

  • Page 64

    64 chapter 4: using flash remoting data in actionscript the following figure shows this data conversion: a two-step conversion process enables flash remoting to use a system-neutral, efficient representation for the data it transmits. This way, you can create a flash application that can work with m...

  • Page 65

    Converting from actionscript to application server data types 65 converting from actionscript to application server data types flash remoting automatically converts between actionscript data and the data types specific to the application server programming environment. In strictly typed environments...

  • Page 66

    66 chapter 4: using flash remoting data in actionscript object flashgateway.Io. Asobject (which implements java.Util.Map) flashgateway. Io.Asobject (which implements the icollection interface) flashgateway. Io.Asobject complex type struct object of type flashgateway. Io.Asobject for more information...

  • Page 67

    Converting from application server data types to actionscript 67 the following is additional information on conversion from actionscript data types to server data types: • flash remoting converts actionscript number data types to any valid java or .Net numeric data type wherever possible. If the num...

  • Page 68

    68 chapter 4: using flash remoting data in actionscript system.Collection s.Icollection object[] system.Collection s.Icollection object[] array array collection object[] array of primitive types array system.Collection s.Hashtable system.Collection s.Idictionary system.Collection s.Hashtable system....

  • Page 69

    Coldfusion to actionscript data conversion issues 69 the following is additional information on conversion from server data types to actionscript data types: • if a string data type on the server represents a valid number in actionscript, flash can automatically cast it to a number if needed. • if y...

  • Page 70

    70 chapter 4: using flash remoting data in actionscript if a coldfusion page or cfc returns a numeric value without specifically identifying the value as numeric, flash remoting treats the value as a string when passing it to the responder. For example, if you have the following user-defined functio...

  • Page 71

    About working with objects 71 when you return an object from the server to flash, flash remoting sends the contents of the object’s data properties to flash as a flash object. In flash, you can access any of the object’s properties that are of types that can be converted to flash data types. The fol...

  • Page 72

    72 chapter 4: using flash remoting data in actionscript the following example shows a java class service function that creates a typed object and returns it to flash: package mycompany.Flash; import flashgateway.Io.Asobject; public class myflashservice { public myflashservice() { } public asobject g...

  • Page 73

    About working with recordset objects 73 public string gettext(){return this.Text;} public void settext(string t){this.Text = t;} public string getrecipient(){return this.Recipient;} public void setrecipient(string r){this.Recipient = r;} public message getmessage() { return this; } } you can use the...

  • Page 74

    74 chapter 4: using flash remoting data in actionscript about record sets a record set is a two-dimensional data table. The rows of the table correspond to individual data records, such as the data for a particular product or employee. The columns of the table correspond to different fields of a rec...

  • Page 75

    About working with recordset objects 75 recordset methods you can use the following methods to create and manage recordset objects. Method description constructor for recordset creates a new local recordset object. Recordset.Addeventlistener() registers a listener object with this recordset. When th...

  • Page 76

    76 chapter 4: using flash remoting data in actionscript for more information about each of these methods, see flash remoting actionscript dictionary help. The following sections describe how you can use these methods to create and manage recordset objects in actionscript code. Using recordset method...

  • Page 77

    About working with recordset objects 77 getting information about a recordset object to get information about a recordset object, use the following methods: in the following example, therecordset represents a recordset object: // get an array of the column names and convert it to a comma delimited l...

  • Page 78

    78 chapter 4: using flash remoting data in actionscript adding records to the recordset object to add items to a recordset object, use the additem() or additemat() methods. The additem() method adds a record at the end of the record set. The additemat() method inserts a record at the specific index ...

  • Page 79

    About working with recordset objects 79 to set up a notification event for an actionscript object, use the recordset addeventlistener() method and specify the object to notify when the recordset object changes. You can specify any object that receives change notifications in the addeventlistener() m...

  • Page 80

    80 chapter 4: using flash remoting data in actionscript sorting record sets to sort the records of a recordset object, use the sortitems and sortitemby() methods. The sortitemby() method performs an ascending (the default) or descending sort on the records in the recordset object. The sortitems() me...

  • Page 81

    About working with recordset objects 81 the following example filters a recordset object to produce a new recordset object with records that have contact fields that start with a specific letter: var myselectionfunction = function(arecord, letter) { return (arecord.Contact.Charat(0) == letter); } co...

  • Page 82

    82 chapter 4: using flash remoting data in actionscript flash remoting can deliver pageable record set data to your application in three modes, as described in the following table: you change a recordset object’s delivery mode by calling the setdeliverymode() method, as in the following example: fun...

  • Page 83

    About working with recordset objects 83 if the config_panel object specifies page mode, the setdeliverymode() method tells flash remoting to set the page size to the number of rows in the contact_grid movie clip and to prefetch one additional page beyond the page with the requested data, if it is no...

  • Page 84

    84 chapter 4: using flash remoting data in actionscript by default, each label value is a comma-delimited string that consists of the contents of one record’s fields; the data values are not set. However, you can use a recordset object directly in the dataprovider property to provide both the list a...

  • Page 85

    About working with xml 85 for example, the following formatting function takes a record that includes a parkname field. It converts the parkname text to all lowercase as the label, and uses the field’s length as the data. The bindformatfunction() method calls the formatting function once for each re...

  • Page 86

    86 chapter 4: using flash remoting data in actionscript // function that runs when the user clicks a "test xml" button after // entering text in two text boxes. Handles a return message sent by // the server: function testdocument(){ // create the xml document. Var xmldocument:xml = new xml(); var f...

  • Page 87: Chapter 5

    87 chapter 5 the netconnection debugger this chapter describes how to use the netconnection debugger and the netdebug and netdebugconfig classes to debug your flash remoting application. It includes a brief description of the netconnection debugger interface and describes the types of events that th...

  • Page 88

    88 chapter 5: the netconnection debugger to use the netconnection debugger with your flash remoting application 1. From the window menu in flash, select other panels > common libraries > remoting. 2. From the library panel, drag the remotingdebugclasses library to the stage. 3. Use the following imp...

  • Page 89

    Netconnection events 89 if you experience connectivity problems with the netconnection debugger, try starting it outside the flash authoring environment by following these steps: to start the netconnection debugger outside of the flash authoring environment: 1. Locate the netconnection debugger swf ...

  • Page 90

    90 chapter 5: the netconnection debugger the following table describes the information the netconnection debugger displays about specific event types. Event type information displayed by the debugger client activity information sent from the client. The default value is true . For detailed informati...

  • Page 91

    Netconnection events 91 common event information the following table describes the information that the netconnection debugger displays for all events. Two fields, debugid and protocol, are not used for trace events initiated by the netdebug.Trace() method. Recordset events associated with the parti...

  • Page 92

    92 chapter 5: the netconnection debugger client event messages the following table describes the specific client events that the netconnection debugger reports, and the information it displays for each event: event type triggering event information fields trace flash executed a netdebug.Trace() or c...

  • Page 93

    Netconnection events 93 application server event messages the following table describes the specific app_server events that the netconnection debugger reports and the information it displays for each event: event type triggering event information fields error an unresolved error occurred in the flas...

  • Page 94

    94 chapter 5: the netconnection debugger coldfusion event messages if you enable debugging output in coldfusion, the netconnection debugger can report a subset of the debugging information that is normally displayed by the coldfusion server. The netconnection debugger can report the following coldfu...

  • Page 95

    Using the netconnection debugger in actionscript 95 using the netdebug.Initialize() method the netdebug.Initialize() method initializes debug support for flash remoting. You must call this method prior to creating a connection or using any debugging operations, and typically before any actionscript ...

  • Page 96

    96 chapter 5: the netconnection debugger you can send a trace message that includes the connection id by using the gatewayconnection object’s trace() method, as in the following example: gatewayconnection.Trace("i just created myservice2 over this connection."); additionally, the getdebugid() method...

  • Page 97: Chapter 6

    97 chapter 6 using flash remoting with coldfusion mx to use macromedia flash remoting for flash mx 2004 actionscript 2.0 with macromedia coldfusion mx, you build coldfusion pages or coldfusion components (cfcs). In coldfusion pages, you use the flash variable scope to interact with flash application...

  • Page 98

    98 chapter 6: using flash remoting with coldfusion mx for example, suppose you create a coldfusion page named helloworld.Cfm in the directory helloexamples under your web root (web_root/helloexamples). You can then use the following actionscript in your flash application to call helloworld.Cfm: impo...

  • Page 99

    Using flash remoting with coldfusion pages 99 the flash scope has several predefined variables that you can use to pass information, as described in the following table: when you call a coldfusion page from a flash application, the flash remoting gateway converts actionscript data types to coldfusio...

  • Page 100

    100 chapter 6: using flash remoting with coldfusion mx in your coldfusion page, you access the parameter using flash.Params , as shown in the following example: select itemname, itemdescription, itemcost from tblitems where itemname='#flash.Params[1]#' because coldfusion converts an actionscript dat...

  • Page 101

    Using flash remoting with coldfusion pages 101 the following table lists actionscript collections and describes how to access them in coldfusion pages: accessing actionscript objects actionscript supports the object initializer syntax when calling a function. For example, the following function call...

  • Page 102

    102 chapter 6: using flash remoting with coldfusion mx you access x and y in your coldfusion page using coldfusion array and structure notation, as follows: you can pass actionscript objects to coldfusion pages. The following actionscript defines an object: var myobj:object = new object(); myobj.X =...

  • Page 103

    Using flash remoting with coldfusion pages 103 the directory name is the service address, and the helloworld.Cfm file is a method of the helloexamples directory of the flash remoting service. The following actionscript example calls the helloworld coldfusion page: import mx.Remoting.Service; import ...

  • Page 104

    104 chapter 6: using flash remoting with coldfusion mx depending on the sql code of the query and the amount of data stored in the database, the query can return a single record, a few records, or a very large number of records. To pass the entire record set to the flash application, you simply writ...

  • Page 105

    Using flash remoting with coldfusion components 105 when you assign a value to the flash.Pagesize variable, you specify that if the record set has more than that number of records, the record set becomes pageable and returns the number of records specified in the flash.Pagesize variable. For example...

  • Page 106

    106 chapter 6: using flash remoting with coldfusion mx "functb" access="remote" returntype="struct"> note: for coldfusion component methods to communicate with flash applications, you must set the cffunction tag’s access attribute to remote . You call these functions in actionscript using the follow...

  • Page 107

    Using flash remoting with coldfusion components 107 the order in which you specify the cfargument tags in the function corresponds to the order in which the parameters are passed from actionscript. For example, the following actionscript call passes three parameters: cfcservice.Functa(a, b, c); the ...

  • Page 108

    108 chapter 6: using flash remoting with coldfusion mx the following example replicates the helloworld() function that was previously implemented as a coldfusion page. For more information, see “using flash remoting with coldfusion pages” on page 97 . To create a coldfusion component that interacts ...

  • Page 109

    Using flash remoting with coldfusion components 109 ...> you can also pass arrays, structures, and named objects using this syntax. The following actionscript code defines an object: var params:object = new object(); params.First = "hello"; params.Second = true; service.Concat(params); in a componen...

  • Page 110

    110 chapter 6: using flash remoting with coldfusion mx to create a coldfusion component that describes itself to the service browser: 1. Edit the flashcomponent.Cfc file in the helloexamples directory by inserting the following code: description="returns date"> description="returns date"> descriptio...

  • Page 111

    Using flash remoting with server-side actionscript 111 using flash remoting with server-side actionscript the ability to create server-side actionscript provides a familiar way for flash developers to access coldfusion query and http features without learning cfml. Identify the actionscript files (w...

  • Page 112

    112 chapter 6: using flash remoting with coldfusion mx "http://localhost/flashservices/gateway", null, "httpfuncs", null, null); // call service method - basicget() var pc:pendingcall = myhttpservice.Basicget("http://examples.Macromedia.Com/ flashservices/gateway"); // specify result and fault handl...

  • Page 113

    Using flash remoting with server-side actionscript 113 the arguments in the following table can be passed only as an array of objects in the params argument of the cf.Http() function: you can write the cf.Http() function using either named arguments or positional arguments. The positional argument s...

  • Page 114

    114 chapter 6: using flash remoting with coldfusion mx when using positional arguments, do not use curly braces. Using cf.Query() the cf.Query() function lets you perform queries against any coldfusion data source. The cf.Query() function maps closely to the cfquery cfml tag, although it currently s...

  • Page 115

    Calling web services from flash remoting 115 calling web services from flash remoting using flash remoting with coldfusion, you can interact with web services directly from your flash applications without having to build a coldfusion page or component. You write the code to reference a web service i...

  • Page 116

    116 chapter 6: using flash remoting with coldfusion mx to handle the results of the web service method, you create an event handler with the same name as the service functions with _result or _fault appended to the name. The result handler displays the results in the mygrid datagrid component, as th...

  • Page 117

    Handling errors with coldfusion 117 > roles="admin"> this example does not show how to perform user verification. For more information on verification, see developing coldfusion mx applications with cfml. Assigning security roles to component functions coldfusion components offer roles-based securit...

  • Page 118

    118 chapter 6: using flash remoting with coldfusion mx to simplify the debugging of your coldfusion code, use the cftry and cfcatch tags in your coldfusion page or component to catch errors and return helpful error messages about the errors to the flash application. For example, the coldfusion page ...

  • Page 119: Chapter 7

    119 chapter 7 using flash remoting for java this chapter describes how to use macromedia flash remoting for flash mx 2004 actionscript 2.0 with services running in java application servers. You can use flash remoting from actionscript in a flash application to call public methods on java objects run...

  • Page 120

    120 chapter 7: using flash remoting for java about flash remoting for java flash remoting exposes java objects as services that are accessible from flash applications as actionscript functions that correspond to java object methods. A flash developer writes actionscript that uses the actionscript se...

  • Page 121

    Calling java classes or javabeans from actionscript 121 you can use a value object to send a coarse-grained view of data to the server and get back fine-grained data. For example, you can call a single method on a value object that aggregates several method calls on an entity bean. The method result...

  • Page 122

    122 chapter 7: using flash remoting for java the following table lists standard ways to add classes to the system classpath: getting a reference to a java class or javabean in actionscript before calling methods of a java class or javabean from actionscript, you must get a reference to the java obje...

  • Page 123

    Calling java classes or javabeans from actionscript 123 invoking java methods in actionscript after you have created a reference to a java class or javabean, you can use actionscript functions to invoke that object’s public methods. Consider the following javabean method: public string getmessage() ...

  • Page 124

    124 chapter 7: using flash remoting for java looking at the javabean code the example flash application invokes the setmessage() , getmessage() , testboolean() , and testdate() methods of the following javabean: package com.Samples; import java.Util.Date; import java.Io.Serializable; import org.W3c....

  • Page 125

    Calling java classes or javabeans from actionscript 125 looking at the user interface for the javabean the following figure shows the user interface of the example flash application with callouts that indicate the field types and variable names referenced in the actionscript code. Looking at the act...

  • Page 126

    126 chapter 7: using flash remoting for java invokebutton.Addeventlistener("click", runexample); // set initial text for messageinput and dateinput text fields. Messageinput.Text = "[enter a message]"; dateinput.Text = "" + flashdate; } // invoke business methods when user clicks the runbutton funct...

  • Page 127

    Calling java classes or javabeans from actionscript 127 // handle results from server; display results in output fields. Function setmessage_result( re:resultevent ):void { // shouldn't happen } function getmessage_result( re:resultevent ):void { messageoutput.Text = re.Result.Tostring(); } function...

  • Page 128

    128 chapter 7: using flash remoting for java calling enterprise javabeans (ejbs) from flash the following sections describe how to get a reference to an ejbhome object and call enterprise javabeans (ejb) methods from actionscript. Getting a reference to an ejbhome object in actionscript before calli...

  • Page 129

    Calling enterprise javabeans (ejbs) from flash 129 mx.Remoting.Debug.Netdebug.Initialize(); //… function runexample() { var sampleloanhome:service = new service( "http://localhost:8300/flashservices/gateway", null, "sampleloanejbhome", null, null); var pc:pendingcall = sampleloanhome.Create(); pc.Re...

  • Page 130

    130 chapter 7: using flash remoting for java looking at the ejb code the example flash application calculates loan payments by invoking the calculate() method on the following stateless session bean: package ejbeans; import java.Rmi.*; import java.Util.*; import javax.Ejb.*; public class sampleloanb...

  • Page 131

    Calling enterprise javabeans (ejbs) from flash 131 looking at the actionscript code that calls the ejb the following code is the actionscript of the example flash application: // import flash remoting files import mx.Remoting.Service; import mx.Remoting.Debug.Netdebug // ----------------------------...

  • Page 132

    132 chapter 7: using flash remoting for java calling servlets and jsps from flash the following sections describe how to get a reference to a servlet or a jsp defined as a servlet in a web.Xml file, and call the servlet or jsp. Note: servlets are supported on servlet 2.2- and servlet 2.3-compliant a...

  • Page 133

    Calling servlets and jsps from flash 133 calling a servlet or jsp to call a servlet or a jsp defined as a servlet from actionscript, use the servlet name specified in the web application’s web.Xml deployment descriptor file as an actionscript function name. For example, the servlet name is myservlet...

  • Page 134

    134 chapter 7: using flash remoting for java } public string getservletinfo() { return "a test servlet."; } public servletconfig getservletconfig() { return null; } public void destroy() { message = null; } } to handle the function results in actionscript, you use a result handler function like this...

  • Page 135

    Calling server-side actionscript from flash (jrun only) 135 getting a reference to an mbean in actionscript before calling the methods of an mbean from actionscript, you must get a reference to an mbean. To get a reference to an mbean: 1. Import the flash remoting files: import mx.Remoting.Service; ...

  • Page 136

    136 chapter 7: using flash remoting for java getting a reference to a server-side actionscript file before calling the functions of a server-side actionscript file (with the .Asr extension), you must get a reference to the file. Place the server-side actionscript file that you want to call in a web ...

  • Page 137

    Handling function results in actionscript 137 for more information, see the next section. Handling function results in actionscript in java application servers, you handle function results in actionscript the same way that you do for other platforms that flash remoting supports. You write an actions...

  • Page 138

    138 chapter 7: using flash remoting for java the calculate() function returns the following loaninfo bean: package samples; public class loaninfo { private double principal; private int months; private float rate; private double monthlypayment; public loaninfo() { } public loaninfo(double principal,...

  • Page 139

    Using flash remoting with jrun security 139 you can use the following actionscript code to get the value of the loaninfo bean’s monthlypayment property, or handle a fault condition: function calculatereturncomplex_result (re:resultevent):void { payoutput.Text = re.Result.Monthlypayment; } function c...

  • Page 140

    140 chapter 7: using flash remoting for java the following example shows entries for the flashrole role and corresponding ejb method permissions in an ejb-jar.Xml file: flashrole flashrole sampleloanbean calculate passing xml objects between flash and java both actionscript and java have object type...

  • Page 141

    Viewing flash remoting log entries 141 flashtestservice.Testdocument(xmldocument); } note: you can also create an xml document object in actionscript by passing a string representation of the xml to the new xml(source) constructor. For more information, see the flash documentation set. Returning an ...

  • Page 142

    142 chapter 7: using flash remoting for java.

  • Page 143: Chapter 8

    143 chapter 8 using flash remoting for microsoft .Net macromedia flash remoting for flash mx 2004 actionscript 2.0 for microsoft .Net is an asp.Net web application that enables flash applications to access and invoke asp.Net pages, ado.Net data, web services, and assemblies from actionscript. This c...

  • Page 144

    144 chapter 8: using flash remoting for microsoft .Net flash remoting contains four service adapters for .Net technologies: • asp.Net adapter • ado.Net data-binding adapter • web services adapter • assembly (with the .Dll extension) flash remoting for .Net requires the .Net framework sdk to be insta...

  • Page 145

    Flash remoting for microsoft .Net 145 the facadestructural design pattern can be particularly useful with flash remoting by reducing the number of remote method calls required in a flash application. You can use a service facade to provide a single point of contact to a set of aspx pages or dll meth...

  • Page 146

    146 chapter 8: using flash remoting for microsoft .Net as the figure shows, the local assembly cache in the myaspapp directory contains the flash remoting assembly, flashgateway.Dll. Also, to connect a flash application with a remote service, you must reference a physical resource in your applicatio...

  • Page 147

    Calling asp.Net pages from flash 147 your flash remoting-enabled asp.Net application directory is now ready to use. Calling asp.Net pages from flash this section describes calling an aspx page from flash using flash remoting, working with the flash remoting custom server control in aspx pages, using...

  • Page 148

    148 chapter 8: using flash remoting for microsoft .Net function gotresourcesfault( fe:mx.Rpc.Faultevent ): void { trace( "error occurred"+ fe.Fault.Faultstring ); } the gateway url must reference an aspx page inside the application directory. You should use the gateway url only during development in...

  • Page 149

    Calling asp.Net pages from flash 149 using the flash remoting custom server control in aspx pages to access data passed from flash applications or return results to flash applications in aspx pages, you use the flash remoting custom server control in your aspx page. The flash remoting server control...

  • Page 150

    150 chapter 8: using flash remoting for microsoft .Net if more than one parameter is passed from flash, you access the parameters in your .Net application in the same order that they were passed from the flash application. For example, the following actionscript function passes two parameters, assum...

  • Page 151

    Calling asp.Net pages from flash 151 ... } } the following vb.Net example performs the same operation: namespace samples.Ado public class customerinfo inherits system.Web.Ui.Page protected flash as flashgateway.Flash after you establish the flash remoting namespace, you can manipulate the server con...

  • Page 152

    152 chapter 8: using flash remoting for microsoft .Net to return a session variable, you use the flash.Result property, as shown in the following example: assembly="flashgateway" %> flash.Result = session.Mypreference; %> in the code, the value of the mypreference variable is assigned to the flash.R...

  • Page 153

    Using ado.Net objects with flash remoting 153 using ado.Net objects with flash remoting flash remoting provides a service adapter for binding ado.Net data tables and data views to the flash remoting custom server control. To bind data sets to the custom server control, you use the control’s datasour...

  • Page 154

    154 chapter 8: using flash remoting for microsoft .Net to display the data from the previous aspx page, as customercountries.Aspx under the adoexamples folder, in a datagrid object called custcountry_grd, the actionscript code would look like this: import mx.Remoting.Service; import mx.Remoting.Pend...

  • Page 155

    Displaying a recordset object in flash with actionscript 155 dim selectcontactdata as string 'insert flash parameter into sql statement selectcontactdata = "select contactname, city, phone from customers where country = \'" + selectedcountryname + "\'" end if 'create the data adapter object dim coun...

  • Page 156

    156 chapter 8: using flash remoting for microsoft .Net import mx.Rpc.Relayresponder; import mx.Rpc.Faultevent; import mx.Remoting.Pendingcall; // get a reference to the aspx-based service var aspxservice:service = new service("http://localhost/myaspapp/ default.Aspx",null,"myaspapp",null,null); // c...

  • Page 157

    Calling web services from flash 157 invoking web service methods using flash remoting flash remoting uses the .Net wsdl tool to generate the necessary proxy classes automatically by specifying a valid url to a wsdl file or to a url that can generate a wsdl file, such as a .Net asmx file. To invoke a...

  • Page 158

    158 chapter 8: using flash remoting for microsoft .Net null); var pc:pendingcall = flashservice.Getmessage(); pc.Responder = new relayresponder( this, "getmessage_result", "getmessage_fault" ); function getmessage_result(var re:resultevent):void { servicemessage.Text = re.Result; } function getmessa...

  • Page 159

    Calling asp.Net assemblies from flash 159 in the actionscript code, you specify the servicename argument with a url that produces wsdl. The gettemp function maps to the web service method of the same name. Here, zip represents an input text field, and tempdisplay represents a dynamic text field. To ...

  • Page 160

    160 chapter 8: using flash remoting for microsoft .Net "echostring_fault"); function echostring_result(re:resultevent):void { stringdisplay.Text = re.Result; } function echostring_fault(fe:faultevent):void { stringdisplay.Text = fe.Fault.Faultstring; } in the code, you use the fully qualified class ...

  • Page 161

    Calling asp.Net assemblies from flash 161 this code creates an instance of the asobject object, named aso , and uses the astype property to identify the object as calculator . The add method inserts key-value pairs into the object. Finally, aso is returned to flash using the flash.Result variable. H...

  • Page 162

    162 chapter 8: using flash remoting for microsoft .Net } function subtract():number { return ( x - y ); } function add():number { return( x + y ); } } viewing flash remoting log entries flash remoting writes error messages to the flash.Log file in the local assembly cache. You can change the log fil...

  • Page 163: Appendix A

    163 appendix a using netservices and connection classes this appendix explains how to use the netservices object to create a gateway connection and return a connection object. It also explains how to handle results and error information that are returned by a service. This appendix covers the follow...

  • Page 164

    164 appendix a: using netservices and connection classes you can also combine these techniques. If you do so, the gateway url is determined as follows: 1. A url specified in a creategatewayconnection() method takes precedence over any other url. 2. A url specified in the deployed web page takes prec...

  • Page 165

    Creating a gateway connection using the netservices object 165 setting a default gateway url provides you with the greatest flexibility in both development and deployment. It lets you provide a url that works when you test your swf file directly in the flash development environment. Setting a gatewa...

  • Page 166

    166 appendix a: using netservices and connection classes the following example illustrates these steps: myservice.Logout(); gatewayconnection.Setcredentials("", ""); the technique that you use to authenticate the user and to authorize access on the application server depends on the application serve...

  • Page 167

    Handling results for a connection object 167 handling results for a connection object when you use the methods of the netservices object to create a gateway connection and obtain a connection object, you use the connection.Getservice() method to access a service. When you access a service using the ...

  • Page 168

    168 appendix a: using netservices and connection classes // initialization code specifies gateway, creates connection, calls service if (inited == null) { inited = true; netservices.Setdefaultgatewayurl("http://localhost:8300/flashservices/ gateway") var gatewayconnection:connection = netservices.Cr...

  • Page 169

    Handling errors for a connection object 169 // initialization code specifies gateway, creates connection, calls service if (inited == null) { inited = true; netservices.Setdefaultgatewayurl("http://localhost:8300/flashservices/ gateway") var gatewayconnection:connection = netservices.Creategatewayco...

  • Page 170

    170 appendix a: using netservices and connection classes the error object when flash remoting receives a status event, flash passes an error object that contains information about the error to the status event handler. The error object has the following format: error-handling hierarchy flash remotin...

  • Page 171

    Handling errors for a connection object 171 error-handling strategies flash applications use error-handling code less often than server applications do, because flash does not report errors to the user when the user is viewing swf files. However, flash remoting does make error information available ...

  • Page 172

    172 appendix a: using netservices and connection classes this.Onresult = function(result){ // display successful result resultdisplay.Text = result; } this.Onstatus = function(error){ // display successful result resultdisplay.Text = error.Description; } } // general responder object can be used for...

  • Page 173: Index

    173 index a action message format see amf actionscript connecting to a service 18 data types, converting from application server 67 data types, converting to application server 65 debugging 94 function results, handling in 137 typed objects, using 71 xml object, sending to java 140 actionscript 2.0 ...

  • Page 174

    174 index asp.Net and helloworld application 19 application 146 assemblies 159 pages 147 service name format 39 specifying functions 42 state management 151 aspx page getting a reference to 147 using the flash remoting custom server control in 149 assemblies asp.Net, calling 159 creating 160 returni...

  • Page 175

    Index 175 using flash remoting mx with coldfusion components 105 using flash remoting mx with coldfusion pages 97 web services 115 coldfusion pages actionscript object access 101 arrays and 100 error handling 117 flash remoting mx and 97 flash service name 97 pageable record sets 104 parameter passi...

  • Page 176

    176 index error app_server event message 93 error app_server event type 90 error handling error object 170 example 168 fault object 170 hierarchy 170 in coldfusion 117 strategies 171 error object, handling 170 event types, debugger 89 events application server 93 client 92 coldfusion 94 common debug...

  • Page 177

    Index 177 flashvars attribute specifying gateway 38 flashvars parameter gateway connection 38 function results, handling in actionscript 137 functions, specifying 42 g gateway specifying in a web page 38 specifying in creategatewayconnection netservices object method 164 gateway connection establish...

  • Page 178

    178 index m mbeans calling jmx from flash 134 getting a reference to 135 invoking methods in actionscript 135 microsoft .Net about 143 flash remoting design patterns 144 flash remoting directory structure 145 migrating to actionscript 2.0 22 remote datagrid example 24 taking full advantage 23 model,...

  • Page 179

    Index 179 replaceitemat method 78 see also record sets sorting 80 sortitemsby method 80 using 73 using directly in components 83 values, returning 77 recordset class description 33 importing 36 reference aspx page, getting 147 ejbhome, getting 128 mbean, getting 135 server-side actionscript, getting...

  • Page 180

    180 index handling errors 43 handling results 43 passing parameters 41 result handling example 167 specifying 42 service name for helloworld 21 service object calling functions 41 creating 39 handling results 44 service request 17 session variables getting and setting with flash remoting mx 151 setc...