Create XML and save to desktop
...
@author Brian Hodge (brian@hodgedev.com)
♥0 |
Line 47 |
Modified 2009-10-23 08:36:33 |
MIT License
archived:2017-03-09 13:06:16
ActionScript3 source code
/**
* Copyright sinclairc5 ( http://wonderfl.net/user/sinclairc5 )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/hDO2
*/
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.utils.ByteArray;
import flash.net.FileReference;
import flash.text.TextField;
/**
* ...
* @author Brian Hodge (brian@hodgedev.com)
*/
public class FlashTest extends Sprite
{
private var _xml:XML;
public function FlashTest():void
{
var txt:TextField = new TextField()
txt.text = "click to save XML file to desktop";
txt.width = 200;
addChild( txt );
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
//Calling the save method requires user interaction and Flash Player 10
stage.addEventListener(MouseEvent.MOUSE_DOWN, _onMouseDown);
_xml= <xml>
<test>data</test>
</xml>;
}
private function _onMouseDown(e:MouseEvent):void
{
var ba:ByteArray = new ByteArray();
ba.writeUTFBytes(_xml);
var fr:FileReference = new FileReference();
fr.addEventListener(Event.SELECT, _onRefSelect);
fr.addEventListener(Event.CANCEL, _onRefCancel);
fr.save(ba, "filename.xml");
}
private function _onRefSelect(e:Event):void
{
trace('select');
}
private function _onRefCancel(e:Event):void
{
trace('cancel');
}
}
}