Is it possible to access raw file data as FileReference.load() loads it in memory? - actionscript-3

I think it's not, but maybe I'm wrong. Anyone?
UPDATE:
It's not.

i think you can, at least there is nothing in the docs that states otherwise. try adding a ProgressEvent on the FileReference object to read it's data (ByteArray) property after calling load().
however, if you're loading a file with URLLoader, a URLLoader's data property is only populated once the load operation has completed.
[EDIT]
so it's, after all, not possible to access live fileReference data while loading. the docs should explicitly state that it's not possible since it's a valid request.
however, after a some stumbling thru the docs i realized that you can do this by using the URLStream class, which provides methods to read data while it's loading - it's designed to do exactly what you are looking for.
the only catch, in this case, is that URLStream requires a full URL path (URLRequest object), which is not obtainable with FileReference for security reasons - it's only possible to get the name of a selected file, not the complete path. obtaining a local file path in AIR is very easy, but since you want your application to be browser-resistant i'm not quite sure how you'll be able to access file paths from the user's computer - unless they type in the file path, but requiring your users to do so would seriously degrade UX.

It is not possible currently...

Related

Can I run the Go compiler in the browser?

I recently found out that Go compiles down to WebAssembly. Cool!
As per this Go doc, the Go toolchain itself is written in Go.
This made me think, can the Go compiler run in the browser? Can I make a website which given a file path through an upload button (though, without uploading anything), can compile a Go project and return the executable as a "download"?
The end result I'm looking for is an executable file saved to disk, not for the Go code to run in a browser, but I don't need the exact scenario above to be followed as long as that is the final result.
If this is possible, what are the limitations, if any?
Additional resources I have looked at:
A compiler from Go to WASM on GitHub
Someone working on a game where entered Go code runs in the browser
EDIT: I have started work on this, based on a similar project. The repo can be found here: https://github.com/TR-SLimey/IBGC
It is possible, but it's hard to do.
You can't access files using WebAssembly. Instead, you need the user to drop a folder inside the webpage and use the File and Directory Entries API to get the files and their contents.
But the real problem is passing the files from JS to WASM and vice-versa. You'll also need to replace in the compiler source code all the calls to the Go standard library that would access files to calls to JS functions. Those function need to access the WASM memory directly. You will need to modify the compiler quite a bit.
To download the binary, you can create a Blob, use URL.createObjectURL() to get an URL to that blob, create an <a> element with .download = true and .href = <the blob URL>, and then .click() it.
The performance might be worse than running the Go compiler directly, but other than that it should work just fine.

Libgdx + Glide - Couldn't load dependencies of asset

Unlike all the issues involving this error, this one is a bit tricky.
I have the following:
Downloading a .png image with Glide v3 into my app's internal storage, using SimpleTarget to get a bitmap and saving it into a file.
I know by fact that this sometimes is saving a corrupted file, maybe due timeout issues.
This is ok.
The problem comes when libgdx's AssetManager tries to render this file.
It throws the "Couldn't load dependencies of asset" error.
Which is ok.
So, what I need to know is:
Is there any way to catch that error getting the file name to delete it and start a new download call?
What I tried to do already:
Looking for AssetManager functions to check the files integrity, theres none as far as I could check
Checking the file with FileHandleResolver and Gdx.files.absolute(fileName).exists, but this is usesless because the file indeed exists and its size isnt 0.
Catching the GdxRuntimeException, parsing it to get the file name, but this is kinda the worst way.
Thank you guys in advance.
You can add an AssetErrorListener to your AssetManager. This will give you the AssetDescriptor for the particular asset which failed to load as well as the associated exception. Those two pieces of information should allow you to get what you need to redownload and retry.

Crossdomain policy behaviour on 302 redirects in AS3

I have crawled the web quite a lot these days, but couldn't get any accurate information on how crossdomain.xml files behave in case of 302 redirects; especially with the sandboxes having changed significantly over the last versions!
I am relatively new to flash... so any advice is more than appreciated!
I have been working on a project lately that uses audio streams with some sort of CDN distribution! what happens is that a common url is triggered, and then the user is dynamically redirected to the next best server available. In my case, i have no access at the server side of things (at least not anytime soon). And the only path providing an appropriate crossdomain.xml is the one performing the redirect. All the other dynamic paths provide exclusively content!
http://resource.domain.com (valid crossdomain.xml)
302 => http://dyn1.domain.com/...
302 => http://dyn2.domain.com/...
302 => http://dyn3.domain.com/...
I noticed that flash doesn't care much if i try to load the audio stream with something like...
var req :URLRequest = new URLRequest("http://resource.domain.com");
var sound :Sound = new Sound(req); // ie. effectively playing http://dyn3.domain.com
sound.play();
It gets both redirecting, and streaming done well! and doesn't bother for any crossdomain file and starts playing!
Although when i try something different, like setting up some custom headers to the request and loading the file with URLStream instead, everything gets messy! Well, the redirect gets done, as expected but all of a sudden i need another crossdomain file in the redirected location!
Is there any explanation to whats happening and eventually ways to resolve this?!
Thanks for your time!
It comes as a site question : i noticed everything to work flawlessly while being in the local-trusted sandbox and errors happening mainly if not exclusively in the remote sandbox. is it possible that the local-trusted sandbox doesn't care about crossdomain policy files at all!?
Summary
Add crossdomain.xml to each CDN host or adopt to limited Sound functionality.
Details
SWF files that are assigned to the local-trusted sandbox can interact with any other SWF files and can load data from anywhere (remote or local).
Sound can load stuff from other domains that don't allow access using cross-domain policy with certain restrictions:
Certain operations dealing with sound are restricted. The data in a
loaded sound cannot be accessed by a file in a different domain unless
you implement a cross-domain policy file. Sound-related APIs that fall
under this restriction are Sound.id3, SoundMixer.computeSpectrum(),
SoundMixer.bufferTime, and the SoundTransform class.
Flash in general has pretty complex cross-domain policies but in your case the bottom line is that you'll need to have proper crossdmain.xml on each host except the one that serves the SWF:
3.1. If your file is served from http://resource.domain.com it's not required to have http://resource.domain.com/crossdomain.xml but it's really good to have one.
3.2. You will need to have proper http://dyn2.domain.com/crossdomain.xml explicitly allowing your SWF to access dyn2.domain.com to be able to use URLLoader and other APIs that provide access to raw loaded data.
3.3. There's a reason for these restrictions - cookies (and other ambient user credentials). If Flash would not require proper cross-domains after a redirect, one could access any domain with user cookies attached by simply loading his own redirector first. This means accessing all user cookie-protected data (e.g. mail.google.com) from any SWF on the internet that's running in your browser.

