AS3 URLLoader unable to find local file - actionscript-3

Using AS3 Loader object's load(new URLRequest('file.swf'), and the file is in the same directory as the FLA file. Just read that flash looks for files based on the application directory, but even when using the absolute file path flash can't find it such as "C:\Users\acerbook\Desktop\swf2\file.swf".
i keep getting "Error #2044: Unhandled IOErrorEvent:." and "Error #2035: URL Not Found.", seemingly regardless
Edit: Tested with adobe's preloader files and it worked, so there must be some issue with my AS, will keep checking.

You did read wrong, files are loaded from the location of the generated swf file or the generated html file (if running inside a html), files are NEVER loaded according to the project directory location. If you have set your swf to be exported to a different folder then loading operations run from that location.
The absolute path you are using is not a valid url and so a URLRequest can't find it.

Related

How reading exif metadata from file

I'm trying to implement the following Exif reading library with as3, but I can't load the browsed file.
In the library example they use loader.load(new URLRequest("http://www.example.com/sample.jpg")); for loading the image, the problem in my application is that the file is selected by a file-browser in a local computer.
I tried a fileReference.name but it doesn't work, the only way that I found to make my test, is putting a file in the same directory than the .swf like this :
loader.load(new URLRequest("IMG_001.JPG"));
Can you tell me what is the parameter that I can put in the URLRequest function to get the path of the selected file ?
Thank you

How to load a local directory in as3

I want to load a directory in actionscript. To do that I use the File class but sadly it doesn't work.
Here is what I did. First I created the directory in the applicationStorageDirectory using this code:
var root:File = File.applicationStorageDirectory.resolvePath(UIDUtil.createUID());
root.createDirectory();
After that I dispatch an event so that the application copies some files into that folder. To do that I use the method File.copyToAsync (that works, so this is not the problem). When all files are copied to that directory I try to load that directory using the File call again. The reason I want to do that is, that I need the content/data as a byte array. The data property of the File class is only set when the load method is called successfully before.
Since the directory is in the application storage directory (the url property of the file object has this content: app-storage:/FF011DBC-2E92-46A8-D5F8-29FE1DD8FA7A) I thought just calling the load method would work. I was wrong... Although the documentation of that method says I can just call that method when the application runs in AIR and the file to load is inside the application sandbox, I get the following error:
Error #2044: Unhandled IOErrorEvent:. text=Error #2038: File I/O Error.
at flash.filesystem::File/resolveComponents()
at flash.filesystem::File/resolvePath()
...
Do you have any ideas what could be wrong? Is it even possible to load a directory using the File class? Or does that error occur because the isDirectory flag is set to true in the file object?
kind regards
Markus
I believe a File, when pointing to a directory, does not contains the data of the files contained inside it. You would have to use File.getDirectoryListing() to loop over all files the folder, and append their bytes to the ZIP archive separately. Don't forget to check if you come across sub-directory...
You can check this link for an example of how to do this.

Load all images from internal application

I am trying to load all the .png files from an internal application folder into a list control and I am stuck on exactly how to do it. I have tried httpservice to get the folder and count how many images there are so I can loop through them but I just cant figure that out.
File structure
-src
-(default package)
-my application files
-icons
-all my .png files
httpService i tried:
<s:HTTPService id="loadAllImages" destination="/icons" result="gotImages(event)" fault="loadAllImagesFault(event)"/>
This always results in directory not found. Am I going about this completely wrong? Anyone have a suggestion?
You can't do this. To store an image within an Flash application (SWF or AIR), you must embed it either using #Embed('') in MXML or by using the [Class] method.
The only way to actually reveal a folder directory of an internal folder in an AIR app is by using File (which is an AIR only class).
var file:File = File.applicationDirectory;
file.browseForDirectory('icons'); ; //unsure if that will pull an internal folder or not, but you get the idea
If this is an external directory (doesn't sound like it is), I believe you would do it how you show in your question (although I have never needed to use this method, so I don't know if/how it works)

how to embed symboles IDs stored into external swf file into my swf app?

My app will run on desktop, I am trying to embed a swf file, to use all its symbols IDs,
I tried to load it, but, I get this error:
SecurityError: Error #2148: SWF file file:///D|/my%20projects/bin/app.swf cannot access local resource file:///D|/my%20projects/bin/graphicsDLL.xml. Only local-with-filesystem and trusted local SWF files may access local resources.
at flash.net::URLStream/load()
at flash.net::URLLoader/load()
so, I tried to embed each symbol's ID like this:
[Embed(source="../../../swc/components.swf", mimeType="gxBattery")]
public var gxBattery:Class;
but, I get this error:
D:\my projects\src\com\components\Battery.as(34): col: 9: Error: no transcoder registered for mimeType 'gxBattery'
But, I am sure that I have a movie clip with ID gxBattery
The question is, how can I overcome the security problem in the first error above ?
Loading swf file will make all symboles IDs available to my app, which is what I need.
Also, how can I use the symbols IDs by embedding them ? Can I embed them all at once ?
You should not use mimeType but symbol:
[Embed(source="../../../swc/components.swf", symbol="gxBattery")]
public var gxBattery:Class;

How to deploy SWF file?

I have a SWF file I created using Adobe Flex and I cannot seem to properly embed it inside an HTML page. If I take another SWF file and use it instead, it works all the time. My SWF file is pretty big (1 MB) while the other one is tiny (25 KB). However, I can wait 5-10 minutes and the server connection is super fast and it still will never load.
Is there something I need to do to the SWF to have it start up properly? My SWF almost never runs.
Thoughts?
I see two posible problems here:
Browser is not able to download your SWF file
You can check it if you add SWF file name directly into browser URL. For example http://your_domain/page/test.swf. If you will get "Not Found" error then your file was uploaded incorrectly
You did something wrong when embeding SWF file into HTML
If you have a working file then you can try to overwrite it with new one (leave original file name). Problem can be in sigle symbol in new file name, even letter case should match.
Or you can try using swfobject library for embeding flash into html