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 didn’t 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 doesn’t 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.”
CAU
T
IO
N
If a web server does not return a status code to the Flash Player, the number 0 is
returned to the
onHTTPStatus
event handler.
Содержание FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
Страница 1: ...Learning ActionScript 2 0 in Flash...
Страница 8: ...8 Contents...
Страница 18: ...18 Introduction...
Страница 30: ...30 What s New in Flash 8 ActionScript...
Страница 66: ...66 Writing and Editing ActionScript 2 0...
Страница 328: ...328 Interfaces...
Страница 350: ...350 Handling Events...
Страница 590: ...590 Creating Interaction with ActionScript...
Страница 710: ...710 Understanding Security...
Страница 730: ...730 Debugging Applications...
Страница 780: ...780 Deprecated Flash 4 operators...
Страница 830: ...830 Index...