1
votes

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...

2
What is the purpose of the AS2 wrapper? Does it do something you could not do if you loaded it into an AS3 loader?Plastic Sturgeon
Based on my research so far (I've only been working on this for a few days, so I could be mistaken) AS2 and AS3 applications are run in separate VMs that can't directly communicate with one another. So to have my AS3 application alter the uploaded AS2 file, I need to first pass my commands over a LocalConnection bridge to my AS2 wrapper, which will then take the actions. I can't just make a LocalConnection to the uploaded file because I didn't create it (ie: nothing's listening).VisibleMan
I understand. But based on your comments above, I think having an AS3 and AS2 button might be the best (only?) option. If you can't get the file reference to load it a second time without user input - the only thing I can think of is to build it with AIR and write a copy to a temp file, then re-open it since you would then know the file path.Plastic Sturgeon
Well, even separating the buttons won't work because I still have no way to load the selected file in AS2. I'm thinking AIR may be the only option. I was hoping to use "pure" Flash, because AIR requires a separate runtime to be installed, and because Flash applications are more "safe" (which I guess is funny, because that's what's getting in my way!). Thanks for your help, I'll just have to bite the bullet :)VisibleMan

2 Answers

0
votes

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

0
votes

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)