package import flash display Sprite import flash events Event import f

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package {
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.external.*;
import flash.net.FileFilter;
import flash.net.FileReference;
import flash.net.URLRequest;
public class pict_upload extends Sprite
{
var fileRef:FileReference = new FileReference();
public function pict_upload()
{
fileRef.addEventListener(Event.SELECT,onSelectFile);
fileRef.addEventListener(Event.COMPLETE, completeHandler);
stage.addEventListener(MouseEvent.CLICK, fileBrowse );
}
private function fileBrowse(e:MouseEvent):void{
trace('click');
fileRef.browse(getTypes());
}
private function onSelectFile(e:Event):void {
trace("select");
var request:URLRequest = new URLRequest('http://upload.pict.com/api/upload');
try
{
fileRef.upload(request);
}
catch (error:Error)
{
trace("Unable to upload file.");
}
}
private function completeHandler(e:Event):void{
trace("uploaded");
}
private function getTypes():Array {
var allTypes:Array = new Array();
allTypes.push(getImageTypeFilter());
allTypes.push(getTextTypeFilter());
return allTypes;
}
private function getImageTypeFilter():FileFilter {
return new FileFilter("Images (*.jpg, *.jpeg, *.gif, *.png)", "*.jpg;*.jpeg;*.gif;*.png");
}
private function getTextTypeFilter():FileFilter {
return new FileFilter("Text Files (*.txt, *.rtf)", "*.txt;*.rtf");
}
}
}