图片切换

来源:互联网 发布:java分页查询代码 编辑:程序博客网 时间:2024/05/29 21:33

images.mxml

 

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
    creationComplete="createComplete()"
    layout="absolute"
    fontSize="12"
    width="200"
    height="120"
    borderColor="#E48911" backgroundColor="#FFFFFF">
 <mx:Script>
  <![CDATA[
   import mx.controls.Alert;
   import mx.controls.Button;
   import mx.controls.Image;
   public var images:Array = [];
   public var buttons:Array = [];
   public var urls:Array = [];
   public var currentImageIndex:Number = 0;
   public var ttime:Timer;
   public var titles:Array=[];
   
   public function createComplete():void {
    
    this.horizontalScrollPolicy = "off";
    this.verticalScrollPolicy="off";
    
    c.horizontalScrollPolicy = "off";
    c.verticalScrollPolicy="off";
    
    h.horizontalScrollPolicy = "off";
    h.verticalScrollPolicy="off";
    h.setStyle("horizontalGap",2);
    
    imask.buttonMode = true;
    imask.addEventListener(MouseEvent.CLICK,toUrl);
    
    title.useHandCursor=true;
    title.buttonMode=true;
    title.mouseChildren=false;
    
    
    var loader:URLLoader = new URLLoader();
    loader.addEventListener(Event.COMPLETE,setPictures);
    loader.dataFormat = URLLoaderDataFormat.TEXT;
    loader.load(new URLRequest("pics.xml"));
    
   }
   
   private function setPictures(evt:Event):void{
    var loader:URLLoader = URLLoader(evt.target);
    var AnnounceXml:XML = XML(loader.data);
    var i:Number = 0;
    for each(var element:XML in AnnounceXml.elements()){
     if (element.name()=="item"){
      
      var name:String = element.@name;
      var img:String = element.@img;
      var url:String = element.@url;
      titles[i]=element.@title;
      
      var button:Button = new Button;
      button.setStyle("fontSize","10");
      button.setStyle("cornerRadius","0");
      button.setStyle("borderColor","#FFFFFF");
      button.setStyle("color","#FFFFFF");
      button.setStyle("themeColor","#FFFFFF");
      button.setStyle("backgroundColor","#CC2707");
      button.setStyle("fillColors",["#CC2707","#CC2707"]);
      button.setStyle("fillAlphas",[0.3, 0.3]);
      
      button.width=30;
      button.height=15;
      button.label = new String(i+1);
      button.buttonMode = true;
      button.addEventListener(MouseEvent.CLICK,selectImage);
      buttons[i]=button;
      h.addChild(button);
      
      var tempImage:Image = new Image();
      tempImage.x=0;
      tempImage.y=0;
      tempImage.source = img;
      tempImage.width = c.width;
      tempImage.height = c.height;
      //tempImage.visible = false;
      
      
      
      var p:Number = (new Date()).getTime() % 4;
      var eff:String;
      switch(p) {
       case 0:
        eff = "fadeIn";
        break;
       case 1:
        eff = "aWipeRight";
        break;
       case 2:
        eff = "aIris";
        break;
       case 3:
        eff = "aWipeLeft";
        break;
       default:
        eff = "fadeIn";
      }
      tempImage.setStyle("showEffect",eff);
      
      images[i]=tempImage;
      c.addChild(tempImage);
      urls[i]=url;
      i++;
     }
    }
    
    
    
    h.y = this.height - 15 - 15;
    h.x = this.width - (30*images.length) - 15;
    
    
    clickIndex(currentImageIndex);
    (buttons[currentImageIndex] as Button).setStyle("fontWeight","bold");
    (buttons[currentImageIndex] as Button).setStyle("fillAlphas",[1, 1]);
    
    ttime = new Timer(2500,0);  
    ttime.addEventListener(TimerEvent.TIMER,function():void{autoPlay();});
    ttime.start();     
   }
   
   private function clickIndex(i:Number):void {
    (images[i] as Image).visible = false;
    c.setChildIndex(images[i],images.length-1);
    (images[i] as Image).visible = true;
    currentImageIndex = i;
    title.text=titles[i];
    title.addEventListener(MouseEvent.CLICK,toUrl);
   }
   
   private function selectImage(evt:MouseEvent):void {
    
    ttime.reset();
    ttime = new Timer(2500,0);  
    ttime.addEventListener(TimerEvent.TIMER,function():void{autoPlay();});
    ttime.start();
    
    var button:Button = Button(evt.currentTarget);
    var index:Number = h.getChildIndex(button);
    
    if (index==currentImageIndex) return;
    (buttons[currentImageIndex] as Button).setStyle("fontWeight","normal");
    (buttons[currentImageIndex] as Button).setStyle("fillAlphas",[0.3, 0.3]);     
    button.setStyle("fontWeight","bold");
    button.setStyle("fillAlphas",[1, 1]);
    clickIndex(index);
   }
   
   
   
   private function toUrl(evt:MouseEvent):void {
    navigateToURL(new URLRequest(urls[currentImageIndex]), "_blank");  
   }
   
   private function autoPlay():void{
    (buttons[currentImageIndex] as Button).setStyle("fontWeight","normal");
    (buttons[currentImageIndex] as Button).setStyle("fillAlphas",[0.3, 0.3]);  
    
    currentImageIndex ++ ;
    if (currentImageIndex >= images.length) {
     currentImageIndex = 0;
    }
    (buttons[currentImageIndex] as Button).setStyle("fontWeight","bold");
    (buttons[currentImageIndex] as Button).setStyle("fillAlphas",[1, 1]);
    clickIndex(currentImageIndex);
   }
   
  ]]>
 </mx:Script>
 <mx:Fade id="fadeIn" duration="500" alphaFrom="0.0" alphaTo="1.0"/>
 <mx:Iris id="aIris"/>
 <mx:WipeRight id="aWipeRight" />
 <mx:WipeLeft id="aWipeLeft" />
 
 <mx:Canvas id="c" x="0" y="0" width="100%" height="100%">
 </mx:Canvas>
 <mx:Canvas id="imask" x="0" y="0" width="100%" height="100%" backgroundColor="#FFFFFF"
      alpha="0"> 
 </mx:Canvas>
 <mx:Canvas backgroundColor="#FFFFFF" width="120" height="25" x="5" y="90" >
  <mx:Label id="title" height="16" width="116" y="2" x="2" fontSize="12"
      ></mx:Label>
 </mx:Canvas>
 <mx:HBox id="h" horizontalAlign="right" verticalAlign="bottom">
 </mx:HBox>
</mx:Application>

 

 

pics.xml

 

<?xml version="1.0" encoding="utf-8" ?>
<AlterPic>
<item name="图片1图片1图片1" url="#.aspx" img="1.jpg" title="油机调度调度方案1"/>
<item name="图片2图片2图片2" url="#.aspx" img="2.jpg" title="油机调度调度方案2"/>
<item name="图片3图片3图片3" url="#.aspx" img="3.jpg" title="油机调度调度方案3"/>

</AlterPic>
 

 

 

原创粉丝点击