Archive for May, 2007

FileReference:Class

Tuesday, May 15th, 2007

The Flash FileReference Class is a tool for uploading files by:

  1. Popping up a browse box, prompting the user to define the file they would like to upload
  2. Uploading the required file, using either php, coldfusion, or asp.
  3. Keeping Flash up to date on the progress of uploading the file.
  4. And returning to Flash either an error or else it notifies Flash that it uploading has been completed successfully.

The properties of the FileReference :Class are as follows:

  1. addListener(listener:Object) :Function
  2. browse(typelist:Array) :Function
  3. cancel:Function
  4. creationDate:Date[read-only]
  5. creator:String[read-only]
  6. download
  7. modificationDate:Date[read-only]
  8. name:String[read-only]
  9. onCancel:Function -runs when user cancels
  10. onComplete:Function -runs when uploading completes
  11. onHTTPError:Function -runs when a HTTPError is encountered
  12. onIOError:Function -runs when an IOError is encountered
  13. onOpen:Function -runs when file is Opened
  14. onProgress:Function -runs when upload progress is made
  15. onSecurityError:Function -runs when a security error is encountered
  16. onSelect:Function -runs when user selects which file to upload
  17. removeListener:Function
  18. size:Number[read-only]
  19. type:String[read-only]
  20. upload:Function

Judging by the number of people having problems with the FileReference class, a list of causes of errors would be helpful. If an error you are currently having is not listed, then please feel free to comment on it.

  1. 406 error
    • This might be able to be fixed by going to the root directory on your site, and adding the following lines to .htaccess (if it is not there, then create it)
        SecFilterEngine Off
        SecFilterScanPOST Off
    • or, on the other hand, if your page is under a secure connection,
      Flash cannot upload under a secure connection, so if you are trying for example to upload to https://mysite.com/upload.php, it won’t work, because flash cannot upload under a secure connection, however, you can upload to http://mysite.com/upload.php
    • or a combination of both
  2. If you would like to have an error listed, please comment on your error, and an administrator may add it to the blog

Also included in this blog is a list of other articles on the FileReference Class and it’s errors

The code for php is:

$fileName = basename($_FILES[”Filedata”][”name”]);
$uploadFile = “images/uploaded/” . $_GET[”date”] . “-” . $fileName;

if (move_uploaded_file($_FILES[”Filedata”][”tmp_name”], $uploadFile)) {
chmod(dirname(__FILE__) . “/” . $uploadFile, 0777);
print 1;
}else{
print 0;
}
?>

The code for coldfusion:

is available here

The code for asp:

<%@LANGUAGE=”VBSCRIPT” CODEPAGE=”1252″%>
<%

Set theForm = Server.CreateObject(”ABCUpload4.XForm”)
theForm.Overwrite = True ‘ overwrite existing files
.
For Each theFile in theForm.Files
If theFile.FileExists Then
‘ save in virtual directory
theFile.Save “temp\” & theFile.FileName
Response.Write(”1 ” & theFile.FileName)
Else
Response.Write(”0″)
End If
Next

Set theForm = nothing

%>

If you have any comments or questions please feel free to let us know… and
Thanks for reading
…Also, a tutorial on this is coming soon!

setInterval

Monday, May 7th, 2007

I have been a Flash developer for a number of years, but until recently, i have not come across the setInterval() function. I have used the onEnterFrame function before, and although it does work properly, you are limited to just repeating at the current frame rate. SetInterval on the other hand, allows for more flexibility by allowing you to specify in milliseconds exactly how much time you want between each repetition of a function.

_root.onEnterFrame = function(){
    refresh();
}

As you have probably already worked out, this code will run the function refresh() again and again every time the frame should be changed, even if there is only one frame in _root. However, the setInterval() will allow the user to define, exactly how often they want the function to repeat. For Instance:

setInterval(doStuff, 2000,"doThis","doThat")
function doStuff(a,b){
trace (a)
trace (b)
}

The Previous code will trace "doThis", and "doThat" once every 2000 miliseconds, or 2 seconds. Also, the Parameters for the setInterval() function are (functionName,timeInMilliseconds,anyParameters).

This Concludes our rundown on the setInterval() function.

If you have any comments or questions please feel free to let us know… and

Thanks for reading