EasyManua.ls Logo

MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH - Page 643

MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
830 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
Using HTTP to connect to server-side scripts 643
The previous code creates a new text field on the Stage and enables text field autosizing.
Next, a LoadVars object is created and two event handlers:
onHTTPStatus and onLoad.
The
onHTTPStatus event handler is new to Flash Player 8 and is invoked when a
LoadVars.load() or LoadVars.sendAndLoad() operation has completed. The value
passed to the
onHTTPStatus event handler function (httpStatus in the previous code)
contains the HTTP status code definition for the current load operation. If the SWF file
was able to successfully load the text file, the value of
httpStatus is set to 200 (HTTP
status code for “OK”). If the file didnt exist on the server, the value of
httpStatus is set
to 404 (HTTP status code for “Not Found”). The second event handler,
LoadVars.onLoad(), gets called after the file has finished loading. If the file successfully
loaded, the value of the
success parameter is set to true, otherwise the success
parameter is set to
false. Finally, the external file is loaded using the LoadVars.load()
method.
3. Select Control > Test Movie to test the Flash document.
Flash displays an error message to the Output panel stating that it was unable to load the
image because it doesnt exist on the server. The
onHTTPStatus event handler traces the
status code of 404 since the file could not be found on the server, and the
onLoad event
handler sets the
params_txt text field’s text property to “unable to load text file.
CAUTION
If a web server does not return a status code to the Flash Player, the number 0 is
returned to the
onHTTPStatus event handler.

Table of Contents

Related product manuals