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)
Related
I have this problem that when i am running my project in Flash cs6 using ctrl+enter, the project is ok, the flash player is retrieving the files from mysql database. but when i run the independent swf file outside, there is no retrieval happening. the text box that suppose to be showing the retrieved data is empty. how can i fix this?
Make sure you are running the published html from an actual page in the browser and not from the local file system.
Just make sure that the URL doesn't start with file:///
You must be having a security sandbox error, but you probably don't have the Debugger version of the Flash Player, so it's not telling you anything.
Just go to http://www.adobe.com/support/flashplayer/downloads.html and choose the proper one for your operating system and browser.
If you STILL want to run the files from your local file system, you can have a look at Flash Player's Global Configuration, to give access to the files/directories you want. Just right click on your swf file in the browser, and when the Menu opens, select Global Configuration.
The reason it is working when running inside Flash CS6 is that the player has less security restrictions in there.
Let me know if you were able to solve your problem.
I'm a complete noob when it comes to flash coding.
I have a flash swf file that I'm loading from an S3 assets bucket. Inside the flash swf it should be displaying a "Browse" button, images also courtesy of the same bucket. This works fine when I host the images and swf file from the same domain that the site is on, but not when loaded from S3.
I have added a crossdomain.xml file to the assets bucket as follows (I'm trying with '*' to start just to get it working, and will narrow it down to my actual host when it appears to be doing anything):
<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
<allow-access-from domain="*"/>
</cross-domain-policy>
I also have a cross-origin resource sharing configuration in the bucket so that the fonts will correctly load for our stylesheets (This is working).
What am I doing wrong to make the button images load in the actionscript? Do I need to modify the actionscript code itself? The code is located here (public library anyone can use, not authored by me): s3-swf-upload-plugin
You can see here that it is instantiating a new browseButton defined here. Like I said I'm not totally familiar with actionscript but believe I could fumble through it if someone could show me what's going wrong :) What's a good way to get actual error reporting? Firebug in Firefox and Chrome's console don't have any kind of messages from Flash about errors going on.
EDIT:
There were some quirkinesses going on in the setting up of the flash object and setting the paths for the button images. I updated BrowseButton.as to do this:
Security.loadPolicyFile("http://s3.amazonaws.com/my-bucket/crossdomain.xml");
I placed this before any of the URLRequest calls in the BrowseButton() function. However it's still not displaying the images :( I also hardcoded the values in the URLRequest to be things like:
upLoader.load(new URLRequest("http://s3.amazonaws.com/my-bucket/assets/s3_up_button.gif"));
but nothing seems to happen. When I set it to /assets/s3_up_button.gif to pull from the local file then it works fine. What am I doing wrong! How can I get error messages displaying from the flash video? :\ I compiled with <debug>true</debug> but I'm not sure how to get actual exception messages.
Check what sandbox your swf is in:
The Security.sandboxType property
An author of a SWF file can use the read-only static
Security.sandboxType property to determine the type of sandbox to
which Flash Player has assigned the SWF file. The Security class
includes constants that represent possible values of the
Security.sandboxType property, as follows:
Security.REMOTE--The SWF file is from an Internet URL, and operates under domain-based sandbox rules.
Security.LOCAL_WITH_FILE--The SWF file is a local file, but it has not been trusted by the user and was not published with a networking designation. The SWF file can read from local data sources but cannot communicate with the Internet.
Security.LOCAL_WITH_NETWORK--The SWF file is a local file and has not been trusted by the user, but it was published with a networking designation. The SWF can communicate with the Internet but cannot read from local data sources.
Security.LOCAL_TRUSTED--The SWF file is a local file and has been trusted by the user, using either the Settings Manager or a Flash Player trust configuration file. The SWF file can both read from local data sources and communicate with the Internet.
You probably want Security.LOCAL_WITH_NETWORK, although Security.LOCAL_TRUSTED will also work.
An explanation, along with details of how to set the sandbox in Flex, is here: http://livedocs.adobe.com/flex/3/html/help.html?content=05B_Security_04.html
If you're working in the Flash IDE, it should just be part of the publish settings.
I'm trying to follow directions given by MonsterDebugger I've linked the SWC, added the code. Then built the project.
The last thing they say: "Publish your project and watch the magic happen."
What I got is a SWF that is built to an http directory where my PHP file picks it up and displays it in browser.
What I'm expecting/want is to interact with my SWF application through browser and debug it with MonsterDebugger.
I'm obviously missing something since there it looks like there is no way for Monster tool to attach itself to the SWF? I'm not sure how does Monster will know about my published SWF?
I'm using FlashDevelop/FlashCS5 and Actionscript 3.
Sorry if this is a stupid question, but did you actually started Monster Debugger.exe after publishing and opening your project in browser? Also MonsterDebugger.initialize(); has second argument which is an address if you publishing and accessing your project on the server I suppose. Did you try to change it?
My bad. I had MonsterDebugger.initialize() statement to execute last in constructor of my document file. I moved initialize statement to be the very first line in my constructor. Now it attaches. Apparently there was some code that executed before initialize that caused issue. All is well now that it is the first line in the document file.
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...
I built an AS3 image gallery using FlashDevelop.
Before I zip up the application, I can run the image gallery in my browser by simply opening the index.html for the project. Everything works perfectly.
I then zip up the project as proj-0.1.2.zip using winrar.
I then unzip this newly created zip and try to load the application using the project index.html like above. The gallery doesn't function properly. From seeing what happens, it appears as though the image metadata is not present(but I'm not sure, see below).
There are other applications as well that are broken. Videos don't load. If an application doesn't depend on any external assets then everything looks fine.
Another thing..If I then build the FlashDevelop project and republish the swf..then it works in the index.html like I want. What is going on here?
I want people to be able to fire up my demo apps out of the box by just running the index.html. If that doesn't always work and they have to figure out that they need to rebuild the SWF then that's pretty bad.
I don't think zipping is the problem, I think moving to a different folder is a problem.
I assume you are running this index.html on your local PC, and not on a webserver?
By default, Flash cannot access from a local SWF to load other local files. However, FlashDevelop / Flash CS3 / Flex Builder, in order to get around this restriction, set some flags in the flash player telling him "This SWF is a trusted SWF, allow him to open local files". But it's based on the exact location of the SWF.
There's a setting somewhere in the compiler, that sets a flag in the SWF saying "This SWF can access local data", but there's one downside: It blocks all access to network resources. So it's either/or: access local data, OR access network resources (anything that goes over HTTP, Socket, etc). I'm not sure where this setting is offhand. It may be that the default setting for Flash CS3 is different than the default setting for FlashDevelop.
Anyway, the easy way to avoid all this issue is to not run the file locally. Put it on your webserver before testing.