Jump to content

upload()


Ustag

Recommended Posts

Hello I am getting this error when I press the uploadBtn:

TypeError: Error #1034: Type Coercion failed: cannot convert flash.events::MouseEvent@25764ea1 to flash.net.URLRequest.
and this is my file uploader attempt:
import flash.events.*;import flash.net.FileReference;import flash.net.URLRequest;var file:FileReference = new FileReference();//Browse for a file  on MOUSE_UPbrowseBtn.addEventListener(MouseEvent.MOUSE_UP, browseFile);//Open file browserfunction browseFile(event:MouseEvent):void{	file.browse();}//Listen for file selectionfile.addEventListener(Event.SELECT, selectHandler);//Show selected filefunction selectHandler(event:Event):void{	var file:FileReference = FileReference(event.target);	infoBox.text = "Selected: " + file.name;}//Locate the upload scriptvar request:URLRequest = new URLRequest("upload.php");//Upload the selected file on MOUSE_UPuploadBtn.addEventListener(MouseEvent.MOUSE_UP, upload);//Upload the selected file with the selected scriptfunction upload(request:URLRequest, uploadDataFieldName:String = "Filedata", testUpload:Boolean = false):void{	infoBox.text = "Uploading: " + file.name + " ...";}

Does someone understand this error and know what I am missing?

Link to comment
Share on other sites

The problem is that you are calling your upload() function with an event:

uploadBtn.addEventListener(MouseEvent.MOUSE_UP, upload);

So upload is being called and the first argument given is a MouseEvent object, while your upload function expects something else.

Link to comment
Share on other sites

  • 2 weeks later...

ok so now the upload is called on mouse up:

//Upload the selected file on MOUSE_UPuploadBtn.addEventListener(MouseEvent.MOUSE_UP, uplUp);//Upload the selected file with the selected scriptfunction uplUp(event:Event):void{	function upload(request:URLRequest, uploadDataFieldName:String = "Filedata", testUpload:Boolean = true):void	{				trace("ok");		infoBox.text = "Uploading: " + file.name + " ...";	}}

But nothing hapens after selecting file and pressing upload.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...