农家女

导航

flex 的图片浏览

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
      xmlns:s="library://ns.adobe.com/flex/spark"
      xmlns:mx="library://ns.adobe.com/flex/mx"
      xmlns:supportClasses="com.esri.ags.skins.supportClasses.*"
      minWidth="955" minHeight="600"
      creationComplete="init();">
 <fx:Declarations>
  <!-- 将非可视元素(例如服务、值对象)放在此处 -->
  <mx:RemoteObject destination="fileUpload" id="fileUploadService1" endpoint="/JWXLXT/messagebroker/amf" fault="fileUploadService_faultHandler(event)" result="fileUploadService_resultHandler(event)"/>
 </fx:Declarations>
 <fx:Script>
  <![CDATA[
   import com.taiji.derive.java.service.JavaService;
   import com.taiji.examine.java.model.TbPicture;
   
   import flash.net.FileFilter;
   import flash.net.FileReference;
   
   import mx.collections.ArrayCollection;
   import mx.collections.ArrayList;
   import mx.controls.Alert;
   import mx.core.UIComponent;
   import mx.rpc.events.FaultEvent;
   import mx.rpc.events.ResultEvent;
   
   import org.osmf.events.TimeEvent;
   
   private var _imageFiles:Array;
   private var imageIndex:int=0;
   private var javaService:JavaService = new JavaService("flexService");
   private var timer:Timer;
   private var filePath:String ="http://localhost:8080/jwxlFlex/screencpature/anonym/20120917/2/";
   
   public function get imageFiles():Array
   {
    return _imageFiles;
   }
   
   public function set imageFiles(value:Array):void
   {
    _imageFiles = value;
   }

   private function init():void{
    //Alert.show("init"+filePath+"152317.png");
    image.source=filePath+"152317.png";
   /*  var uicomp:UIComponent=new UIComponent();
    uicomp.addChild(imageLoader);
    addElement(uicomp); */
   /*  timer=new Timer(10000);
    timer.addEventListener(TimerEvent.TIMER,changeImage);
    timer.start(); */
   /*  javaService.invokeJavaOperation("getPathByProterty", [42]
     , function(event:ResultEvent):void{
      var picture:TbPicture=event.result as TbPicture;
      Alert.show(picture.path);
     }
     , function(event:FaultEvent):void{
      Alert.show(event.toString());
     }
    );  */
   fileUploadService1.downLoadFile("F:\\jwxlWorkspace\\jwxlFlex\\WebContent\\screencpature\\anonym\\20120917\\2");
   }
   private function changeImage(event:TimerEvent):void
   {
    Alert.show("changeImage"+imageIndex);
    Alert.show(filePath+this.imageFiles[imageIndex].toString());
    image.source=filePath+this.imageFiles[imageIndex].toString();
    imageIndex++;
    if(imageIndex>=this.imageFiles.length)
    {
     timer.stop();
      Alert.show("图片播放完毕");
    }
   }
   //自动回放事件
   private function autoPlayImage(event:MouseEvent):void
   {
    timer= new Timer(10000);
    timer.addEventListener(TimerEvent.TIMER,changeImage);
    timer.start();
    this.previousBtn.visible=false;
    this.nextBtn.visible=false;
   
   }
            //手动回放事件
   private function playImage(event:MouseEvent):void
   {
    Alert.show(" playImage");
    if(timer!=null&&timer.running)
    {
     timer.stop();
    }
     //
      this.previousBtn.visible=true;
      this.nextBtn.visible=true;
      Alert.show(" playImage");
   }

   protected function fileUploadService_faultHandler(event:FaultEvent):void
   {
    Alert.show(event.fault.toString());
   }
   protected function fileUploadService_resultHandler(event:ResultEvent):void
   {
    var fileStr:String=event.result.toString();
    var files:Array=fileStr.split('&');
    this.imageFiles=files;
   }
            //上一页的事件
   protected function previousBtn_clickHandler(event:MouseEvent):void
   {
    imageIndex=imageIndex-1;
    if(imageIndex==-1)
    {
    Alert.show("当前为第一页");
    return;
    }
    Alert.show(filePath+this.imageFiles[imageIndex].toString());
    image.source=filePath+this.imageFiles[imageIndex].toString();
   }
   //下一页的事件
   protected function nextBtn_clickHandler(event:MouseEvent):void
   {
    imageIndex=imageIndex+1;
    if(imageIndex>this.imageFiles.length)
    {
     Alert.show("当前为最后一页");
     return;
    }
    Alert.show(filePath+this.imageFiles[imageIndex].toString());
    image.source=filePath+this.imageFiles[imageIndex].toString();
   }
  ]]>
 </fx:Script>
 <s:Button label="自动回放"  click="autoPlayImage(event)" x="411" y="10"/>
 <mx:Image id="image"  width="484" height="295" x="304" y="61">
  
 </mx:Image>
 <s:Button x="226" y="178" label="上一页" id="previousBtn"  visible="true"  click="previousBtn_clickHandler(event)"/>
 <s:Button x="796" y="178" label="下一页" id="nextBtn"  visible="true" click="nextBtn_clickHandler(event)"/>
 <s:Button x="613" y="11" label="手动回放" click="playImage(event)" />
</s:Application>

posted on 2012-09-19 15:21  农家女  阅读(332)  评论(0编辑  收藏  举报