home *** CD-ROM | disk | FTP | other *** search
/ Computer Active 2010 August / CA08.iso / Multimedija / shufflr.air / ShufflrClient.swf / scripts / com / facebook / delegates / WebImageUploadDelegate.as < prev   
Encoding:
Text File  |  2010-06-23  |  3.0 KB  |  88 lines

  1. package com.facebook.delegates
  2. {
  3.    import com.adobe.images.JPGEncoder;
  4.    import com.adobe.images.PNGEncoder;
  5.    import com.facebook.commands.photos.UploadPhoto;
  6.    import com.facebook.commands.photos.UploadPhotoTypes;
  7.    import com.facebook.facebook_internal;
  8.    import com.facebook.net.FacebookCall;
  9.    import com.facebook.net.IUploadPhoto;
  10.    import com.facebook.session.WebSession;
  11.    import com.facebook.utils.PlayerUtils;
  12.    import flash.display.Bitmap;
  13.    import flash.display.BitmapData;
  14.    import flash.events.Event;
  15.    import flash.net.FileReference;
  16.    import flash.net.URLRequest;
  17.    import flash.utils.ByteArray;
  18.    
  19.    use namespace facebook_internal;
  20.    
  21.    public class WebImageUploadDelegate extends AbstractFileUploadDelegate
  22.    {
  23.       public function WebImageUploadDelegate(param1:FacebookCall, param2:WebSession)
  24.       {
  25.          super(param1,param2);
  26.       }
  27.       
  28.       override protected function getExt() : String
  29.       {
  30.          return (call as IUploadPhoto).uploadType == UploadPhotoTypes.JPEG ? "jpeg" : "png";
  31.       }
  32.       
  33.       override protected function getContentType() : String
  34.       {
  35.          return "Content-Type: image/jpg";
  36.       }
  37.       
  38.       override protected function sendRequest() : void
  39.       {
  40.          var _loc1_:ByteArray = null;
  41.          var _loc4_:JPGEncoder = null;
  42.          var _loc2_:URLRequest = new URLRequest(_session.rest_url);
  43.          var _loc3_:Object = call.args.data;
  44.          if(_loc3_ == null)
  45.          {
  46.             super.sendRequest();
  47.             return;
  48.          }
  49.          if(PlayerUtils.majorVersion == 9 && _loc3_ is FileReference)
  50.          {
  51.             throw new TypeError("Uploading FileReference with Player 9 is unsupported.  Use either an BitmapData or ByteArray.");
  52.          }
  53.          if(_loc3_ is Bitmap)
  54.          {
  55.             _loc3_ = (_loc3_ as Bitmap).bitmapData;
  56.          }
  57.          if(PlayerUtils.majorVersion == 10 && _loc3_ is FileReference)
  58.          {
  59.             _loc1_ = (_loc3_ as FileReference)["load"]();
  60.             fileRef = _loc3_ as FileReference;
  61.             fileRef.addEventListener(Event.COMPLETE,onFileRefComplete);
  62.          }
  63.          else if(_loc3_ is ByteArray)
  64.          {
  65.             uploadByteArray(_loc3_ as ByteArray);
  66.          }
  67.          else
  68.          {
  69.             if(!(_loc3_ is BitmapData))
  70.             {
  71.                throw new Error("Error data type " + call.args.data + " is not supported.  Please use one of the following types:  FileReference, ByteArray, BitmapData or Bitmap.");
  72.             }
  73.             switch((call as UploadPhoto).uploadType)
  74.             {
  75.                case UploadPhotoTypes.JPEG:
  76.                   _loc4_ = new JPGEncoder((call as UploadPhoto).uploadQuality);
  77.                   ba = _loc4_.encode(_loc3_ as BitmapData);
  78.                   break;
  79.                case UploadPhotoTypes.PNG:
  80.                   ba = PNGEncoder.encode(_loc3_ as BitmapData);
  81.             }
  82.             uploadByteArray(ba);
  83.          }
  84.       }
  85.    }
  86. }
  87.  
  88.