Flash and Java development tools combined _ "Java for Flash dynamic web development Letters" _ serial sections (5)

  Article 09 in Chapter Flash Video Application procedures and the results of result sets targets 

  To connect to the Java application server on the Flash Remoting MX services and long-distance call services, and must use mx.remoting mx.rpc two ActionScript class library: This two class library contains all the Flash Remoting MX for ActionScript 2.0 classes and methods to achieve. 

  Among them, mx.remoting is a very core ActionScript class library, and it contains the application server to connect all the objects and methods, and can be used to call mx.rpc remote method and the results. 

  In the previous chapters, we have introduced through Flash Remoting MX gateway services in the Servlet and JSP page to the Flash movie data transmission applications, but also on how to use Flash videos to the application Servlet and JSP page transmission parameters, and introduced how to use Flash Remoting MX for Java and JDBC database of calls, and created a few simple examples. 

  However, when the JSP and Servlet Web applications to the Flash movie transfer data to be received, how to deal with receiving the results?    In the previous example we have used a number of methods, it is only in the Flash movie applications rich in the results of the most simple method, Flash Remoting MX for ActionScript 2.0 components built-rich ActionScript scripting syntax used to the results. 

  On the detail of this chapter to tell us about these ActionScript scripting syntax. 

  9.4 DataGlue use of collecting data processing records 

  In a Flash UI components RecordSet record set in the show, the general can use the built-in components setDataProvider () method or dataProvider attributes, but if you would like a Flash UI components on show in a field of all Records are more difficult. 

  For example, in the previous example, we should in a drop-down list box components on show in a hotel, they must first create a new single-field records set the original record on the field is filled with new data Single-field record set, and then re-use components setDataProvider () method or dataProvider attributes, it is clear that this comparison trouble, and the use of resources will be more. 

  To solve this problem, Flash Remoting MX also called DataGlue the built-in ActionScript category.    DataGlue ActionScript use of documents can be in a Flash UI components RecordSet record set in the show.    DataGlue ActionScript types of documents accompanying Flash Remoting MX components to be installed, it is necessary to use it, must be imported into the corresponding class library, you can use the following his script: 

  Import mx.remoting.DataGlue; 

  DataGlue built-in two categories: DataGlue.bindFormatStrings () and DataGlue.bindFormatFunction (), the use of these two methods can be in the Flash UI components (such as portfolio boxes and list boxes) show record set. 

  9.4.1 bundled methods used DataGlue.bindFormatStrings record set 

  Can be used DataGlue.bindFormatStrings () method in a Flash UI components (such as portfolio boxes and list boxes) displayed RecordSet.    Below ActionScript section of the script code will be bound to result RecordSet named displayNames the list box UI components: 

  DataGlue.bindFormatStrings (displayNames, result, "ContactName # #", "# # customerID"); 

  In this section of the code, and the latter two parameters are passed to the function (ContactName # and # # # is the record set customerID column).    When users select components in a special record, ContactName are displayed on the UI components, which are customerID return.    Below, we have to transform to the previous example, a look at how to use DataGlue category. 

  A    Open in front of us to create a chapter of the Restaurant_component.fla documents, will file for Save Restaurant_component_DataGlue.fla; 

2   Maintain the current state is located in the main time frame edit, modify the time frame of the script code.    In the "moves" the panel added his script code below: 

  Import mx.remoting.DataGlue; 

3   Double-click on the stage video clips components main_mc example, the main components in a movie clip editing state, the selected layer Script.    Maintain the layer selected in the "moves" panel modify the script code: 

  Below will be a section of the script code: 

  Var newRecordSet: new RecordSet RecordSet = ([ "hotelName"]); 

  For (var i = 0; i <resultRecordSet.length; i + +) ( 

  NewRecordSet.addItemAt (i (hotelName: resultRecordSet.getItemAt (i). Hotel_name)); 

  ) 

  If (newRecordSet.isLocal ()) ( 

  NewRecordSet.addItemAt (0, (hotelName: "Please choose a restaurant or hotel")); 

  HotelName_cb.dataProvider = newRecordSet; 

  ) 

  Replaced 

  DataGlue.bindFormatStrings (hotelName_cb, resultRecordSet, "hotel_name # #", "# # hotel_name"); 

  Can see that the front lines of code to achieve multi-function, and his party can now only has been achieved. 

4   It is because of the use of DataGlue, which is why the UI components of the reader should also change its ways.    In this case, this script code in the function applyFilter () in: 

  Below will be a section of the script code 

  List_lb.dataProvider = resultRecordSet.filter (thisFilter, hotelName_cb.selectedItem [ "hotelName"]); 

  Replaced 

  List_lb.dataProvider = resultRecordSet.filter (thisFilter, hotelName_cb.selectedItem.label); 

5   Finally can test results, and we can see examples in front of the same functions. 

  9.5 RemotingConnector components and the use of data binding 

  RemotingConnector Flash is a data components, the use of the components you can very easily with the establishment of long-distance service connections - the long-distance service must be through Flash Remoting MX gateways - and long-distance call services can be defined by function method , it requires the use of drag-and-drop components to the stage and defined component parameters, but also can use the data binding Flash function. 

  We are here to introduce the preparation of the first through the use of script code RemotingConnector components. 

  9.5.1 prepared script code components used RemotingConnector 

  Prepared script code through the use of the component, it must first begin RemotingConnector drag-and-drop components of the current arena (or in the library as long as we can), and then can begin to write code using the component, which is the first step in the use of the components. 

  In addition, in the preparation of the script code to import RemotingConnector category, which is the use of the components of the prepared script code first step, the script can use the following statement: 

  Import mx.data.components.RemotingConnector; 

  Below we will use an example of how to use the components. 

  A    We open the front of a document created Restaurant_component.fla, Save As Restaurant_component_RC.fla documents; 

2   Documents maintained in a state of the main Timeline edit and change the time frame of the script code as follows: 

  Stop (); 

  //———————————————— ————- 

  / / Import category RemotingConnector 

  Import mx.data.components.RemotingConnector; 

  / / Examples of structural components and RemotingConnector examples attribute definition 

  Var my_rc: RemotingConnector = new RemotingConnector (); 

  My_rc.addEventListener (the "result" returnRowSet_Result); 

  My_rc.addEventListener ( "status", returnRowSet_Status); 

  My_rc.gatewayUrl = "http://localhost:8080/3JK/gateway"; 

  My_rc.methodName = "returnRowSet"; 

  My_rc.serviceName = "3JK"; 

  My_rc.suppressInvalidCalls = true; 

  Function GetRestaurantInfo (): Void ( 

  If (selectedhotel_name undefined & selectedhotel_flavor == == == selectedhotel_location & undefined undefined) ( 

  / / Definition of parameters for the air 

  My_rc.params = null; 

  / / Trigger connections, called remote method services 

  My_rc.trigger (); 

  Else () 

  / / Definition transmitted to the remote method parameters services 

  My_rc.params = (hotel_name: selectedhotel_name, hotel_flavor: selectedhotel_flavor, hotel_location: selectedhotel_location); 

  / / Trigger connections, called remote method services 

  My_rc.trigger (); 

  Selectedhotel_name = "load data"; 

  ) 

  ) 

  Function returnRowSet_Result (ev: Object) ( 

  / / Reception results 

  Main_mc.list_lb.removeAll (); 

  Main_mc.list_lb.dataProvider = ev.target.results; 

  Selectedhotel_name = ""; 

  FetchOK = 1; 

  Main_mc.resultRecordSet = ev.target.results; 

  ) 

  Function returnRowSet_Status (stat: Object) ( 

  / / Receive errors 

  Trace ( "receiving the wrong"); 

  ) 

  / / Initialization 

  Function ini (): Void ( 

  If (this.inited! = Undefined) ( 

  Return; 

  Else () 

  Var inited: Boolean = true; 

  GetRestaurantInfo (); 

  ) 

  ) 

  Ini (); 

3   Open components panel, RemotingConnector components will drop to the stage to create an example (actually, just put in the can.) 

  Finally can test results, and we can see examples in front of the same functions. 

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Facebook
  • DotNetKicks
  • DZone
  • Netvouz
  • Propeller

Tags: , , ,

Releated Java Articles

Comments

Leave a Reply