MACROMEDIA FLASH REMOTING MX-USING FLASH REMOTING FOR FLASH MX 2004 ACTIONSCRIPT 2.0 Use Manual
MACROMEDIA FLASH REMOTING MX-USING FLASH REMOTING FOR FLASH MX 2004 ACTIONSCRIPT 2.0 Use Manual

MACROMEDIA FLASH REMOTING MX-USING FLASH REMOTING FOR FLASH MX 2004 ACTIONSCRIPT 2.0 Use Manual

Using flash remoting for flash mx 2004 actionscript 2.0
Table of Contents

Advertisement

Quick Links

Using Flash Remoting for Flash MX 2004 ActionScript 2.0

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the FLASH REMOTING MX-USING FLASH REMOTING FOR FLASH MX 2004 ACTIONSCRIPT 2.0 and is the answer not in the manual?

Questions and answers

Summary of Contents for MACROMEDIA 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 Open Sesame!, Roundtrip, Roundtrip HTML, Shockwave, Sitespring, SoundEdit, Titlemaker, UltraDev, Web Design 101, what the web can be, and Xtra are either registered trademarks or trademarks of Macromedia, Inc. and may be registered in the United States or in other jurisdictions including internationally. Other product names, logos, designs, titles, words, or phrases mentioned within this publication may be trademarks, service marks, or trade names of Macromedia, Inc.
  • Page 3: Table Of Contents

    Contacting Macromedia ........
  • Page 4 Handling service results and errors ........43 Using the RelayResponder object for a service .
  • Page 5 CHAPTER 5: The NetConnection Debugger ......87 Using the NetConnection Debugger ........87 Enabling debugging .
  • Page 6 Calling Enterprise JavaBeans (EJBs) from Flash......128 Getting a reference to an EJBHome object in ActionScript....128 Invoking EJB methods in ActionScript.
  • Page 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 Contents...
  • Page 9: Introduction About Flash Remoting

    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 Macromedia Flash MX 2004, read the documentation set. If you are not familiar with application server development, read the documentation included with your server.
  • Page 10: What's New In Flash Remoting For Flash Mx 2004 Actionscript 2.0

    • The ActionScript Dictionary describes the syntax and use of ActionScript elements in Macromedia Flash MX 2004 and Macromedia Flash MX Professional 2004. To access the ActionScript Dictionary in Flash MX 2004, select Help > ActionScript Dictionary from the Help menu.
  • Page 11: Developer Resources

    Developer resources Macromedia is committed to setting the standard for customer support in developer education, documentation, technical support, and professional services. The Macromedia website is designed to give you quick access to the entire range of online resources. The following table shows the...
  • Page 12: Contacting Macromedia

    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 help you figure out how to do just about anything with Flash Remoting.
  • Page 13: Chapter 1: Getting Started

    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 Remoting architecture and how to build a Hello World Flash Remoting application.
  • Page 14: Flash Remoting Data Flow

    When compared to traditional HTML-based browser applications, Flash applications provide unique abilities to create dynamic and sophisticated user interactions, including the following: • Macromedia Flash Player runtime to execute code, transmit data, and invoke remote services • Separation of client-side presentation logic from the server-side application logic •...
  • Page 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 are returned as a record set that lists the section, row, seat, and ticket price for each of the available seats.
  • Page 16: Understanding The Flash Remoting Service Adapters

    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 adapters Flash Remoting automatically maps incoming requests to the appropriate service adapters, each of which provide a direct connection to a specific application server technology.
  • Page 17: Using Flash Remoting

    // import PendingCall clsas import mx.rpc.ResultEvent // import ResultEvent class import mx.rpc.RelayResponder // import RelayResponder class mx.remoting.debug.NetDebug.initialize(); var myService:Service = new Service("http://examples.macromedia.com/ flashservices/gateway",null,"petmarket.api.catalogservice", null, null); // connect to remote service var pc:PendingCall = myService.getCatagories({locale:”en_US”}); // call service method pc.responder = new RelayResponder(this, "getData_Result", "getData_Fault");...
  • Page 18 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 by using the Flash Remoting ActionScript API to write code in the Actions panel.
  • Page 19 FlashJavaBean() { message = "Hello from Java!"; public String helloWorldJava() { return message; ASP.NET Save the ASPX page as <%@ Register TagPrefix="Macromedia" Namespace="FlashGateway" helloWorldNET.aspx in the Assembly="flashgateway" %> flashremoting directory under your <%@ Page language="c#" debug="true" %> web root.
  • Page 20 Highlight the text field and in the Property inspector, name the text field messageDisplay and select Dynamic Text in the menu. Open the Actions panel and insert the following ActionScript code, replacing variables that appear in italics with the values that correspond to the server you are using. These values are provided following the code: import mx.remoting.Service;...
  • Page 21 , which is the name of the remote service. To select the appropriate value serviceName for this example, see the table that follows this section. The two values represent the parameters, which are not null connection responder used in this case. For information about these parameters, see the constructor for the Service class in Flash Remoting ActionScript Dictionary Help.
  • Page 22: Actionscript 2.0

    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 ActionScript 1.0 and you want to migrate to Flash Remoting for Flash MX 2004 ActionScript 2.0, you have two choices regarding how to migrate your applications.
  • Page 23: Taking Full Advantage Of Flash Remoting For Flash Mx 2004 Actionscript 2.0

    Adjust for and adhere to case sensitivity in ActionScript 2.0. ActionScript 2.0 is case sensitive. For example, were treated as the same myVar myvar variable in ActionScript 1.0 but they are treated as two distinct variables in ActionScript 2.0: var myVar:Object = new Object(); var temp:Object = myvar;...
  • Page 24: Actionscript 2.0

    DataGrid with dynamic data, listing customers who belong to a selected category. You can find the Remote DataGrid application in the following folder: /Program Files/Macromedia/Flash MX 2004/en/First Run/RemotingSamples See the Readme.htm file in this folder for information on how to set up and use this sample application.
  • Page 25 In the ActionScript code in the Actions panel, change # statements to include import statements: // Old API #include "NetDebug.as" #include "NetServices.as" // New API import mx.remoting.*; import mx.rpc.*; These two statements will import all of the Flash Remoting for Flash MX 2004 import ActionScript 2.0 files.
  • Page 26 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/flashservices/ gateway". The Log, which is optional. For information about the Log, see the Log class in the Flash Remoting ActionScript Dictionary.
  • Page 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 event for the dataGrid to be updated. combo.dispatchEvent({type:"change", target:combo}); function gotCatStatus(fault:FaultEvent) trace(" Error : "+ fault.fault.faultstring); You can set up the Responder object in one of the following two ways: The Service constructor passes its name, in which cases it becomes the default handler for the result and fault outcomes of any method called for the service.
  • Page 28 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.selectedItem.description; grid.addEventListener("change", gridChange); Chapter 1: Getting Started...
  • Page 29: Chapter 2: Using Flash Remoting Actionscript

    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 service returns. After reading this chapter, you should be able to create a simple application that uses Flash Remoting to obtain data from an application server.
  • Page 30: Flash Remoting Application Structure

    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 Configuring publish settings for Flash Player detection in Using Flash Help.
  • Page 31 // Remove the slashes in the following two lines to use the NetConnection Debugger // import mx.remoting.debug.NetDebug; // NetDebug.initialize(); function makePetMarketCalls(){ Configure Flash var catalogService:Service = new Service( Remoting "http://examples.macromedia.com/flashservices/gateway", new Log(), "petmarket.api.catalogservice", null,null ); var cat_pc:PendingCall = catalogService.getCategories({locale:"en_US"}); Call the service cat_pc.responder = new RelayResponder(this,"gotCategories_Result", function(s) "gotCategories_Fault");...
  • Page 32: Flash Remoting Actionscript Classes

    NetConnection Debugger with a specific ActionScript object. The NetConnection Debugger reports information on Flash Remoting events. For Macromedia ColdFusion MX, these events also include server activity, such as SQL queries. For more information on using the NetConnection Debugger, see Chapter 5, “The NetConnection Debugger,”...
  • Page 33 Represents a reference to a specific remote service and the methods that the service exposes. Remote services consist of application server modules that leverage technologies such as JavaBeans, Macromedia ColdFusion Components (CFCs), CFML pages, ASP.NET web services and pages. For more information, see “Calling service functions”...
  • Page 34: Properties And Methods

    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 debugging. Purpose Class Properties Methods Creating and Connection addHeader()
  • Page 35: Importing Flash Remoting Actionscript Classes

    This is typically done in the first frame of the Flash application or at the top of any class files as required: Import statement Purpose Replaces NetConnection class. Macromedia recommends import mx.remoting.Connection that you use the Service class to connect to remote services and use the methods of the Connection class to perform connection-related tasks such as authenticating users.
  • Page 36: Configuring Flash Remoting

    Import statement Purpose import mx.services.Log; Log object is optional parameter to Service constructor. You can use the Log class to create a customized logger for your Flash Remoting application. Provides debugging methods for Flash Remoting import mx.remoting.debug.NetDebug; applications. Remove it before publishing your application to a production server to prevent access to debugging information.
  • Page 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 following format: http://webServer[:port]/flashservices/gateway...
  • Page 38 The following HTML example runs the myMovie.swf Flash application and specifies http://apps. myCompany.com/flashservices/gateway as the URL for the Flash Remoting services gateway. The first highlighted line contains the code for Internet Explorer. The second highlighted line contains the code for Netscape. <OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash. cab#version=6,0,0,0" WIDTH="100%" HEIGHT="100%" id="MyMovie">...
  • Page 39: Specifying A Service

    Note: If you specify the Flash Remoting gateway in the web page, the ActionScript import mx. directive must be on the Flash Timeline, not in a SWF file. remoting.Service; When you specify the gateway connection in a Web page, you specify the parameter gatewayUrl as an empty string in the Service constructor that you create to access the service.
  • Page 40: Authenticating A User To The Application Server

    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 the application server In some cases, your application server might require you to provide user authentication—a user name and password—before you can use a service.
  • Page 41: Calling Service Functions

    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: Call a logout service function on the server that logs out the user.
  • Page 42: Specifying Functions

    // create RelayResponder to specify result handling methods var myResponder:RelayResponder = new RelayResponder(this,"getCategories_Result","getCategories_Fault"); // establish gateway and create a Service object to refer to the service var petMarketService:Service = new Service( "http://examples.macromedia.com/flashservices/gateway", null, "petmarket.api.catalogservice", null, myResponder ); // set user credentials petMarketService.connection.setCredentials("myUserName","myPassword");...
  • Page 43: Calling Functions Using Named Arguments In Coldfusion

    Service type Function name ColdFusion pages (.cfm) ColdFusion page (without the cfm suffix) ColdFusion components (.cfc) Component method 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 using Flash Remoting.
  • Page 44: Using The Relayresponder Object For A Service

    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 instead of a result if either of the following conditions occur: •...
  • Page 45: Using Pendingcall And Relayresponder Objects For A Specific Service Function

    { petMarketService = new Service( "http://examples.macromedia.com/flashservices/gateway", new Log(), "petmarket.api.catalogservice", null, null); var temp_pc:PendingCall = petMarketService.getCategories("en_US"); temp_pc:responder = new RelayResponder(this,"getCategories_Result","getCategories_Fault");...
  • Page 46: Using The Faultevent Class

    Handling the result object requires knowledge of the service function. The service function could return a simple string, as shown in the following method: HelloWorld_Result() function serviceFunctionName_Result(result:ResultEvent) // display successful result messageDisplay.text = result.result; The service function could also return a complex object such as a record set holding several records that were retrieved from a database.
  • Page 47: Using The Flash Remoting Actionscript Api In The Customerinfoexampleapi Application

    • Using event listeners to trigger refreshing of the data You can find the CustomerInfoExampleAPI application in the following folders: • /Program Files/Macromedia/Flash MX 2004/en/First Run/RemotingSamples/Client • /Program 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 and use this sample application.
  • Page 48 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 application creates the CustomerInfoForm class, which extends the Form class. The sections following the ActionScript code describe the functions in this class.
  • Page 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.setStyle( "textAlign", "right" ); //set the textField to Left Align totalSales_label.setStyle( "textAlign", "right" ); 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 updateDetails():Void {...
  • Page 50 // 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" ); totalRec_txt.text = String( rs.length ); customers_grd.dataProvider = rs; customers_grd.selectedIndex = 0; updateDetails();...
  • Page 51: Onreveal()

    Establishing the connection in the HTML file enables you to change it without needing to republish the application. After creating the Service object, calls the c custService CustomerInfoFormAPI() ustService. function to retrieve a record set of all categories, sets the alignment for the getCatergories() Total Sales label on the DataGrid component, and assigns a RelayResponder object to the property of the...
  • Page 52: Oncustcat_Change()

    function calls the function to establish this function as onReveal() addEventListener() the event handler for the DataGrid component customers_grd onCustCat_Change() function is the event handler that is called when the selection in the onCustCat_Change() Category ComboBox component changes. It calls the function to refreshCustomerData() retrieve the customers for the selected category.
  • Page 53: Chapter 3: Using The Remotingconnector Component (Flash Professional Only)

    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 define an easy way to send parameters to, and receive results from, an external data source.
  • Page 54: Remotingconnector Parameters

    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 on the Schema tab of the Component inspector for the RemotingConnector component, as shown in the following example.
  • Page 55 These parameters can take the following values: Parameter Type Category Description Boolean General If it has the value , this parameter allows multipleSimultaneousAllowed true method to be invoked even if trigger() results have not yet been returned from a previous invocation. If it has the value method does not false, trigger()
  • Page 56: Creating An Instance Of The Remotingconnector Component

    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 parameters and the result to the UI component that uses them: To create an instance of the RemotingConnector component In the Components panel, double-click the RemotingConnector component to place an instance on the stage.
  • Page 57: Using The Remotingconnector In The Customerinfoexamplecon Application

    • Specifying of the gateway URL using HTML You can find the CustomerInfoExampleCon application in the following folders: • /Program Files/Macromedia/Flash MX 2004/en/First Run/RemotingSamples/Server • /Program 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 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.
  • Page 58 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 sections following the ActionScript code describe the functions in this class. import mx.data.components.RemotingConnector;...
  • Page 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 updateDetails() var curItem:Object = customers_grd.selectedItem; custInfo_txt.text = curItem.Details; totalSales_label.text = curItem.TotalSales;...
  • Page 60: Onreveal()

    // 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" ) { Alert.show( "Couldn't retrieve category data.", "Error", Alert.OK, this );...
  • Page 61: Updatedetails()

    Finally, the function calls the method for the categoryData_con onReveal() trigger() RemotingConnector object to connect to the service, retrieve the Category data for the ComboBox component, and execute the data bindings to populate it. updateDetails() function updates the text, the total sales, and the logo in the Customer updateDetails() Details section of the user interface.
  • Page 62 Chapter 3: Using the RemotingConnector component (Flash Professional only)
  • Page 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, and how to use simple and complex data types.
  • Page 64: Understanding Action Message Format

    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 multiple application servers. Flash Remoting performs all data conversions automatically.
  • Page 65: Converting From Actionscript To Application Server Data Types

    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, such as Java and C#, the service function data types must correspond to (or be derived from) the listed data types.
  • Page 66 ActionScript Converted Converted C# Converted Converted Converted Data Type Java data type data type Visual Basic SOAP ColdFusion data type data type MX data type Object flashgateway.io. FlashGateway. FlashGateway. Complex Struct ASObject IO.ASObject IO.ASObject type Object of type (which (which implements FlashGateway.
  • Page 67: Converting From Application Server Data Types To Actionscript

    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 number cannot be converted to the appropriate data type for the service, if the number exceeds the valid range of an integer data type, for example, Flash Remoting throws an error on the server.
  • Page 68 C# data type Visual Basic SOAP ColdFusion Java data Converted data type data type MX data type type ActionScript data type System.Collection System.Collection array Array Collection Array s.ICollection s.ICollection Object[] object[] object[] array of primitive types System.Collection System.Collection complex Struct java.util.Map Associative s.Hashtable...
  • Page 69: Coldfusion To Actionscript Data Conversion Issues

    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. •...
  • Page 70: About Working With Objects

    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 function and ActionScript code, Flash displays 22, not 4, in the trace message: ColdFusion <cffunction name="getNumber"access="remote">...
  • Page 71: Working With Actionscript Typed Objects

    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 following sections cover two special cases of objects: ActionScript typed objects and Java Serializable objects.
  • Page 72: Working Withjava Serializable Objects

    Flash. public class Message implements java.io.Serializable private String text; private String recipient; private String server; public Message() this.text = "Default message"; this.recipient = "user@macromedia.com"; this.server = "smtp.macromedia.com"; Chapter 4: Using Flash Remoting Data in ActionScript...
  • Page 73: About Working With Recordset Objects

    You can use the following ActionScript to set and get the result object’s properties. (For brevity, this example omits the code that configures the network connection and service object.) myBeanService.setText("Hello from Me."); myBeanService.setRecipient("me@macromedia.com"); myBeanService.getMessage(); function getMessage_Result(msgEvent:mx.rpc.ResultEvent) myMessageText.text = msgEvent.result.text;...
  • Page 74: About Record Sets

    The following table shows a sample record set structure: lastName firstName emailAddress telExt Smith Dave dave.tomlin@macromedia.com 3456 Basham Meredith meredith.neville@macromedia.com 7890 Card Sean sean.carr@macromedia.com...
  • Page 75: Recordset Methods

    RecordSet methods You can use the following methods to create and manage RecordSet objects. Method Description Creates a new local RecordSet object. constructor for RecordSet Registers a listener object with this RecordSet. When the RecordSet.addEventListener() RecordSet is modified in some way the listener can respond to these changes.
  • Page 76: Using Recordset Methods And Properties

    Method Description RecordSet.setDeliveryMode() Changes the delivery mode of a pageable record set from an application server. Replaces one field of a record with a new value. RecordSet.setField() RecordSet.sort() Sorts all the records using a comparison function that you specify as an argument to the method. Sorts all the records using a user-specified comparison RecordSet.sortItems() function...
  • Page 77 Getting information about a RecordSet object To get information about a RecordSet object, use the following methods: Method Description RecordSet.contains() Indicates whether the record set contains the specified record. Returns an array of the names of the columns of a RecordSet RecordSet.getColumnNames() object.
  • Page 78 Adding records to the RecordSet object To add items to a RecordSet object, use the methods. The addItem() addItemAt() method adds a record at the end of the record set. The method inserts a addItem() addItemAt() record at the specific index location; the indexes of all the other records in the RecordSet object are automatically incremented by one.
  • Page 79 To set up a notification event for an ActionScript object, use the RecordSet method and specify the object to notify when the RecordSet object addEventListener() changes. You can specify any object that receives change notifications in the method, as in the following example: addEventListener() myRecordSet.addEventListener("modelChanged", contact_grid);...
  • Page 80 Sorting record sets To sort the records of a RecordSet object, use the methods. The sortItems sortItemBy() method performs an ascending (the default) or descending sort on the records in sortItemBy() the RecordSet object. The method requires a comparison function as an argument, sortItems() and uses that function to sort the records.
  • Page 81: Delivering Recordset Data To Flash Applications In Coldfusion Mx

    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); contact_grid.dataProvider = myRecordSet.filter(mySelectionFunction, theLetter); In this example: •...
  • Page 82 Flash Remoting can deliver pageable record set data to your application in three modes, as described in the following table: Data delivery Description modes ondemand When you access a particular record using the method, the getItemAt() RecordSet object requests the record from the server-side Flash Remoting (default) RecordSet service.
  • Page 83: Using Flash Ui Components With Recordset Objects

    ComboBox • DataGrid • ListBox Additional UI objects might be available at the Macromedia Flash Exchange at http:// dynamic.macromedia.com/go/fl_exchange. The following sections describe how to use the RecordSet objects with these components. Using RecordSet objects directly You can use RecordSet objects directly in the...
  • Page 84 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 property to provide both the list and data values if the record set has two columns dataProvider and the column names are label and data.
  • Page 85: About Working With Xml

    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 method calls the formatting function once for each record in the record bindFormatFunction() set and uses the output of the function to populate a Flash UI component: function myFormatFunction ( record )
  • Page 86 // 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 firstElement:XMLNode = xmlDocument.createElement("test");...
  • Page 87: Chapter 5: The Netconnection Debugger

    • Flash Communication Server • Application server Note: This document does not cover using the NetConnection Debugger with Macromedia Flash Communication Server applications. For more information about Flash Communication Server applications, see Managing Flash Communication Server. Enabling debugging Flash Remoting for Flash MX 2004 ActionScript 2.0 separates the debugging library from the RemotingClasses library so that you can add debugging capabilities to your application when you need them and remove them to reduce the size of your application when you publish it.
  • Page 88 To use the NetConnection Debugger with your Flash Remoting application From the Window menu in Flash, select Other Panels > Common Libraries > Remoting. From the Library panel, drag the RemotingDebugClasses library to the Stage. Use the following directive to import the NetDebug class at the beginning of the import ActionScript code for your Flash application: import mx.remoting.debug.NetDebug;...
  • Page 89: Disabling Debugging

    Select the NetConnection Debugger SWF file and open the context menu with a right-mouse click on Windows or a Ctl-Click on Mac. Select the Open With menu item and then the stand-alone player (Macromedia Flash Player 7.0 on Windows or SAFlashPlayer Mac). Disabling debugging When you no longer need Flash Remoting debugging capabilities, you can remove the RemotingDebugClasses library from your application to reduce its size by approximately 6K.
  • Page 90 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 information on client debug events, see “Client event messages”...
  • Page 91: Common Event Information

    Information about Macromedia ColdFusion debug events. When enabled, any debug events enabled in ColdFusion are reported to the NetConnection Debugger. If ColdFusion debugging information is not enabled in ColdFusion, a single debug error event that notifies the developer that ColdFusion debugging information has not been enabled on the server is returned per transaction.
  • Page 92: Client Event Messages

    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 Trace The object passed to the NetDebug.trace() method.
  • Page 93: Application Server Event Messages

    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 Data Any object associated with the error event. in the Flash Remoting Normally an Exception object.
  • Page 94: Flash Communication Server Events

    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 ColdFusion debugging information: • Template type (for CFM pages only, not CFCs) •...
  • Page 95: Using The Netdebug.initialize() Method

    The example connects to the CustomerData service used by the CustomerInfoExampleAPI sample application: import mx.remoting.Service; import mx.services.Log; import mx.remoting.debug.NetDebug; function CustomerDisplayForm() { NetDebug.initialize(); super(); var custService:Service = new Service( "http://examples.macromedia.com/flashservices/gateway/", new Log(Log.DEBUG,"CustomerDisplayApp"), "petmarket.api.catalogservice", null, null); CustomerDisplayForm(); For more information on the method, see the NetDebug class in the NetDebug.initialize() Flash Remoting ActionScript Dictionary in Help.
  • Page 96: Configuring Debugger Output In Actionscript

    You can send a trace message that includes the connection ID by using the GatewayConnection object’s method, as in the following example: trace() gatewayConnection.trace("I just created myService2 over this connection."); Additionally, the method returns the ID set by the method, and getDebugId() setDebugId() method returns the...
  • Page 97: Chapter 6: Using Flash Remoting With Coldfusion Mx

    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 applications.
  • Page 98: Using The Flash Scope To Pass Parameters To Coldfusion Pages

    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: import mx.remoting.Service; import mx.remoting.PendingCall; import mx.rpc.RelayResponder; //… var CFMService:Service = new Service( "http://localhost/flashservices/gateway", null,...
  • Page 99 The Flash scope has several predefined variables that you can use to pass information, as described in the following table: Variable Description For more information Array containing the parameters passed from the “Using Flash.Params to Flash.Params Flash application to the ColdFusion page. If you do access parameters in a not pass any parameters, still exists,...
  • Page 100 In your ColdFusion page, you access the parameter using , as shown in the Flash.Params following example: <cfquery name="flashQuery" datasource="exampleapps" > SELECT ItemName, ItemDescription, ItemCost FROM tblItems WHERE ItemName='#Flash.Params[1]#' </cfquery> <cfset Flash.Result=flashQuery> Because ColdFusion converts an ActionScript data type to the corresponding ColdFusion data type, you can perform CFML type-specific operations on the parameter.
  • Page 101: Accessing Actionscript Objects

    The following table lists ActionScript collections and describes how to access them in ColdFusion pages: Collection ActionScript example Notes Strict array The Flash Remoting service converts var myArray:Array = new Array(); myArray[0] = "zero"; the array parameters to a ColdFusion myArray[1] = "one";...
  • Page 102 You access in your ColdFusion page using ColdFusion array and structure notation, as follows: <cfset arrayElement1=Flash.x[1]> <cfset arrayElement2=Flash.x[2]> <cfset structElement1=Flash.y.zero> <cfset structElement2=Flash.y.one> You can pass ActionScript objects to ColdFusion pages. The following ActionScript defines an object: var myObj:Object = new Object(); myObj.x = "one";...
  • Page 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 mx.remoting.PendingCall; import mx.rpc.RelayResponder; import mx.rpc.FaultEvent; import mx.rpc.ResultEvent;...
  • Page 104 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 write the record set to the Flash.Result variable.
  • Page 105: Using Flash Remoting With Coldfusion Components

    When you assign a value to the variable, you specify that if the record set has Flash.Pagesize more than that number of records, the record set becomes pageable and returns the number of records specified in the variable. For example: Flash.Pagesize import mx.remoting.Service;...
  • Page 106: Returning Results To Actionscript

    </cffunction> <cffunction name="functB" access="remote" returnType="Struct"> </cffunction> </cfcomponent> Note: For ColdFusion component methods to communicate with Flash applications, you must set tag’s attribute to cffunction access remote You call these functions in ActionScript using the following syntax: CFCService.functA(); CFCService.functB(); Returning results to ActionScript In a ColdFusion component, you use the tag to return a single variable to ActionScript.
  • Page 107 The order in which you specify the tags in the function corresponds to the order in cfargument which the parameters are passed from ActionScript. For example, the following ActionScript call passes three parameters: CFCService.functA(a, b, c); The corresponding ColdFusion component defines three arguments, including the data type of the parameter: <cfcomponent>...
  • Page 108: Accessing Actionscript Objects

    The following example replicates the function that was previously implemented as helloWorld() a ColdFusion page. For more information, see “Using Flash Remoting with ColdFusion pages” on page To create a ColdFusion component that interacts with a Flash application: Create a ColdFusion component, and save it as flashComponent.cfc in the helloExamples directory.
  • Page 109: Using Component Metadata With The Flash Remoting Service

    </cffunction ...> </cfcomponent> 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 component, you access the object elements using named parameters, as follows: <cfcomponent>...
  • Page 110 To create a ColdFusion component that describes itself to the Service Browser: Edit the flashComponent.cfc file in the helloExamples directory by inserting the following code: <cfcomponent> <cffunction name="getTime" access="remote" returnType="Struct" description="Returns date"> <cfset Var tempStruct = StructNew()> <cfset tempStruct.timeVar = DateFormat(Now ())> <cfreturn tempStruct>...
  • Page 111: Using Flash Remoting With Server-Side Actionscript

    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 (with the .asr extension) that you want to call from the Flash application and place them on the server, anywhere under the web server’s root directory.
  • Page 112 For example, the following HTTP header specifies that the character encoding is EUC-JP: Content-Type: text/html; charset=EUC-JP Header Raw response header. For example, macromedia.com returns a header similar to this one: HTTP/1.1 200 OK Date: Mon, 04 Mar 2002 17:27:44 GMT Server: Apache/1.3.22 (Unix) mod_perl/1.26...
  • Page 113 Property Description Responseheader Response header. If there is one instance of a header key, you can access the value as a simple type. If there is more than one instance, values are put in an array in the structure. responseHeader Statuscode HTTP error code and associated error string, which returns the following HTTP status codes:...
  • Page 114: Using Cf.query()

    When using positional arguments, do not use curly braces. Using CF.query() function lets you perform queries against any ColdFusion data source. The CF.query() function maps closely to the CFML tag, although it currently supports a CF.query() cfquery subset of the attributes.
  • Page 115: Calling Web Services From Flash Remoting

    No connection to ColdFusion is made until you make the service function call. The following example Service constructor references a petmarket web service, located at http:// examples.macromedia.com/flashservices/gateway, which returns a list of categories to display in a DataGrid component: var petMarketService:Service = new Service( "http://examples.macromedia.com/flashservices/gateway",...
  • Page 116: Securing Access To Coldfusion From Flash Remoting

    To handle the results of the web service method, you create an event handler with the same name as the service functions with appended to the name. The result handler _Result _Fault displays the results in the DataGrid component, as the following example shows: myGrid function getCategories_Result(result:ResultEvent):Void { // display successful result...
  • Page 117: Assigning Security Roles To Component Functions

    <!--- Verify user name from cflogin.name and password from cflogin.password using your authentication mechanism. For example, you might store this information in an LDAP database. ---> > <cfif cflogin.name eq "bob"> <!--- In this example, bob is in the role of administrator. Typically, you store user roles with authentication information.
  • Page 118 To simplify the debugging of your ColdFusion code, use the tags in your cftry cfcatch ColdFusion page or component to catch errors and return helpful error messages about the errors to the Flash application. For example, the ColdFusion page causeError.cfm contains the following code: <cftry>...
  • Page 119: Chapter 7: Using Flash Remoting For Java

    Java servlets and Java Server Pages (JSPs) • Java Management Extensions (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 chapter has the following sections: •...
  • Page 120: About Flash Remoting For Java

    In design pattern terminology, a Flash application that uses Flash Remoting is the view portion of an application, much as a JavaServer Pages (JSP)-based or servlet-based front end is. Macromedia Flash Player, running in a web browser or in stand-alone mode, is the client in which the view is rendered.
  • Page 121: Calling Java Classes Or Javabeans From Actionscript

    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 is returned to the Flash application as an ActionScript result object from which you can access data locally.
  • Page 122: Getting A Reference To A Java Class Or Javabean In Actionscript

    The following table lists standard ways to add classes to the system classpath: Application server Classpath information Sun™ ONE Web In the Web Server Administration Server console, add classes to the Server Classpath field in the Configure JVM Attributes page of the Java panel. IBM®...
  • Page 123: Invoking Java Methods In Actionscript

    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() { count++; return message + " (count=" + count + ")"; You could use the following ActionScript code to invoke the method, for example, getMessage()
  • Page 124 Looking at the JavaBean code The example Flash application invokes the , and setMessage() getMessage() testBoolean() methods of the following JavaBean: testDate() package com.samples; import java.util.Date; import java.io.Serializable; import org.w3c.dom.Document; public class FlashJavaBean implements Serializable { private String message; private int count; public FlashJavaBean() { message = "Hello World From JavaBean";...
  • Page 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. This Flash application invokes several ‘getter’ and ‘setter’ methods on a JavaBean in the remote server.
  • Page 126 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 function runExample() _parent.setMessage(); _parent.getMessage(); _parent.testBoolean(); _parent.testDate(); // Business functions. function setMessage() flashtestService.setMessage(messageInput.text).responder = new RelayResponder(this, "setMessage_Result", "setMessage_Fault");...
  • Page 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 setMessage_Fault( fe:FaultEvent ):Void messageOutput.text = fe.fault.faultstring; function getMessage_Fault( fe:FaultEvent ):Void messageOutput.text = fe.fault.faultstring; function testBoolean_Result(re:ResultEvent):Void boolOutput.text = "result: "...
  • Page 128: Calling Enterprise Javabeans (Ejbs) From Flash

    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 calling the methods of an EJB from ActionScript, you must get a reference to an EJBHome object.
  • Page 129: Looking At A Flash Application That Calls An Ejb

    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.responder = new RelayResponder(this, "create_Result", "create_Fault"); function create_Result( re:ResultEvent ) flashStatelessEJB = re.result; calculate(); function create_Fault( fe:FaultEvent ) mx.remoting.debug.NetDebug.trace({level:"None", message:"There was a problem"...
  • Page 130 Looking at the EJB code The example Flash application calculates loan payments by invoking the method calculate() on the following stateless session bean: package ejbeans; import java.rmi.*; import java.util.*; import javax.ejb.*; public class SampleLoanBean implements SessionBean ////////////////////////////////////////// ///// General Enterprise EJBean stuff ////////////////////////////////////////// private SessionContext sessionContext;...
  • Page 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 // -------------------------------------------------- // Start up the application // -------------------------------------------------- function ejbLoan_init(){ flashstatelessHome = new Service( "http://localhost/flashservices/gateway", null,...
  • Page 132: Calling Servlets And Jsps From Flash

    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 application servers. JSPs are supported only on Servlet 2.3-compliant application servers.
  • Page 133: Calling A Servlet Or Jsp

    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 in the following example: function go_Clicked() var pc:mx.remoting.PendingCall = servletService.MyServlet();...
  • Page 134: Calling Jmx Mbeans From Flash (Jrun Only)

    137. Calling JMX MBeans from Flash (JRun only) You can call Macromedia JRun application functionality through JMX using Flash Remoting. You connect to a JMX MBean object using the MBean object name in the ActionScript constructor. Service functions are methods defined in the MBean’s manageable Service() interface.
  • Page 135: Getting A Reference To An Mbean In Actionscript

    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: Import the Flash Remoting files: import mx.remoting.Service; Connect to the Flash Remoting gateway and get a reference to the MBean object. You must provide the name of the JMX object under which the MBean is registered, as shown in the following example: jrunDeployerMBean = new Service(...
  • Page 136: Getting A Reference To A Server-Side Actionscript File

    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 application.
  • Page 137: Handling Function Results In Actionscript

    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 ActionScript result handler function and tell the RelayResponder object its name.
  • Page 138 function returns the following LoanInfo bean: calculate() package samples; public class LoanInfo { private double principal; private int months; private float rate; private double monthlyPayment; public LoanInfo() { public LoanInfo(double principal, int months, float rate, double monthlyPayment) { this.principal=principal; this.months=months; this.rate=rate;...
  • Page 139: Using Flash Remoting With Jrun Security

    The following example shows ActionScript code that passes a user name and password from a Flash application to a JRun server: var con1:Connection = new Connection(); con1.connect("http://examples.macromedia.com/flashservices/gateway/"); con1.setCredentials("Flash", "Flashpass"); Looking at the JRun security settings The following example shows entries for the user named Flash and a role, FlashRole, to which the user belongs, using the default security implementation (jrun-users.xml file) for a JRun server:...
  • Page 140: Passing Xml Objects Between Flash And Java

    The following example shows entries for the FlashRole role and corresponding EJB method permissions in an ejb-jar.xml file: <assembly-descriptor> <security-role> <role-name>FlashRole</role-name> </security-role> <method-permission> <role-name>FlashRole</role-name> <method> <ejb-name>SampleLoanBean</ejb-name> <method-name>calculate</method-name> </method> </method-permission> </assembly-descriptor> Passing XML objects between Flash and Java Both ActionScript and Java have object types for storing XML documents, and you can use Flash Remoting to send XML documents back and forth between ActionScript and Java.
  • Page 141: Returning An Xml Object From Java To Flash

    flashtestService.testDocument(xmlDocument); Note: You can also create an XML document object in ActionScript by passing a string representation of the XML to the constructor. For more information, see the Flash new XML(source) documentation set. Returning an XML object from Java to Flash The JavaBean method discussed in the previous section returns an org.w3c.dom.Document object as follows: public Document testDocument(Document doc)
  • Page 142 Chapter 7: Using Flash Remoting for Java...
  • Page 143: Chapter 8: Using Flash Remoting For Microsoft .Net

    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.
  • Page 144: Where Flash Remoting Fits Into The Microsoft .Net Framework

    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 installed. To check whether you have the .NET Framework installed, open the Windows Control Panel and double-click the Add/Remove Programs icon.
  • Page 145: Understanding The Flash Remoting For Microsoft .Net Directory Structure

    The facade structural 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 methods. You can call methods on a DLL facade that is capable of calling various methods on several other DLLs, ASPX pages, or web services, depending on the user’s current context in the application.
  • Page 146: Setting Up A Flash Remoting Asp.net Application

    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 application’s directory in the web root. Flash Remoting automatically installs a blank ASPX page named gateway.aspx, but you can use any ASPX file in the application directory.
  • Page 147: Calling Asp.net Pages From Flash

    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 the Flash Remoting namespace in code-behind files, and so on.
  • Page 148: Invoking Aspx Pages In Actionscript

    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 the Flash authoring environment. When you deploy the Flash application, you should supply the gateway URL using a parameter in the HTML that embeds the SWF file in the web page.
  • Page 149: Using The Flash Remoting Custom Server Control In Aspx Pages

    (bin directory) of your application. You must first register this control, as you would any custom server control, in your ASPX page. Here is an example: <%@ Register TagPrefix="Macromedia" Namespace="FlashGateway" Assembly="flashgateway" %> directive establishes the tag prefix (...
  • Page 150: Using The Flash Remoting Namespace In Code-Behind Files

    In an ASPX page, for example, you access the parameters using strict array syntax, as the following VB.NET code shows: <%@ Page language="vb" debug="true" CodeBehind="myASPPage.aspx.vb" AutoEventWireup="false" Inherits="myASPApp.myASPPage" %> <%@ Register TagPrefix="Macromedia" Namespace="FlashGateway" Assembly="flashgateway" %> <Macromedia:Flash ID="Flash" Runat="Server" /> <% dim message as string message = "Hi "...
  • Page 151: Using Asp.net State Management With Flash Remoting

    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 control properties in the method definition, as the following VB example shows: Page_Load Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load{...
  • Page 152: Using Asp.net Exception Handling

    To return a session variable, you use the property, as shown in the following Flash.Result example: <%@ Page language="c#" debug="true" %> <%@ Register TagPrefix="Macromedia" Namespace="FlashGateway" Assembly="flashgateway" %> <Macromedia:Flash ID="Flash" Runat="Server" /> <% Flash.Result = session.myPreference; %> In the code, the value of the...
  • Page 153: Using Ado.net Objects With Flash Remoting

    RecordSet object. The following C# example could be used in a code-behind file or in the ASPX page that contains the Flash Remoting server control: <%@ Page Language="c#" Debug="true" %> <%@ Register TagPrefix="Macromedia" Namespace="FlashGateway" Assembly="flashgateway" %> <Macromedia:Flash id="Flash" Runat="Server" /> <% // create a SQL connection object and open a connection String source1 = "server=(local)\\NetSDK;"...
  • Page 154 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.PendingCall; import mx.rpc.RelayResponder; import mx.rpc.FaultEvent; import mx.rpc.ResultEvent; var custCountryASPX:Service = new Service( "http://localhost/flashremoting/ gateway.aspx", null, "flashremoting.samples.ADOExamples", null, null );...
  • Page 155: Displaying A Recordset Object In Flash With Actionscript

    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 countryAdapter As System.Data.OleDb.OleDbDataAdapter 'create a dataset object countryAdapter = New System.Data.OleDb.OleDbDataAdapter(selectAll, sqlConnection) 'fill the dataset with the query results...
  • Page 156: Calling Web Services From Flash

    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); // call the ASPX page var pc:PendingCall = ASPXservice.myASPPage(); pc.responder = new RelayResponder(this, "myASPPage_Result", "myASPPage_Fault"); // handler for ASPX page results function myASPPage_Result(re:ResultEvent):Void DataGlue.bindFormatStrings(displayNames, re.result, "#SSN#","#ID#");...
  • Page 157: Invoking Web Service Methods Using Flash Remoting

    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.
  • Page 158: Invoking A Remote Web Service From Flash

    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 getMessage_Fault(fe:FaultEvent):Void serviceMessage.text = fe.fault.faultstring; Invoking a remote web service from Flash Using Flash Remoting for .NET, you can invoke any remote .NET-compatible web service directly from your Flash application with no .NET application development required.
  • Page 159: Calling Asp.net Assemblies From Flash

    In the ActionScript code, you specify the argument with a URL that produces serviceName WSDL. The function maps to the web service method of the same name. Here, getTemp represents an input text field, and represents a dynamic text field. tempDisplay To see the web service proxy assembly (with the .dll extension) that Flash Remoting creates, look in your local assembly cache for a DLL with the same name as the web service.
  • Page 160: Returning An Actionscript Object From An Assembly

    "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 name (FlashRemoting.EchoTests.EchoClass) in the argument. To call an assembly method, you use the class method name serviceName ) as defined in the class file. echoString Returning an ActionScript object from an assembly You can use the ASObject class of the FlashGateway.IO namespace to create and populate...
  • Page 161 This code creates an instance of the ASObject object, named , and uses the property ASType to identify the object as . The method inserts key-value pairs into the object. Calculator Finally, is returned to Flash using the variable. Flash.Result Handling the ActionScript object in Flash The following ActionScript code handles the ActionScript object returned by the assembly: import mx.remoting.Service;...
  • Page 162: 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 file settings in the Windows Registry. The Flash Remoting registry keys are located at HKEY_LOCAL_MACHINE\SOFTWARE\Macromedia\Flash Remoting\1\Registration. The following table lists the Flash Remoting registry keys:...
  • Page 163: Appendix A: Using Netservices And Connection Classes

    “Handling errors for a Connection object” on page 169 Creating a gateway connection using the NetServices object Note: Although using NetServices to create a Connection object is still supported, in Macromedia Flash MX 2004, Macromedia recommends that you create a gateway connection using the Service object.
  • Page 164: Specifying The Gateway In The Netservices Creategatewayconnection() Method

    If you do not otherwise specify a gateway URL, Flash Remoting uses the gateway specified in a method. NetServices.setDefaultGatewayUrl() Macromedia recommends using the method to specify the URL of setDefaultGatewayUrl() the gateway that you use in the Flash authoring environment. Doing so lets you test your Flash Remoting application directly in the development environment, without having to change your code when you deploy your application.
  • Page 165: Authenticating A User To The Application Server

    Flash application from outside the Flash development environment or Macromedia Flash Player, Flash Remoting does not use localhost as the default gateway host. Instead, it replaces localhost and any port specified in the...
  • Page 166: Creating The Service Object

    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 server you are using. Creating the service object Before you access a service function, you must use the method of the gateway getService() connection object to create a service object in the Flash client.
  • Page 167: Handling Results For A Connection Object

    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 method to access a service. When Connection.getService() you access a service using the methods of the Connection object, you can either direct all results for a service to a single object or direct the results of a specific service call to a specific result handler.
  • Page 168: Directing Results For A Service To Specific Responder Objects

    // initialization code specifies gateway, creates connection, calls service if (inited == null) inited = true; NetServices.setDefaultGatewayUrl("http://localhost:8300/flashservices/ gateway") var gatewayConnection:Connection = NetServices.createGatewayConnection(); // specify this object (this) as the responder object howdyService = gatewayConnection.getService("remoteservices", this); // function specific result handlers function helloWorld_Result(result) // display successful result messageDisplay.text = result;...
  • Page 169: Handling Errors For A Connection Object

    // initialization code specifies gateway, creates connection, calls service if (inited == null) inited = true; NetServices.setDefaultGatewayUrl("http://localhost:8300/flashservices/ gateway") var gatewayConnection:Connection = NetServices.createGatewayConnection(); // specify this object (this) as the responder object howdyService = gatewayConnection.getService("remoteservices"); // function specific result handler objects function helloWorld_Result() this.onResult = function(result){ // display successful result...
  • Page 170: The Error Object

    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: Key name Contents code Currently, always SERVER.PROCESSING. level Currently, always Error.
  • Page 171: Error-Handling Strategies

    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 to the Flash SWF ActionScript, and your application can use this information.
  • Page 172 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 multiple service functions function general_Result() this.onResult = function(result){ trace("result is: " + result); this.onStatus = function(error){ trace("result is: "...
  • Page 173: Index

    INDEX debugging messages 90 Action Message Format See AMF understanding 64 ActionScript amf app_server event type 90 connecting to a service 18 amfheaders app_server event type 90 data types, converting from application server 67 AmfMethodCall app_server event message 93 data types, converting to application server 65 AmfRequestHeader app_server event message 93 debugging 94 AmfResponseCall app_server event message 93...
  • Page 174 ASP.NET NetServices 33 and helloWorld application 19 PendingCall 33 application 146 properties and methods 34 assemblies 159 RecordSet 33 pages 147 RelayResponder 33 service name format 39 RemotingConnector 33 specifying functions 42 Service 33 state management 151 client ASPX page event type 90 getting a reference to 147 NetConnection Debugger event messages 92...
  • Page 175 using Flash Remoting MX with ColdFusion custom server control components 105 using in ASPX pages 149 using Flash Remoting MX with ColdFusion pages CustomerInfoExampleAPI application example 47 web services 115 description 50 ColdFusion pages user interface 47 ActionScript object access 101 CustomerInfoExampleAPI example 47 arrays and 100 CustomerInfoExampleCon 57...
  • Page 176 Error app_server event message 93 advantages 13 error app_server event type 90 application structure 30 error handling architecture 14 error object 170 building Flash applications with 16 example 168 building the Flash application 19 Fault object 170 configuring 36 hierarchy 170 custom server control, using in ASPX pages 149 in ColdFusion 117 development environment 16...
  • Page 177 flashvars attribute specifying gateway 38 Java flashvars parameter converting data to ActionScript 67 gateway connection 38 converting data types from ActionScript 65 function results, handling in ActionScript 137 Flash Remoting MX for 120 functions, specifying 42 results 137 serializable objects 72 using XML with Flash Remoting MX 140 gateway Java application servers...
  • Page 178 MBeans pageable record sets 82, 104 calling JMX from Flash 134 PendingCall class getting a reference to 135 description 33 invoking methods in ActionScript 135 importing 36 Microsoft .NET about 143 Flash Remoting design patterns 144 realtime_server, NetConnection Debugger event types Flash Remoting directory structure 145 migrating to ActionScript 2.0 22 record sets...
  • Page 179 replaceItemAt method 78 result handler See also record sets example 31 sorting 80 relationship to service call 30 sortItemsBy method 80 result handling using 73 callback function 21 using directly in components 83 for helloWorld 21 values, returning 77 receiving results 17 RecordSet class ResultEvent class description 33...
  • Page 180 handling errors 43 handling results 43 web page, specifying gateway in 38 passing parameters 41 web service result handling example 167 service name format 39 specifying 42 specifying function 42 service name web service methods for helloWorld 21 calling using ColdFusion 115 Service object invoking using Flash Remoting MX 157 calling functions 41...

This manual is also suitable for:

Flash remoting mx

Table of Contents