1.如何動態載入mxml文件
在web開發中,往往需要講網站中的所有頁面用樹形列表體現出來,而這些頁面的地址是存在于數據庫中的,那么前臺AS代碼中只能拿到
這個數據的XML格式,最初的設想是用eval來實現,但AS3中取消了eval,后來又使用反射,無奈AS3的反射實在是有點問題,最后查到可以用
ModuleLoader來解決這個問題。
主程序
1
<?xml version="1.0" encoding="utf-8"?>
2
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
3
<mx:Script>
4
<
14
}
15
]]>
16
</mx:Script>
17
<mx:XMLList id="ct">
18
<node name="根節點">
19
<node name="學生管理">
20
<node name="學生瀏覽"/>
21
<node name="學生查看"/>
22
</node>
23
<node name="班級管理">
24
<node name="班級瀏覽"/>
25
</node>
26
</node>
27
</mx:XMLList>
28
29
<mx:Panel layout="vertical" width="80%" height="80%" x="63.5" y="58">
30
<mx:HDividedBox width="100%" height="100%">
31
<mx:Tree width="20%" height="100%" dataProvider="{ct}" showRoot="false"
32
labelField="@name" change="showCanvas(event);"/>
33
<mx:ModuleLoader id="rightCanvas" width="80%" height="100%" />
34
</mx:HDividedBox>
35
</mx:Panel>
36
</mx:Application>
37

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

子程序:
1
<?xml version="1.0" encoding="utf-8"?>
2
<mx:Module xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="400" height="300">
3
<mx:Canvas width="100%" height="100%">
4
<mx:Label x="243.5" y="181" text="asdfa;sldkfjaks;djf;alskdjfkld" width="144" height="103"/>
5
</mx:Canvas>
6
</mx:Module>
注意被加載的子程序一定要繼承自Module
2

3

4

5

6

每天進步一點點
