178
Chapter 10: Working with External Data
Several ActionScript functions and methods let you pass information into and out of a SWF file.
Each function or method uses a protocol to transfer information, and requires information to be
formatted in a certain way.
•
The functions and MovieClip methods that use the HTTP or HTTPS protocol to send
information in URL-encoded format are
getURL()
,
loadVariables()
,
loadVariablesNum()
,
loadMovie()
, and
loadMovieNum()
.
•
The LoadVars methods that use the HTTP or HTTPS protocol to send and load information
in URL-encoded format are
load()
,
send()
, and
sendAndLoad()
.
•
The methods that use HTTP or HTTPS protocol to send and load information as XML are
XML.send()
,
XML.load()
, and
XML.sendAndLoad()
.
•
The methods that create and use a TCP/IP socket connection to send and load information as
XML are
XMLSocket.connect()
and
XMLSocket.send()
.
Checking for loaded data
Each function or method that loads data into a SWF file (except
XMLSocket.send()
) is
asynchronous
: the results of the action are returned at an indeterminate time.
Before you can use loaded data in a SWF file, you must check to see if it has been loaded. For
example, you can’t load variables and manipulate their values in the same script. In the following
script, you can’t use the variable
lastFrameVisited
until you’re sure the variable has loaded from
the file
myData.txt
:
loadVariables("myData.txt", 0);
gotoAndPlay(lastFrameVisited);
Each function or method has a specific technique you can use to check data it has loaded. If you
use
loadVariables()
or
loadMovie()
, you can load information into a movie clip target and
use the
data
event of the
onClipEvent()
handler to execute a script. If you use
loadVariables()
to load the data, the
onClipEvent(data)
handler executes when the last
variable is loaded. If you use
loadMovie()
to load the data, the
onClipEvent(data)
handler
executes each time a fragment of the SWF file is streamed into Flash Player.
For example, the following button action loads the variables from the file
myData.txt
into the
movie clip
loadTargetMC
:
on(release){
loadVariables("myData.txt", _root.loadTargetMC);
}
An
onClipEvent()
handler assigned to the
loadTargetMC
instance uses the variable
lastFrameVisited
, which is loaded from the file
myData.txt
. The following will execute only
after all the variables, including
lastFrameVisited
, are loaded:
onClipEvent(data) {
goToAndPlay(lastFrameVisited);
}
If you use the
XML.load()
,
XML.sendAndLoad()
, and
XMLSocket.connect()
methods, you
should define a handler that will process the data when it arrives. This handler is a property of an
XML or XMLSocket object to which you assign a function you have defined. The handlers are
called automatically when the information is received. For the XML object, use
XML.onLoad()
or
XML.onData()
. For the XMLSocket object, use
XMLSocket.onConnect()
.
Содержание FLASH MX 2004 - ACTIONSCRIPT
Страница 1: ...ActionScript Reference Guide...
Страница 8: ...8 Contents...
Страница 12: ......
Страница 24: ...24 Chapter 1 What s New in Flash MX 2004 ActionScript...
Страница 54: ...54 Chapter 2 ActionScript Basics...
Страница 80: ...80 Chapter 3 Writing and Debugging Scripts...
Страница 82: ......
Страница 110: ...110 Chapter 5 Creating Interaction with ActionScript...
Страница 112: ......
Страница 120: ...120 Chapter 6 Using the Built In Classes...
Страница 176: ......
Страница 192: ...192 Chapter 10 Working with External Data...
Страница 202: ...202 Chapter 11 Working with External Media...
Страница 204: ......
Страница 782: ...782 Chapter 12 ActionScript Dictionary...
Страница 793: ...Other keys 793 221 222 Key Key code...
Страница 794: ...794 Appendix C Keyboard Keys and Key Code Values...
Страница 798: ...798 Appendix D Writing Scripts for Earlier Versions of Flash Player...
Страница 806: ...806 Appendix E Object Oriented Programming with ActionScript 1...
Страница 816: ...816 Index...