วันอังคารที่ 13 มกราคม พ.ศ. 2552

Working with data

Working with data
Flash offers many options when it comes to working with external data sources such as web services.
XML is natively supported in both ActionScript 2.0 and 3.0. In addition, there are many other data formats
that a developer can use when working with data:
LoadVar objects, which consist of variable names and values, can be used when dealing with
simple text strings.
JSON, a method of encapsulating text and numerical data within native JavaScript objects, is
perfectly usable within Flash, and its parsing is straightforward because of the shared
ECMAScript syntax.
ActionScript 3.0 is capable of directly manipulating binary data.
Other techniques, such as SWX, which we will cover later in the book, provide a way of essentially
serializing Flash objects and communicating data as a SWF, eliminating any parsing overhead.
Compared to JavaScript, Flash is also a lot more flexible when it comes to loading cross-domain files
and resources, while also running within a security sandbox that mitigates most security risks. Imagine
a Flash application hosted on www.mydomain.com. During the course of its execution, it makes an
attempt to call a data service located at www.datadomain.com/services/myservice. Before the call is
made, Flash Player makes an additional call to a cross-domain security file, www.datadomain.com/
crossdomain.xml. This is a file that can be used to specify whether requests from a Flash application
hosted on a specific domain are allowed to access resources on the web server.
For example, if you wanted to allow any application to use your service, you would create a crossdomain.
xml file that looked like this:




You could also restrict access to your service so that it could be accessed only from applications on
mydomain.com, like this:




If a crossdomain.xml file does not exist or does not permit access, then any calls to that domain
would not be made.

ไม่มีความคิดเห็น:

แสดงความคิดเห็น