MACROMEDIA FLASH REMOTING MX-USING FLASH REMOTING FOR FLASH MX 2004 ACTIONSCRIPT 2.0 Spezifikationen Seite 23

  • Herunterladen
  • Zu meinen Handbüchern hinzufügen
  • Drucken
  • Seite
    / 40
  • Inhaltsverzeichnis
  • LESEZEICHEN
  • Bewertet. / 5. Basierend auf Kundenbewertungen
Seitenansicht 22
This is the Title of the Book, eMatter Edition
Copyright © 2003 O’Reilly & Associates, Inc. All rights reserved.
Hello World
|
21
Section 1 of Example 1-1 includes the NetServices.as library, which contains the code
necessary to connect to a Flash Remoting–enabled server from Flash. If you do not
include NetServices.as, the example will not work, but you will not receive any errors
within the authoring environment.
Section 2 initializes two variables:
myURL and myServicePath.ThemyURL variable will
be used to create a NetConnection object that points to the server. The
myServicePath
variable will be used to create a service object that points to the service that will be
called.
The
myURL variable specifies the URL to the Flash Remoting gateway installed on the
server. If the Flash Remoting gateway is installed on a Microsoft .NET server, the
URL will point to the .aspx file for the gateway. Similarly, if you are using AMFPHP,
the URL will point to a gateway.php file on your server.
The
myServicePath variable specifies the path on the server to the remote service that
will be called. The naming convention is similar to a Java package, with each section
representing a directory on the server and the last section pointing to the actual ser-
vice. If the remote service is a Microsoft .NET DLL,
myServicePath should refer to
the DLL’s namespace and class name. Similarly, if the remote service is a Java class,
the
myServicePath variable will refer to the package name and class name of the Java
class. If the remote service is a web service,
myServicePath should contain the path to
the web service’s WSDL file.
Calls from the Flash Player to the application server via the Flash Remoting gateway
are asynchronous. Code execution within the Flash Player continues while data is
being loaded, which is similar to loading XML into the Flash Player. You must define
callback functions, which will be called automatically when the data loads from the
server.
A callback function is a function that is called when a specific event
occurs. For example, attaching a callback function to an object’s
onClick property causes the callback function to execute whenever the
object is clicked. Similarly, a remote service call causes a specific event
to occur, which can have a callback function associated with it.
In ActionScript, callback functions can be attached as properties to a generic object
(instantiated from the Object class). The functions are used to catch data and mes-
sages sent back from the server.
Section 3 of Example 1-1 creates an object and attaches two callback functions to it.
The onResult( ) callback function is called when data is returned from the remote
var myService = myServer.getService(myServicePath, myResult);
myService.sayHello( );
Example 1-1. Client-side ActionScript code (HelloWorld.fla) (continued)
Seitenansicht 22
1 2 ... 18 19 20 21 22 23 24 25 26 27 28 ... 39 40

Kommentare zu diesen Handbüchern

Keine Kommentare