Check input file size using Flash - html

I have a multipart html form with a file input element and would like to check the size of the selected file before uploading. I can access the file path using the value attribute, however is it possible to pass that path to a swf and have the swf return the file size or is this blocked by the flash sandbox? Are there any existing projects that already do this? I'd like to avoid replacing my file input element with a flash uploader if possible.

Passing file names and accessing it via Flash is security risk. Flash does support a FileReference API, but it requires user input in order to work.

Related

Downloading new SWF after passing in variables via FlashVars

I'm passing text to an SWF file via the FlashVars parameter in the HTML object. This is working fine and I can see the new text in my SWF in the browser.
What I'd like to be able to achieve now is for the user to be able to click a "Download" button which saves the SWF that's currently displaying the dynamic text.
Is the possible or is there an alternative way of passing text to an SWF via the browser and then saving that SWF with the next text "compiled" inside it.
Thanks,
An SWF is compiled code. Your FlashVars are runtime variables that are read into the compiled program. The short answer is, "No". What you're trying to do isn't possible. The SWF will always need to read into itself those variables, and storing them in the SWF isn't the way.
Because the SWF will need to load your data after it opens, the only question is "where to store them?"
If the data is specific to an individual's computer, try SharedObject.
If the data is general to all users, you could host the data on your site, and the app loads the file using URLLoader with XML/JSON/TXT.
If the data is dynamic for each user and needs to run offline, have your website write the XML/JSON/TXT and zip it and your SWF into a single download.

delete external text file from .swf file

I have a swf file (game file) which reads the content of external text file which I have created. This swf file will not be used in any browser. It's for windows only. I was wondering if I can delete or update that text file after I read it's content without using air.
Your question isn't very clear, I'm not sure what exactly you wanted to know. But if I understood you correctly:
You cannot delete files from the filesystem in the through Flash Player, but you can however delete it from SWF file's memory.
Deleting from the file system (basically like putting into trash) is something that only AIR can help you with.
Deleting from memory would mean to remove all the listeners from URLLoader or Loader object instance and setting it to null.
You cannot write the file with Flash player to edit it's content (update), but you can load it again and check if anything changed in that file's content that also would be considered as updating.
Hope that answers your question.
you cant do that without air. but you can use an external application using fscommand().
or you can use Multimedia Zinc

Some way to change text of SWF without having Flash?

I have a FLA with some text but the person that will be sending the SWF doesn't have Flash and doesn't know anything about Flash either.
Is there some way to build the FLA so that the text can be changed simply by modifying the SWF somehow? Due to company policy, the SWF cannot read from external files.
We tried programming into the FLA that it read an XML in another server, but that's not allowed. I also cannot send the SWF with another file (ie. an xml file).
Thanks.
Use FLASM or SWFMILL which are free command line assembler/disassembler for swf files. Use any of the one to disassemble your swf. You can open the result file in any of the text editor, find and replace your text and assemble it as swf again. Hope it helps.
It is a strange logic to try to modify a FLA file without Flash. A FLA file is a binary file, you'll need an editor to read it and I'm pretty sure Adobe isn't allowing 3rd party editors legally.
But yes, it's fine to have a dynamic TextField where you can send the parameter and change the data. Please note - you need to send the data. Means it has to come from outside.
What are the options? Well, actually, there are few:
Loading from an external file or getting it from a server side script. You said it's not allowed, let's omit this method.
Read FlashVars. If you publish it within a HTML page, you can actually feed some data via FlashVars. Not only 1 variable, but as many as you want. And it's fine for small strings, but if you plan to pass a text larger than a sentence… Don't do it.
As a funny hack you could try naming your file with the text you want and read the URL of the SWF thus showing it's name and using it as a text data. But don't do it :)^
If you want to try it, you can access the URL with stage.loaderInfo.url, just make sure you have a stage defined - call in the document class or after the display object you're calling from is added to stage.
Use ExternalInterface to communicate with, for example, JavaScript and get the variables from JavaScript. It's actually not so bad, since your text will be tidily stored in a .js file and you can modify it on the run. That of course is a separate file and you need to have the SWF embedded in HTML for that, but it is one of the options you have.
Other than that you could have an external file that will hold the data and embed it in the SWF. Look more on embedding here: http://flashgamedojo.com/wiki/index.php?title=Embedding_XML_in_AS3 . It is about embedding XML data, but you can use the technique for any data, even binary.
Embedding data is a great thing, but you'll need to re-compile each time you make a change in the file, since it isn't loading the file dynamically, but embeds it into to the SWF itself on compile time.
Hope that helps!
JPEXS Decompiler can change text in an SWF pretty easily. It's still actively developed as of 2021.

FileReference vs File?

I want to make a Flash app in which the user can load and save files from and to their local hard drive. While I've often done this in AIR apps using the File and FileStream classes, I haven't done so before in an SWF.
From what I know the FileReference class is used for this, although it seems to have some restrictions due to security risks. I'd like to know what the main differences are between using the FileReference class and using the File and FileStream classes to load and save files.
The File class extends the FileReference.
FileReference is safe to be used in the FlashPlayer (in the browser) because it won't let you modify the files in the user machine.
If you want to open a file, you need to as for the user to open it for you with: FileReference.browse().
To save a file, you need to ask the user to save it: FileReference.save()
With File class you can open, modify and save files without those dialogs.
Furthermore, the File class gives you a bunch of useful properties like: File.desktopDirectory, File.documentsDirectory and such.
You can check if a file exists with the exists property and have a much restriction when manipulating file in the user file system.
You can read more about the FileReference and File classes in the docs.

Is it possible to convert an XML file created in actionscript to a FileReference object?

I have a working s3 uploader in actionscript that uses the FileReference class so a user can browse for files to upload when he/she clicks on the upload button.
I have a web application and I want the user to have his/her configuration saved to s3 as an XML file when they hit the save button, so the "save" button will trigger the upload. However, i cant figure out a way to add the XML file to the FileReference variable I create. I was looking at the File class but that appears to be only usable in AIR.
Is it possible to create a FileReference object based off of an XML file that actionscript creates within the application without browsing for a file using FileReference.browse(); ?
Thanks
The answer to my original question is "no". According to this article by Mike Chambers, you cant.
It is apparently a sandbox issue so that a malicious flash program will not be able to do anything related to saving files without a users permission.