Saving files locally using the FileReference class’s save() method in Flash Player 10
2008-08-29 16:21
489 查看
The following example shows how you can use the FileReference class’s new
Full code after the jump.
To use the following code, you must have Flash Player 10 and a Flex Gumbo SDK installed in your Flex Builder 3. For more information on downloading and installing the Gumbo SDK into Flex Builder 3, see Using the beta Gumbo SDK in Flex Builder 3″.
View MXML
View source is enabled in the following example.
You can also pass the XML object directly to the FileReference class’s
View MXML
Or, you can use the ImageSnapshot class to take a screenshot of an item on the display list and save it to the user’s hard drive by passing a ByteArray object to the FileReference class’s
View MXML
View source is enabled in the following example.
For more information on the new FileReference capabilities in Flash Player 10, see the Flex Gumbo documentation at http://livedocs.adobe.com/flex/gumbo/langref/flash/net/FileReference.html.
save()method in Flash Player 10 to save text, XML, and image files to a user’s hard drive.
Full code after the jump.
To use the following code, you must have Flash Player 10 and a Flex Gumbo SDK installed in your Flex Builder 3. For more information on downloading and installing the Gumbo SDK into Flex Builder 3, see Using the beta Gumbo SDK in Flex Builder 3″.
View MXML
<?xml version="1.0" encoding="utf-8"?> <!-- http://blog.flexexamples.com/2008/08/25/saving-files-locally-using-the-filereference-classs-save-method-in-flash-player-10/ --> <Application name="FileReference_save_test" xmlns="http://ns.adobe.com/mxml/2009" xmlns:mx="library:adobe/flex/halo" xmlns:net="flash.net.*" layout="flex.layout.BasicLayout" creationComplete="init();"> <Script> <![CDATA[ private function init():void { textArea.text = describeType(FileReference).toXMLString(); } private function btn_click(evt:MouseEvent):void { fileReference.save(textArea.text, "describeType.txt"); } ]]> </Script> <Declarations> <net:FileReference id="fileReference" /> </Declarations> <mx:Panel id="panel" width="500" height="300" verticalCenter="0" horizontalCenter="0"> <mx:TextArea id="textArea" editable="true" width="100%" height="100%" /> <mx:ControlBar horizontalAlign="right"> <Button id="btn" label="Save Text" click="btn_click(event);" /> </mx:ControlBar> </mx:Panel> </Application>
View source is enabled in the following example.
You can also pass the XML object directly to the FileReference class’s
save()method, as seen in the following example:
View MXML
<?xml version="1.0" encoding="utf-8"?> <!-- http://blog.flexexamples.com/2008/08/25/saving-files-locally-using-the-filereference-classs-save-method-in-flash-player-10/ --> <Application name="FileReference_save_test" xmlns="http://ns.adobe.com/mxml/2009" xmlns:mx="library:adobe/flex/halo" xmlns:net="flash.net.*" layout="flex.layout.BasicLayout" creationComplete="init();"> <Script> <![CDATA[ private const xmlObj:XML = describeType(FileReference); private function init():void { textArea.text = xmlObj.toXMLString(); } private function btn_click(evt:MouseEvent):void { fileReference.save(xmlObj, "describeType.xml"); } ]]> </Script> <Declarations> <net:FileReference id="fileReference" /> </Declarations> <mx:Panel id="panel" width="500" height="300" verticalCenter="0" horizontalCenter="0"> <mx:TextArea id="textArea" editable="true" width="100%" height="100%" /> <mx:ControlBar horizontalAlign="right"> <Button id="btn" label="Save" click="btn_click(event);" /> </mx:ControlBar> </mx:Panel> </Application>
Or, you can use the ImageSnapshot class to take a screenshot of an item on the display list and save it to the user’s hard drive by passing a ByteArray object to the FileReference class’s
save()method, as seen in the following example:
View MXML
<?xml version="1.0" encoding="utf-8"?> <!-- http://blog.flexexamples.com/2008/08/25/saving-files-locally-using-the-filereference-classs-save-method-in-flash-player-10/ --> <Application name="FileReference_save_test" xmlns="http://ns.adobe.com/mxml/2009" xmlns:mx="library:adobe/flex/halo" xmlns:net="flash.net.*" layout="flex.layout.BasicLayout" creationComplete="init();"> <Script> <![CDATA[ import mx.graphics.ImageSnapshot; import mx.graphics.codec.*; private const jpegEnc:JPEGEncoder = new JPEGEncoder(); private const xmlObj:XML = describeType(FileReference); private function init():void { textArea.text = xmlObj.toXMLString(); } private function btn_click(evt:MouseEvent):void { var imageSnap:ImageSnapshot = ImageSnapshot.captureImage(panel, 0, jpegEnc); fileReference.save(imageSnap.data, "describeType.jpg"); } ]]> </Script> <Declarations> <net:FileReference id="fileReference" /> </Declarations> <mx:Panel id="panel" width="500" height="300" verticalCenter="0" horizontalCenter="0"> <mx:TextArea id="textArea" editable="true" width="100%" height="100%" /> <mx:ControlBar horizontalAlign="right"> <Button id="btn" label="Save" click="btn_click(event);" /> </mx:ControlBar> </mx:Panel> </Application>
View source is enabled in the following example.
For more information on the new FileReference capabilities in Flash Player 10, see the Flex Gumbo documentation at http://livedocs.adobe.com/flex/gumbo/langref/flash/net/FileReference.html.
相关文章推荐
- Previewing an image before uploading it using the FileReference class in Flash Player 10
- Downloading files in Flex using the FileReference class
- Uploading files in Flex using the FileReference class
- parse and display a BMP image in the Flash Player using the ByteArray class
- The number of method references in a .dex file cannot exceed 64K.
- Android SDK低版本切换高版本错误 Error:The number of method references in a .dex file cannot exceed 64K.
- The number of method references in a .dex file cannot exceed 64K
- 如何处理 android 方法总数超过 65536 . the number of method references in a .dex file exceed 64k
- AndroidStudio线上APK打包.Error:The number of method references in a .dex file cannot exceed 64K.
- Reading files in JavaScript using the File APIs
- Android studio: The number of method references in a .dex file cannot exceed 64K. Learn how to resol
- Android “64k”的问题以及解决方案 Error:The number of method references in a .dex file cannot exceed 64K.
- Error:The number of method references in a .dex file cannot exceed 64K.
- The number of method references in xxx.dex file cannot exceed 64K问题
- Android开发 Error(建议收藏下来以备不时之需):The number of method references in a .dex file cannot exceed 64K.
- Error:The number of method references in a .dex file cannot exceed 64K 问题解决
- Error:The number of method references in a .dex file cannot exceed 64K.
- The number of method references in a .dex file cannot exceed 64k API 17
- Method XXX was discovered in the .class file but cannot be resolved in the class
- Reading and Writing Local Files in Flash Player 10