Created
May 12, 2009 19:56
-
-
Save dchelimsky/110700 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import flash.events.*; | |
import flash.net.URLRequest; | |
import flash.display.Loader; | |
import flash.display.BitmapData; | |
import flash.geom.Rectangle; | |
import flash.utils.ByteArray; | |
import ru.inspirit.net.MultipartURLLoader; | |
import com.adobe.images.JPGEncoder; | |
var pack:MovieClip = MovieClip(root).main_mc; | |
var photo:MovieClip = pack.image_mc; | |
var image:MovieClip = new MovieClip(); | |
// Load Data | |
var variableDataLoader:URLLoader = new URLLoader(); | |
variableDataLoader.dataFormat = URLLoaderDataFormat.VARIABLES; // specify format as being variables | |
variableDataLoader.addEventListener(Event.COMPLETE, onComplete); | |
variableDataLoader.load(new URLRequest("wlfdata_as3.txt")); | |
// variableDataLoader.load(new URLRequest(datasrc + "?" + Math.random())); | |
function onComplete (event:Event):void { | |
// Step 1 - Load External Photo and Photo Data (if applicable) | |
// 1A - Load JPG into a Bitmap for Smooth Scaling (non bitmap will look disorientated) | |
photo.addChild(image); | |
var photoLoader=new Loader(); | |
photoLoader.load(new URLRequest(variableDataLoader.data.img)); | |
image.addChild(photoLoader); | |
//} | |
// Saving Bitmap data | |
//save_btn.addEventListener(MouseEvent.MOUSE_OUT, saveOut); | |
//function saveOut(event: MouseEvent):void { | |
var packBitmapData:BitmapData = new BitmapData(pack.width, pack.height, false); | |
//var packBitmap:Bitmap = new Bitmap(packBitmapData); | |
packBitmapData.draw(pack); | |
//var photoBitmapData:BitmapData = new BitmapData(pack.width, pack.height, false); | |
//var photoBitmap:Bitmap = new Bitmap(photoBitmapData); | |
//photoBitmapData.draw(photo); | |
// | |
//packBitmapData.merge(photoBitmapData, new Rectangle(0,0, photo.width, photo.height), new Point(0,0), 1,1,1,1); | |
var jpgEncoder:JPGEncoder = new JPGEncoder(); | |
var byteArray:ByteArray = jpgEncoder.encode(packBitmapData); | |
var ml:MultipartURLLoader = new MultipartURLLoader(); | |
ml.addEventListener(Event.COMPLETE, onReady); | |
function onReady(e:Event):void | |
{ | |
// Upload Complete | |
} | |
ml.addFile(byteArray, 'packhead.jpg', 'photo[photo]'); | |
ml.load(variableDataLoader.data.postURL); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment