zoukankan      html  css  js  c++  java
  • flex做图片切换(播放)

    flex做图片切换(播放)

    Java代码

     

    <?xml version="1.0" encoding="utf-8"?>   

    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"    

    backgroundColor="white" width="300" height="200"  creationComplete="getResult()">  
             <mx:Style>   
             .vbox {  
                 backgroundColor: #000000;  
                 textAlign:center;  
                 borderStyle:solid;  
                 borderColor:#ffffff;  
             }   
             </mx:Style>   
      <mx:Script>  
       <![CDATA[  
        import mx.containers.VBox;  
        import flash.utils.setInterval;  
        import mx.containers.Canvas;  
        import mx.controls.Label;  
        import mx.controls.Button;  
        import mx.controls.Text;  
        import mx.controls.Alert;      
        import mx.rpc.events.*;  
        import mx.collections.*;  
        import mx.controls.*;  
          
        import flash.utils.*;  
        import flash.events.TimerEvent;  
          
           import flash.events.ContextMenuEvent;  
             
        private var newsListXml:XML;  
        private var newsList:XMLListCollection;  
        private var PicUrl:String = "E:\\ad\\";  
        private var newsArray:Array = new Array; //全局变量,用来装vbox集合  
        private var currNews:News;  
        private var newsArrayLength:int;  
         
        //发送请求去读取xml文件信息  
        public function getResult():void{  
           feed.url="http://127.0.0.1:8080/webroot/file/bigAds.xml";   //xml文件路径  
           feed.send(null);        
        }  
        //请求xml成功后处理函数  
        public function resultHandler(event:ResultEvent):void {  
         canvasid.setStyle("backgroundImage",PicUrl+"5.jpg");  
         title.text="哈1";  
         newsListXml = XML(event.result);  
         init();  
         autoPlay();  
        }  
          
        public function titileStyle():void{  
         var glowFilter:GlowFilter=new GlowFilter();  
         glowFilter.color=0xFFFFFF;  
         var sampleFilters:Array = title.filters;  
         sampleFilters.push(glowFilter);  
         title.filters = sampleFilters;      
        }  
          
        //错误时处理的函数  
        public function handleFault(event:FaultEvent):void{  
         Alert.show(event.fault.faultString, "Error");      
        }  
             
        //动态创建标签  
        public function init():void{       
            newsList = new XMLListCollection(newsListXml.children().child(1).children());  
            var lb:Label;  
            var vbox:VBox;  
            for(var i:int=0;i<newsList.length;i++){          
             var newsObject:Object=newsList.getItemAt(i);          
              lb = new Label();  
              var picId:String=newsObject.@pk;  
              lb.id = "pic"+picId;    //存id  
              lb.text = String(i+1);      
              var picName:String=newsObject.@pk+".jpg";   //存图片路径         
              lb.name = picName;   //存图片名字  
              lb.setStyle("color","#ffffff");  
              lb.useHandCursor = true;  
              lb.buttonMode = true;  
              lb.mouseChildren = false;  
              lb.height=15;  
              lb.width=22;  
              var title:String =newsObject.entry.(@key=="title");  
               
                 vbox = new VBox();  
              vbox.id = ""+i;  
                
              vbox.addChild(lb);  
                     
              vbox.styleName="vbox";  
              addIndexEvent(lb,vbox);     //动态为tx标签元素添加事件    
               HboxIndexSet.addChild(vbox);  
                 
               var news:News=new News();  
               news.seq=i;  
               news.id=newsObject.@pk;  
               news.title=newsObject.entry.(@key=="title");  
               news.img=newsObject.@pk+".jpg";  
               news.indexBox=vbox;            
               newsArray[i]=news;  
           }  
             
           titileStyle();        
           newsArrayLength=newsArray.length;  
           currNews=newsArray[newsArrayLength-1];        
           setInterval(function():void{autoPlay();},3000);                           //as2.0中用setInterval  
           ///var ttime:Timer = new Timer(2000,0);  
          /// ttime.addEventListener(TimerEvent.TIMER,function():void{autoPlay();});   //as3.0中用time取代了setInterval  
           ///ttime.start();        
        }  
          
        //动态为标签添加事件  
           public function addIndexEvent(tagetObject:Object,box:VBox):void{   //参数一代表哪个标签对像,二是一个变量参数  
         tagetObject.addEventListener(MouseEvent.CLICK,function():void{clickIndex(box);});  
           }  
             
              //处理事件函数  
        public function clickIndex(box:VBox):void{  
         toTop(newsArray[box.id])  
        }  
          
        //自动切换(播放)  
        public function autoPlay():void{  
         var currSeq:int=currNews.seq;  
         var nextSeq:int=(currSeq+1)%newsArrayLength;  
         var nextNews:News=newsArray[nextSeq];  
         toTop(nextNews);  
        }  
          
        //图片切换,背景色切换  
        public function toTop(nextNews:News):void{  
         currNews.indexBox.setStyle("backgroundColor","#000000");  
         nextNews.indexBox.setStyle("backgroundColor","red");  
         canvasid.setStyle("backgroundImage",PicUrl+nextNews.img);      
         title.text=nextNews.title;  
         currNews=nextNews;     
            
        }  
           
          
        //打开一个浏览器(暂没用)  
     //   public function showPic():void{  
     //    navigateToURL(new URLRequest("http://www.baidu.com"),"_blank");      
     //   }  
       ]]>  
      </mx:Script>  
        
        
     <mx:HTTPService id="feed" resultFormat="e4x" result="resultHandler(event)"   
     fault="handleFault(event);" useProxy="false" />  
     <mx:VBox width="300" height="200" verticalAlign="bottom" verticalGap="0"    
     id="canvasid" horizontalCenter="0" verticalCenter="0" verticalScrollPolicy="off" 
       
     horizontalScrollPolicy="off">  
            <mx:Label x="123" y="180" text="Label" height="26"   
       
     color="#000000" fontSize="20" fontWeight="bold" id="title"   />  
            <mx:HBox x="211" y="180" width="100%"   
       
     backgroundColor="#000000" backgroundAlpha="0.50"   horizontalAlign="right" id="HboxIndexSet"   
       
     horizontalGap="1" horizontalScrollPolicy="off"/>  
          </mx:VBox>   
      </mx:Application>

    http://www.javaeye.com/upload/attachment/35803/afcc61a9-46ec-3980-b4ac-cddbca1815e6.bmp

  • 相关阅读:
    Vue.js 监听属性
    class 属性绑定
    《规划极限编程》阅读笔记03
    原型模式——C++实现
    原型模式——Java实现
    建造者模式——C++实现
    建造者模式——java实现
    抽象工厂模式——C++实现
    抽象工厂模式——java实现
    软件工程 开发模型
  • 原文地址:https://www.cnblogs.com/huqingyu/p/1488703.html
Copyright © 2011-2022 走看看