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
loadVariablesNum()
•
The LoadVars methods that use the HTTP or HTTPS protocol to send and load information
in URL-encoded format are
•
The methods that use HTTP or HTTPS protocol to send and load information as XML are
,
XML.send()
•
The methods that create and use a TCP/IP socket connection to send and load information as
XML are
XMLSocket.connect()
Checking for loaded data
Each function or method that loads data into a SWF file (except
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
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()
use the
event of the
data
loadVariables()
variable is loaded. If you use
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
movie clip
loadTargetMC
on(release){
loadVariables("myData.txt", _root.loadTargetMC);
}
An
onClipEvent()
lastFrameVisited
after all the variables, including
onClipEvent(data) {
goToAndPlay(lastFrameVisited);
}
If you use the
XML.load()
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
. For the XMLSocket object, use
XML.onData()
178
Chapter 10: Working with External Data
,
loadMovie()
load()
, and
XML.load()
XML.sendAndLoad()
and
lastFrameVisited
:
or
loadMovie()
onClipEvent()
to load the data, the
loadMovie()
:
handler assigned to the
, which is loaded from the file
lastFrameVisited
,
XML.sendAndLoad()
,
getURL()
loadVariables()
, and
loadMovieNum()
,
, and
send()
sendAndLoad()
.
XMLSocket.send()
until you're sure the variable has loaded from
, you can load information into a movie clip target and
handler to execute a script. If you use
onClipEvent(data)
to load the data, the
instance uses the variable
loadTargetMC
myData.txt
, are loaded:
, and
XMLSocket.connect()
XMLSocket.onConnect()
,
.
.
.
XMLSocket.send()
handler executes when the last
onClipEvent(data)
myData.txt
. The following will execute only
methods, you
XML.onLoad()
.
) is
handler
into the
or
Need help?
Do you have a question about the FLASH MX 2004 - ACTIONSCRIPT and is the answer not in the manual?
Questions and answers