CSDN博客

img lucky_cxj

flex 点击按钮图片切换

发表于2008/9/28 18:04:00  4280人阅读

  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.     <![CDATA[
  5.         import mx.controls.*;
  6.             private var num:int;
  7.             private function pic(direction:String):void{
  8.                 if(direction == 'next'){
  9.                     this.num++;
  10.                     if (this.num >= xmlPic.pic.length()){this.num = xmlPic.length()-1;}
  11.                 }
  12.                 if(direction == 'prev'){
  13.                     this.num--;
  14.                     if(this.num < 0){this.num = 0;}
  15.                 }       
  16.                 myimg.load(xmlPic.pic[num].@path);//这一句也可这样写 myimg.load((xmlPic.children())[num].@path);
  17.             }
  18.     ]]>
  19. </mx:Script>
  20. <mx:XML id="xmlPic" source="data/pic.xml" />
  21. <mx:Panel horizontalCenter="0" width="400" height="300">
  22.         <mx:Canvas horizontalCenter="0" width="100%" height="100%">
  23.         <mx:VBox width="100%" height="100%" horizontalAlign="center" verticalAlign="middle">            
  24.             <mx:Image id="myimg" width="158" height="120" source="{xmlPic.pic[0].@path}"/>  
  25.             <mx:HBox>
  26.                 <mx:Button id="prev" label="上一张" click="pic('prev')"/>      
  27.                 <mx:Button id="next" label="下一张" click="pic('next')"/>
  28.             </mx:HBox>          
  29.         </mx:VBox>          
  30.         </mx:Canvas>        
  31.     </mx:Panel>     
  32. </mx:Application>
 
xml文件pic.xml
  1. <?xml version="1.0" encoding="utf-8"?> 
  2. <pics>
  3.     <pic name="图1" path="assets/small/1.jpg"/>
  4.     <pic name="图2" path="assets/small/2.jpg"/>
  5.     <pic name="图3" path="assets/small/3.jpg"/>
  6.     <pic name="图4" path="assets/small/4.jpg"/>
  7.     <pic name="图5" path="assets/small/5.jpg"/>
  8.     <pic name="图6" path="assets/small/6.jpg"/>
  9.     <pic name="图7" path="assets/small/7.jpg"/>
  10.     <pic name="图8" path="assets/small/8.jpg"/>
  11. </pics>
 

 

 

0 0

相关博文

我的热门文章

img
取 消
img