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

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;

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

AS3 URLLoader unable to find local file

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.

sharedObject location

i'm using this method to save shared object in specific location but i'm not able to give path
SharedObject.getLocal("save","how to give path here for window");
and this gives following error
Error: Error #2130: Unable to flush SharedObject.
at Error$/throwError()
at flash.net::SharedObject/flush()
at OnlineDiagramEditor/SaveData_mouseDownHandler()[C:\Users\ruchidod\Adobe Flash Builder 4.6\OnlineDiagramEditor\src\OnlineDiagramEditor.mxml:3240]
at OnlineDiagramEditor/__SaveData_mouseDown()[C:\Users\ruchidod\Adobe Flash Builder 4.6\OnlineDiagramEditor\src\OnlineDiagramEditor.mxml:3522]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at mx.core::UIComponent/dispatchEvent()[E:\dev\4.y\frameworks\projects\framework\src\mx\core\UIComponent.as:13152]
at mx.managers::SystemManager/mouseEventHandler()[E:\dev\4.y\frameworks\projects\framework\src\mx\managers\SystemManager.as:2918]
some times it gives
Error: Error #2134: Cannot create SharedObject.
at flash.net::SharedObject$/getLocal()
at OnlineDiagramEditor/SaveData_mouseDownHandler()[C:\Users\ruchidod\Adobe Flash Builder 4.6\OnlineDiagramEditor\src\OnlineDiagramEditor.mxml:3236]
at OnlineDiagramEditor/__SaveData_mouseDown()[C:\Users\ruchidod\Adobe Flash Builder 4.6\OnlineDiagramEditor\src\OnlineDiagramEditor.mxml:3522]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at mx.core::UIComponent/dispatchEvent()[E:\dev\4.y\frameworks\projects\framework\src\mx\core\UIComponent.as:13152]
at mx.managers::SystemManager/mouseEventHandler()[E:\dev\4.y\frameworks\projects\framework\src\mx\managers\SystemManager.as:2918]
SharedObjects are automatically saved in a predefined location and they aren't cross-domain, that means that each domain can read only its own SO.
The localPath is only a parameter that defines in which subfolder of the predefined location Flash player should save the SO. This is, by default, referred to the SWF that is saving the SO itself.
localPath: String [optional]- A string that specifies the full or partial path to the SWF file that created the shared object, and that determines where the shared object is stored locally. The default value is the full path.
Also:
Although the localPath parameter is optional, you should give some thought to its use, especially if other SWF files need to access the shared object. If the data in the shared object is specific to one SWF file that will not be moved to another location, then use of the default value makes sense. If other SWF files need access to the shared object, or if the SWF file that creates the shared object will later be moved, then the value of this parameter affects whether any SWF files are able to access the shared object. For example, if you create a shared object with localPath set to the default value of the full path to the SWF file, then no other SWF file can access that shared object. If you later move the original SWF file to another location, then not even that SWF file can access the data already stored in the shared object.
So if you've multiple SWF on the same domain which need to access the same SO, you need to give a path to getLocal(), the same for each SWF.
http://help.adobe.com/en_US/AS2LCR/Flash_10.0/help.html?content=00001508.html
For example:
In Windows, SO are stored in %APPDATA%\Macromedia\Flash Player\#SharedObjects\.
Here is a subfolder for your user, like 5D3RT21F.
Then we have a subfolder for the domain that originated the SO file, like www.flickr.com.
Then several subfolders to reflect the relative path of the SWF on the domain, like \apps\slideshow\show.swf\, you can find the SO file in here.
But if you specify / (root) as localPath then you'll find the SO file directly in www.flickr.com and other SWF on the same domain will access it freely.

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)