Previewing an image before uploading it using the FileReference class in Flash Player 10
2008-08-29 16:38
691 查看
The following example shows how you can browse for an image file from your local file system and preview the image before uploading it to a remote webserver by using the FileReference class’s new load()
method in Flash Player 10. Once the user has browsed and selected an image from their local machine, you can call the load()
method which dispatches a complete event when the image has successfully loaded, at which point you can display the image using a Flex Image control and setting the Image instance’s source
property to the FileReference class’s data
property (which is a ByteArray).
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/previewing-an-image-before-uploading-it-using-the-filereference-class-in-flash-player-10/ -->
<Application name="FileReference_load_test"
xmlns="http://ns.adobe.com/mxml/2009"
xmlns:mx="library:adobe/flex/halo"
xmlns:net="flash.net.*"
layout="flex.layout.BasicLayout">
<Script>
<![CDATA[
import mx.controls.Alert;
import mx.utils.ObjectUtil;
private function btn_click(evt:MouseEvent):void {
var arr:Array = [];
arr.push(new FileFilter("Images", ".gif;*.jpeg;*.jpg;*.png"));
fileReference.browse(arr);
}
private function fileReference_select(evt:Event):void {
fileReference.load();
}
private function fileReference_complete(evt:Event):void {
img.source = fileReference.data;
Alert.show(ObjectUtil.toString(fileReference));
}
]]>
</Script>
<Declarations>
<net:FileReference id="fileReference"
select="fileReference_select(event);"
complete="fileReference_complete(event);" />
</Declarations>
<mx:Panel id="panel"
layout="absolute"
horizontalCenter="0"
verticalCenter="0"
width="500"
height="300">
<mx:Image id="img"
verticalCenter="0"
horizontalCenter="0"
maxWidth="200"
maxHeight="200" />
<mx:ControlBar>
<mx:Button id="btn"
label="Browse and preview..."
click="btn_click(event);" />
<mx:Button label="Upload..."
enabled="false" />
</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.
相关文章推荐
- Saving files locally using the FileReference class’s save() method in Flash Player 10
- parse and display a BMP image in the Flash Player using the ByteArray class
- Uploading files in Flex using the FileReference class
- Downloading files in Flex using the FileReference class
- 调试记录:The public type <<classname>> must be defined in its own file
- Effects with the Pixel Bender Toolkit – Part 5: Applying a filter to an image in Flash
- Showing the Image file thumbnail view in ListView control using VC++ 6.0
- How to scroll an image, if it does not fit in the display
- The type java.lang.Object cannot be resolved.It is indirectly referenced from required .class file
- 使用cocapods报错 [!] Your Podfile has had smart quotes sanitised. To avoid issues in the future, you should not use TextEdit for editing it. If you are not using TextEdit, you should turn off smart quotes
- A class file was not written. The project may be inconsistent, if so try refreshing this project and building it
- The type java.lang.Object cannot be resolved.It is indirectly referenced from required .class file
- [原]openstack-kilo--issue(十九) ImportError: Could not import settings 'openstack_dashboard.settings' (Is it on sys.path? Is there an import error in the settings file?): No module named main
- The type org.eclipse.core.commands.common.EventManager cannot be resolved. It is indirectly referenced from required .class file
- Truncated class file description The server encountered aninternal error that prevented it from fulf
- detects edges in an image using the homogeneity operator
- Effects with the Pixel Bender Toolkit – Part 5: Applying a filter to an image in Flash
- A class file was not written. The project may be inconsistent, if so try refreshing this project and building it. eclipse提示错误
- 《How hard can it be? Estimating the difficulty of visual search in an image》和 PPT
- A class file was not written. The project may be inconsistent, if so try refreshing this project and building it. eclipse提示错误