Understanding AS3 and XML
2009-10-26 00:00:00 来源:WEB开发网When you are about to design a Flash application using dynamic content, such as an image gallery or a tile based game, XML is one of the best ways to handle external content because it’s very easy to create, understand, read, and update.
AS3 now uses a system called ECMAScript for XML (E4X) that will do most of the dirty job, allowing us to focus on the application we are goingo to write.
From Wikipedia: ECMAScript for XML (E4X) is a programming language extension that adds native XML support to ECMAScript (which includes ActionScript, DMDScript, JavaScript, JScript). The goal is to provide an alternative to DOM interfaces that uses a simpler syntax for accessing XML documents. It also offers a new way of making XML visible. Before the release of E4X, XML was always accessed at an object level. E4X instead treats XML as a primitive (like characters, integers, and booleans). This implies faster access, better support, and acceptance as a building block (data structure) of a program.
So let’s start playing with it, and let me show you the one of the worst XML you can find… a collection of Sokoban levels (guess why?)
<?xml version="1.0" encoding="ISO-8859-1"?>
<SokobanLevels xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="SokobanLev.xsd">
<Title>Fly</Title>
<Description>Simple Microban-style levels.</Description>
<Email>bsimpson_910@hotmail.com</Email>
<LevelCollection Copyright="Tim LeFevre" MaxWidth="15" MaxHeight="11">
<Level Id="The Fly_1" Width="11" Height="11">
<L> ####</L>
<L> # #</L>
<L> ## ####</L>
<L>###.$.$. #</L>
<L># $.$.$ ##</L>
<L># .$@$. #</L>
<L>## $.$.{$selection}nbsp; #</L>
<L> # .$.$.###</L>
<L> #### ##</L>
<L> # #</L>
<L> ####</L>
</Level>
<Level Id="The Fly_2" Width="13" Height="11">
<L> ####</L>
<L> # #</L>
<L> ### ####</L>
<L>### .$.$. #</L>
<L># $.$.$ ###</L>
<L># .$#$. #</L>
<L>### $.$.{$selection}nbsp; #</L>
<L> # .$.$. ###</L>
<L> #### ###</L>
<L> # @#</L>
<L> ####</L>
</Level>
<Level Id="The Fly_3" Width="15" Height="11" Copyright="1106 1087 Jordi Doménech">
<L> ####</L>
<L> ## ##</L>
<L> # ###</L>
<L>#####$.$.$ ###</L>
<L># $.#.#.{$selection}nbsp; ##</L>
<L># $.@.{$selection}nbsp; #</L>
<L>## $.#.#.{$selection}nbsp; #</L>
<L> ### $.$.$#####</L>
<L> ### #</L>
<L> ## ##</L>
<L> ####</L>
</Level>
</LevelCollection>
</SokobanLevels>
Tags:Understanding AS and
编辑录入:爽爽 [复制链接] [打 印]- ››Android 当修改一些代码时,使用什么编译命令可以最...
- ››Android 如何添加一个apk使模拟器和真机都编译进去...
- ››Android 修改Camera拍照的默认保存路径
- ››Android 如何修改默认输入法
- ››asp.net页面弄成伪静态页面
- ››android开发中finish()和System.exit(0)的区别
- ››Android手势识别简单封装类
- ››android中查看项目数字证书的两种方法
- ››Android中获取IMEI码的办法
- ››android 相机报错 setParameters failed
- ››Android重启运用程序的代码
- ››Android为ListView的Item设置不同的布局