212008/070/168
转载:Flex学习笔记(一)
转自:小胖&大胖,作者:Alps Wong
Adobe® Flex® 3 是用于构建和维护在所有主要浏览器、桌面和操作系统一致地部署的极具表现力的 Web 应用程序的高效率的开放源码框架。
---Adobe
如果让我来形容的话,只有一句话说"Flex is the future!"。
---Adobe
如果让我来形容的话,只有一句话说"Flex is the future!"。
1
<?xml version="1.0" encoding="utf-8"?>
2
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
3
<mx:Button name="applications" id="test"/>
4
</mx:Application>
<?xml version="1.0" encoding="utf-8"?>2
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">3
<mx:Button name="applications" id="test"/>4
</mx:Application>报出一个error:
1 'test': identifier and class may not have the same name.
二、MXML文件结构
1)先看一个最简单的mxml文件
1
<?xml version="1.0" encoding="utf-8"?>
2
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
3
</mx:Application>
<?xml version="1.0" encoding="utf-8"?>2
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">3
</mx:Application>①version:声明xml语法的版本号。
②encoding:声明xml的字符集。
③mx:Application:文件主入口的标志,一个工程可以有多个mxml,但只能有一个mx:Application。
④xmlns:mx:定义了xml的命名空间。
我们打开Flex builder\sdks\3.0.0\frameworks\flex-config.xml,看到这样一段话
1
<namespaces>
2
<!-- Specify a URI to associate with a manifest of components for use as MXML -->
3
<!-- elements.-->
4
<namespace>
5
<uri>http://www.adobe.com/2006/mxml</uri>
6
<manifest>mxml-manifest.xml</manifest>
7
</namespace>
8
</namespaces>
<namespaces>2
<!-- Specify a URI to associate with a manifest of components for use as MXML -->3
<!-- elements.-->4
<namespace>5
<uri>http://www.adobe.com/2006/mxml</uri>6
<manifest>mxml-manifest.xml</manifest>7
</namespace>8
</namespaces>可以看到flex通过http://www.adobe.com/2006/mxml这个资源标识符,对应了一个xml文件
我们打开同一目录下的mxml-manifest.xml文件,里面列出了mxml中所有标签以及与其相关联的类。
1
<componentPackage>
2
3
<!-- airframework -->
4
<component id="FileSystemComboBox" class="mx.controls.FileSystemComboBox"/>
5
<component id="FileSystemDataGrid" class="mx.controls.FileSystemDataGrid"/>
6
。。。。。。
7
8
</componentPackage>
9
<componentPackage>2

3
<!-- airframework -->4
<component id="FileSystemComboBox" class="mx.controls.FileSystemComboBox"/>5
<component id="FileSystemDataGrid" class="mx.controls.FileSystemDataGrid"/>6
。。。。。。7

8
</componentPackage>9

⑤layouy:定义了页面的布局方式。'absolute'表示使用绝对位置,它内部包含的所有子元素都是通过x,y坐标来定位布局的。
1
<?xml version="1.0" encoding="utf-8"?>
2
<mx:Button xmlns:mx="http://www.adobe.com/2006/mxml"/>
3
<?xml version="1.0" encoding="utf-8"?>2
<mx:Button xmlns:mx="http://www.adobe.com/2006/mxml"/>3

然后我们在主mxml中调用它
1
<?xml version="1.0" encoding="utf-8"?>
2
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" xmlns:buttons="*">
3
<buttons:test/>
4
</mx:Application>
<?xml version="1.0" encoding="utf-8"?>2
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" xmlns:buttons="*">3
<buttons:test/>4
</mx:Application>四、ActionScript文件
1)所有mxml文件经过编译后,都会编译成as文件。
2)mxml文件中通过<mx:Script>标签来访问内部as代码块。不过在xml中'<'和'&'是禁止使用的。所以应该用如下的方式访问
1
<mx:Script>
2
<
4
5
]]>
6
</mx:Script>
<mx:Script>2
<
4

5
]]>6
</mx:Script>3)访问外部的ActionScript文件
1
<mx:Script source="XXXX.as"/>
<mx:Script source="XXXX.as"/>4)关于注释
1
<?xml version="1.0" encoding="utf-8"?>
2
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" xmlns:buttons="*">
3
<buttons:test/>
4
<mx:Script>
5
<![CDATA[
6
// 单行注释
7
/*
8
多行注释
9
*/
10
]]>
11
</mx:Script>
12
<!--MXML注释-->
13
</mx:Application>
<?xml version="1.0" encoding="utf-8"?>2
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" xmlns:buttons="*">3
<buttons:test/>4
<mx:Script>5
<![CDATA[6
// 单行注释7
/*8
多行注释9
*/10
]]>11
</mx:Script>12
<!--MXML注释-->13
</mx:Application>好了,第一章先到这里吧,有不对的地方欢迎大家指摘问题。
<!-- JiaThis Button BEGIN -->
<div id="ckepop">
<a href="http://www.jiathis.com/share/" class="jiathis jiathis_txt jtico jtico_jiathis" target="_blank">分享到:</a>
<a title="分享到QQ空间" class="jiathis_button_qzone">QQ空间</a>
<a title="分享到人人网" class="jiathis_button_renren">人人网</a>
<a title="分享到开心网" class="jiathis_button_kaixin001">开心网</a>
<a title="分享到新浪微博" class="jiathis_button_tsina">新浪微博</a>
</div>
<script type="text/javascript" src="http://v1.jiathis.com/code/jia.js" charset="utf-8"></script>
<!-- JiaThis Button END -->
以下文章您或许也感兴趣
- 转载:Flex学习笔记(二)
- 转载:Flex学习笔记(三)
- [转]fengoffice用户/用户组/工作区"权限"设置说明
- Feng Office之订户
- 转载:Flex学习笔记(四)
- Feng Office任务之我见