[冷枫]Flex精华摘要 4:使用AS脚本

开发者在线 Builder.com.cn 更新时间:2007-09-23作者:冷枫 来源:CSDN

本文关键词: 冷枫 Flex AS脚本

MXML文件中实现ActionScript逻辑的几种方法:
最简单的方法,在一个MXML文件中通过组件的事件直接书写简单的逻辑控制,但是并不推荐。

 

1. <mx:Application xmlns:mx='http://www.macromedia.com/2003/mxml'>
 

2. <mx:Panel title='My Application' >
 

3. <mx:HBox>
 

4. <mx:Label text='Temperature in Farenheit:'/>
 

5. <mx:TextInput id='farenheit' width='120'/>
 

6. <mx:Button label='Convert' click='celsius.text=(farenheit.text-32)/1.8;' />
 

7. <mx:Label text='Temperature in Celsius:'/>
 

8. <mx:Label id='celsius' width='120' fontSize='48'/>
 

9. </mx:HBox>

10.  </mx:Panel>

11.  </mx:Application>

 

 



第二种,在MXML文件中定义函数调用,比较适合简单的应用,如

 

1. <mx:Application xmlns:mx='http://www.macromedia.com/2003/mxml'>
 

2. <mx:Script>
 

3. <![CDATA[
 

4. function calculate() { 
 

5. celsius.text=(farenheit.text-32)/1.8;
 

6.  }
 

7. ]]>
 

8. </mx:Script>
 

9. <mx:Panel title='My Application' >

10.  <mx:HBox>

11.  <mx:Label text='Temperature in Farenheit:'/>

12.  <mx:TextInput id='farenheit' width='120'/>

13.  <mx:Button label='Convert' click='calculate();' />

14.  <mx:Label text='Temperature in Celsius:'/>

15.  <mx:Label id='celsius' width='120' fontSize='48'/>

16.  </mx:HBox>

17.  </mx:Panel>

18.  </mx:Application>

 

 

用户评论

  • 用户名
  • 评论内容