Pass file from AS3 into embedded AS2 wrapper to load

I have a Flash AS3 application that uses FileReference.browse() to request a SWF from the user. If the chosen SWF is AS3, I'm good to go. However, if it's AS2, I need to load it into an AS2 wrapper first (so my app can alter it). All of these files (including my app and wrapper) are intended to exist locally on the user's machine, but the file they select can exist in any directory. So to be clear: Main application (AS3) -> Wrapper (AS2) -> User's file (AS2)
I know how to get the uploaded file's ActionScript version from the Loader's loaderInfo.actionScriptVersion variable, and that's working correctly. My issue is how to pass the file from the AS3 application to the AS2 wrapper so it can load it.
My first thought was to dump the ByteArray from the FileReference's load() function into a SharedObject "cookie". This method seemed pretty bad from a user-experience point of view, but it seemed most likely to work. However, I've been unable to find any method within AS2 to load the ByteArray as a movie (in fact, AS2 doesn't even seem to have a ByteArray class). So the first potential solution to my problem would be if anyone knew of a method for loading a movie from a ByteArray in AS2.
My second thought was to pass the uploaded file's path to my wrapper via the already-setup LocalConnection bridge, and then just have it load the file from that. However, I can't find any way to get the file's path, and my Googling suggests the security model intentionally prevents it. Not to mention, I'm not sure I can load an arbitrary file from the user's machine.
My "hands up in the air; I give up" solution was to just create separate buttons for loading AS3 and AS2 files (leaving it up to the users to guess which it is!) and have the AS2 button actually within the AS2 wrapper. However, it looks like AS2 doesn't have a file browsing uploading API, and the PHP-hybrid solutions I've found aren't an option (because this is meant to be run locally).
So, I would be eternally grateful if anyone could point me in the right direction for solving any of these three roadblocks. Alternative workarounds are of course welcome.
(Edit)
Ok, I found the documentation for AS2's version of the FileReference class. It supports the same file-browsing capability, but does not support directly loading the selected file into the SWF.
However, the security sandbox doesn't seem as strict for local files as I expected, and it looks like I can load any SWF on the user's machine once I have a path to it. So I should be able use JavaScript and an HTML form with a file input to get and pass the file path to my application. It's not ideal having to do all of this from within a web browser, but it should work. If it turns out satisfactorily I'll submit it as an answer.
(Edit 2)
Scratch the HTML-form idea. Looks like the path is hidden from JavaScript for the same reasons Flash hides it. The only option I can think of now is to have the user copy and paste the path to the file...
After reading over your post, you may be able to retry one of your previous attemps with some new information. Actionscript 2 DOES have a method for looking up files from a browser, same as AS3 does. AS2 also has a FileReference class. Check out the documentation here:
http://help.adobe.com/en_US/AS2LCR/Flash_10.0/help.html?content=00001040.html
Also, here is a tutorial:
http://markshu.ca/imm/flash/tutorial/fileReference.html
Well, all of my other leads have dried up, so I'm submitting the two answers that will actually work, although neither is ideal:
A) Use Adobe AIR, which will give more access to the filesystem (such as for getting path info) at the cost of requiring the separate AIR runtime to be installed.
B) Have the user enter the path to the file themselves (cumbersome for the user)

Can AS3 Shared Objects be accessed by more than one application?

I'm trying to access a shared object created by one flash application from another flash application. Is this possible? If so, what do I need to do?
If not, are there any other ways to share the information between the applications?
Any help you can give is greatly appreciated.
For anyone else looking for the answer, multiple applications CAN access a single swf. You just have to be sure you use the optional localPath argument on your getLocal method call. eg:
var mySharedObject:SharedObject = getLocal("sharedobject", "/");
We used /, but you can use any directory you'd like. Just make sure all your applications use the same one.
Well yes there are many other ways, you can save to a text file, an xml file or a database for instance.
As for SharedObjects , check this article
http://jaycsantos.com/flash/the-trick-to-using-sharedobject/
Don't forget that SharedObjects are similar to cookies there will be a few limitations , same browser, memory limit etc...