sharedObject location - actionscript-3

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.

Related

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.

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.

How to Delete/Remove a Property from a SharedObject in AS3

I have a SharedObject in which I'm saving some data in a flash app. I'm trying to remove some saved data but it doesn't work.
trace(delete(localData.data[key]));
The delete command returns true, but when I reload the data it looks it was not deleted.
As of now the best solution was to "localData.clear();" all the data and then to save it without the fields I want to remove.
You need to call the flush() method to "commit" your changes:
Immediately writes a locally persistent shared object to a local file.
If you don't use this method, Flash Player writes the shared object to
a file when the shared object session ends — that is, when the SWF
file is closed, when the shared object is garbage-collected because it
no longer has any references to it, or when you call
SharedObject.clear() or SharedObject.close().
More info here: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/SharedObject.html#flush()

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;

Check input file size using Flash

I have a multipart html form with a file input element and would like to check the size of the selected file before uploading. I can access the file path using the value attribute, however is it possible to pass that path to a swf and have the swf return the file size or is this blocked by the flash sandbox? Are there any existing projects that already do this? I'd like to avoid replacing my file input element with a flash uploader if possible.
Passing file names and accessing it via Flash is security risk. Flash does support a FileReference API, but it requires user input in order to work.