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 and check the magic;
view source
print?
01 package flexScript {
02 import flash.display.Sprite;
03 import flash.events.MouseEvent;
04 import flash.net.*;
05 import flash.display.*;
06 import flash.events.*;
07 import flash.utils.ByteArray;
08
09 public class uploadImage extends Sprite {
10 private var jagFileRefSave:FileReference = new FileReference();
11 private var loader:Loader = new Loader();
12 private var imagesFilter:FileFilter = new FileFilter("Images", "*.jpg;*.gif;*.png");
13
14 public function uploadImage(){
15 super();
16 upload_Image.addEventListener(MouseEvent.CLICK,onClickSave);
17
18 }
19 private function onClickSave(e:MouseEvent):void{
20 jagFileRefSave.browse([imagesFilter]);
21 jagFileRefSave.addEventListener(Event.SELECT, selectedFile);
22 }
23 private function selectedFile(e:Event):void{
24 jagFileRefSave.load();
25 jagFileRefSave.addEventListener(Event.COMPLETE, loaded);
26 }
27 private function loaded(e:Event):void{
28 var rawBytes:ByteArray = jagFileRefSave.data;
29 loader.contentLoaderInfo.addEventListener(Event.COMPLETE, getBitmapData)
30 loader.loadBytes(rawBytes);
31 }
32 private function getBitmapData(e:Event):void{
33 addChild(loader);
34 }
35
36 }
37 }
No comments:
Post a Comment