posts - 495,comments - 227,trackbacks - 0
          <2010年4月>
          28293031123
          45678910
          11121314151617
          18192021222324
          2526272829301
          2345678

          常用鏈接

          留言簿(46)

          隨筆分類(476)

          隨筆檔案(495)

          最新隨筆

          搜索

          •  

          積分與排名

          • 積分 - 1396482
          • 排名 - 16

          最新評論

          閱讀排行榜

          評論排行榜

          http://my.oschina.net/Boder/blog/931

          國外有高手已經實現了IE瀏覽器內加載flashpaper,好像是這篇吧: http://www.darronschall.com/weblog/2006/11/how-to-load-flashpaper- documents-in-flex-2.cfm 這里將在他的基礎上改成利用LocalConnection來通訊,以便更好的處理來回的操作. flex load flashpaper也離不開flash,這個例子其實就是用flash做一個空殼,比如命名FPload.swf這個殼就是用來加載 flashpapaer的,里面實現了對flashpaper的大小設置,縮略值,頁數設置等等,注意這個fpload.swf是flash8的.在 flex中加載就得利用LocalConnection(如果不明白的得自己去想辦法了解了)或者例子中的ExternalInterface跟 fpload.swf通訊,去設置尺寸,大小,頁面等等 首先看flex3里面如何來加載flashpaper //com.magReader.FlashPaperLoader.as


          package com.magReader
          {

              
          import flash.events.Event;
              
          import flash.events.StatusEvent;
              
          import flash.net.LocalConnection;
          //import flash.system.System;

              
          import mx.controls.SWFLoader;

              
          /**
               * UIComponent designed specifically to load FlashPaper documents
               * and size them correctly in the available area.
               
          */
              
          public class FlashPaperLoader extends SWFLoader
              {

                  
          /**
                   * The id of the FlashPaperLoader.swf proxy that will be used
                   * for communication pyurposes.
                   
          */
                  
          public static const FLASH_PAPER_LOADED    : String = "flashPaperLoaded";
                  
          public static const FLASH_CONNERROR        : String = "flashConnError";
                  
          private var sendFlashConn:LocalConnection;
                  
          private var recieveFlashConn:LocalConnection;
                  
          /**
                   * The name of the application that is loading in the FlashPaperLoader.swf
                   * file.  This name must correspond to the "id" attribute in the object tag
                   * and the "name" attribute in the embed tag when the Flex client is embedded
                   * into the html page.
                   
          */

                  
          /**
                   * Constructor
                   
          */
                  
          public function FlashPaperLoader()
                  {
                      
          //source = "app-storage:/data/fpHolder.swf";
                      sendFlashConn=new LocalConnection();
                      recieveFlashConn 
          = new LocalConnection();
                      recieveFlashConn.client
          =this;
                      sendFlashConn.addEventListener(StatusEvent.STATUS, onStatus);
                      sendFlashConn.allowDomain(
          "*");
                      recieveFlashConn.allowDomain(
          "*");
                      sendConn();
                  }
                  
          public function sendConn():void
                  {
                      
          try
                      {
                          recieveFlashConn.connect(
          "_flexloader");
                      } 
          catch (error:ArgumentError) {
                          trace(
          "Can't connectthe connection name is already being used by another SWF");
                          onConnError();
                          
          return;
                      }
                  }

                  
          private function onStatus(result:StatusEvent) :void{

                      trace (result.level 
          == "error"?"Operation failed":"Operation succeeded");

                  }
                  
          //連接源出錯
                  private function onConnError():void
                  {
                      
          //errUnload();

                      var e:Event
          =new Event(FlashPaperLoader.FLASH_CONNERROR);
                      dispatchEvent( e );
                  }

                  
          // =================================================================
                  
          //  Expose methods that are proxied from FlashPaperLoader.swf - Call
                  
          //  JavaScript methods that the FlashPaperLoader.swf file picks up
                  
          //  and passes to the loaded FlashPaper document.
                  
          // =================================================================

                  
          public function setSize( width:Number, height:Number ):void
                  {
                      trace(
          "=========setPaperSize=============");
                      sendFlashConn.send(
          "_flashpaperloader","setPaperSize",width,height);
                  }
                  
          /**
                   * 文檔加載成功提示
                   * 
          */
                  
          public function fpLoaded():void
                  {
                      trace(
          "reveice fpLoaded message!! this.width = " + this.width + " this.height" + this.height);
                      
          //setSize(parent.width,parent.height);
                      var e:Event=new Event(FlashPaperLoader.FLASH_PAPER_LOADED);
                      dispatchEvent( e );
                      
          //this.visible=true;
                  }
                  
          /**
                   * 設置縮放
                   * 
          */
                  
          public function setZoom(value:Object):void
                  {
                      
          if (this.visible)
                      {
                          sendFlashConn.send(
          "_flashpaperloader","setCurrentZoom",value);
                      }
                  }

          //    override protected function updateDisplayList( unscaledWidth:Number,
          //                                                   unscaledHeight:Number ):void
          //    {
          //        if ( contentHolder )
          //        {
          //            // Adjust values so the FlashPaper document is displayed correctly
          //            contentHolder.scaleX = 1.0;
          //            contentHolder.scaleY = 1.0;
          //            contentHolder.x = 0;
          //            contentHolder.y = 0;
          //    
          //            contentHolder.scrollRect = new Rectangle( 0, 0, unscaledWidth, unscaledHeight );
          //    
          //            // When the content has loaded, call the setSize method so that the
          //            // FlashPaper document sizes right in the available area
          //            if ( Loader( contentHolder ).content )
          //            {
          //                setSize( unscaledWidth, unscaledHeight );
          //                //this.setFocus();
          //            }
          //        }
          //    }

                  
          //卸載此swf
                  public function unload():void
                  {
                      
          if(sendFlashConn != null
                      {
                          sendFlashConn.send(
          "_flashpaperloader","unload");
                          sendFlashConn 
          = null;
                      }
                      
          try
                      {
                          
          if(recieveFlashConn != null
                          {
                              recieveFlashConn.close();
                              recieveFlashConn 
          = null;
                          }
                      }
          catch(e:ArgumentError)
                      {
                          trace(e.toString());
                          recieveFlashConn 
          = null;
                      }

                      unloadAndStop(
          true);
                      
          //System.gc();
                  }
                  
          public function errUnload():void
                  {
                      
          if(sendFlashConn != null
                      {
                          sendFlashConn.send(
          "_flashpaperloader","unload");
                          sendFlashConn 
          = null;
                      }
                      
          if(recieveFlashConn != null) recieveFlashConn = null;
                      unloadAndStop(
          true);
                      
          //System.gc();
                  }

              } 
          // end class
          // end package


          posted on 2010-04-06 14:04 SIMONE 閱讀(728) 評論(0)  編輯  收藏 所屬分類: JAVAflash
          主站蜘蛛池模板: 鄂托克前旗| 淳化县| 桐庐县| 清新县| 罗甸县| 洛阳市| 陕西省| 万载县| 邵东县| 尼玛县| 岢岚县| 上栗县| 鱼台县| 东乡族自治县| 商河县| 蓬莱市| 甘南县| 漾濞| 元谋县| 绥江县| 龙南县| 杭锦旗| 砚山县| 辽源市| 冀州市| 广河县| 曲阜市| 宜川县| 桓台县| 凌云县| 万荣县| 麟游县| 五原县| 庆安县| 鄄城县| 庆城县| 漾濞| 宜兰县| 屏东县| 古浪县| 普兰店市|