Create Temp XML File With ActionScript
I would like to locally save an XML file with ActionScript, as a temp file, if at all possible. I've read all about how AS won't let you do this without dialogs (and I understand the security concerns), but surely there must be some sort of temp op开发者_StackOverflow社区tion? I need to dynamically generate some XML to pass to another swf using URLVariables
(I have no control over this part). Right now, I can only pass in previously created XML files.
var urlReq:URLRequest = new URLRequest(url);
var variables:URLVariables = new URLVariables();
variables.data_file = "us/data.xml"; //data.xml is static/already created
urlReq.data = variables;
ldr.load(urlReq);
I would like to replace us/data.xml
with xml I've created.
You should be able to pass the XML object directly through the URLRequest
or the URLVariables
object. Something like:
var x:XML = ...;
var req:URLRequest = new URLRequest( url )
req.data = xml;
ldr.load( urlReq );
If the xml is large, then you can compress it with a ByteArray
:
var x:XML = ...;
var bytes:ByteArray = new ByteArray;
bytes.writeUTFBytes( x );
bytes.compress();
var req:URLRequest = new URLRequest( url )
req.data = bytes;
ldr.load( urlReq );
If you have a problem, you might need to encode it with Base64, in which case, you can use this lib: http://jpauclair.net/2010/01/09/base64-optimized-as3-lib/
Also as some alternatives, have you looked at LocalConnection
: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/LocalConnection.html or SharedObject.getRemote()
(requires Flash Media Server): http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/SharedObject.html#getRemote()
精彩评论