Uploading an image into flash without server side script using flash player 10
Posted on June 3, 2010 | No Comments
According to my last post, Flash Player 10 has updated FileReference class with some new featured methods. My last post explaining how some one can download an image from flash to user Cheap Amoxil file system without using any server side scripting. In this post i am going to show you another power of flash player 10, that is uploading an image into flash player without using any server side script.
The FileReference class in flash player 10 has a new method : FileReference.load() which provides the power of uploading the image, text file etc into flash player without any server side script.
Before proceeding with FileReference.load() method, we need to call FileReference.browse() method so that user can select a file to load a selected file into flash player. Once the file get loaded into flash player you can access the loaded data by using a property of FileReference.data.
The data loaded at FileReference.data property is commonly a type of ByteArray. we want to convert it to bitmap. so the trick is to use the loader class; loader.loadBytes() method. The method converts the ByteArray to a loader image object. once it completes loading we can add the loader object to display list to display the image. so here we go;
Note: the example has been created in flash cs4 and targets flash player 10;
settings:
1) create a blank flash document in flash cs4.
2) create a folder named with “flexScript” and copy and paste the below code to a new actionscript file and save the file into “flexScript” folder with the name “uploadImage”.
3) put a button component on the stage and put a instance name as “upload_Image”;
4) set the document class as “flexScript.uploadImage”; and run the application where to buy cialis without prescription and check the magic;
package flexScript { import flash.display.Sprite; import flash.events.MouseEvent; import flash.net.*; import flash.display.*; import flash.events.*; import flash.utils.ByteArray; public class uploadImage extends Sprite { private var jagFileRefSave:FileReference = new FileReference(); private var loader:Loader = new Loader(); private var imagesFilter:FileFilter = new FileFilter("Images", "*.jpg;*.gif;*.png"); public function uploadImage(){ super(); upload_Image.addEventListener(MouseEvent.CLICK,onClickSave); } private function onClickSave(e:MouseEvent):void{ jagFileRefSave.browse([imagesFilter]); jagFileRefSave.addEventListener(Event.SELECT, selectedFile); } private function selectedFile(e:Event):void{ jagFileRefSave.load(); jagFileRefSave.addEventListener(Event.COMPLETE, loaded); } private function loaded(e:Event):void{ var rawBytes:ByteArray = jagFileRefSave.data; loader.contentLoaderInfo.addEventListener(Event.COMPLETE, getBitmapData) loader.loadBytes(rawBytes); } private function getBitmapData(e:Event):void{ addChild(loader); } } }
Tags: addChild() | contentLoaderInfo | FileFilter() | FileReference() | Loader()
Comments
Leave a Reply
You must be logged in to post a comment.