imagePane.addEventListener("complete", imageDownloaded);
imagesCb.addEventListener("change", downloadImage);
uploadBtn.addEventListener("click", uploadImage);
/* If the image does not download, the event object's total property will
equal -1. In that case, display a message to the user. */
function imageDownloaded(event:Object):Void {
if (event.total == -1) {
imagePane.contentPath = "Message";
}
}
/* When the user selects an image from the ComboBox, or when the
downloadImage() function is called directly from the
listener.onComplete() method, the downloadImage() function sets the
contentPath of the ScrollPane in order to start downloading the image
to the player. */
function downloadImage(event:Object):Void {
imagePane.contentPath = "http://www.helpexamples.com/flash/file_io/
images/" + imagesCb.value;
}
/* When the user clicks the button, Flash calls the uploadImage()
function, and it opens a file browser dialog box. */
function uploadImage(event:Object):Void {
imageFile.browse([{description: "Image Files", extension:
"*.jpg;*.gif;*.png"}]);
}
This ActionScript code first imports the FileReference class and initializes, positions, and
resizes each of the components on the Stage. Next, a listener object is defined, and three
event handlers are defined:
then added to a new FileReference object named
added to the
imagePane
Button instance. Each of the event listener functions is defined in the code
uploadBtn
that follows this section of code.
The first function,
downloaded images is -1, and if so, it sets the
the movie clip with the linkage identifier of Message, which you created in a previous step.
The second function,
image into the ScrollPane instance. When the image has downloaded, the
imageDownloaded()
image successfully downloaded. The final function,
dialog box, which filters all JPEG, GIF, and PNG images.
12.
Save your changes to the document.
,
onSelect
onOpen
ScrollPane instance,
imageDownloaded()
downloadImage()
function defined earlier is triggered and checks to see whether the
, and
onComplete
. Next, event listeners are
imageFile
ComboBox instance, and
imagesCb
, checks to see if the amount of total bytes for the
for the ScrollPane instance to
contentPath
, attempts to download the recently uploaded
uploadImage()
About file uploading and downloading
. The listener object is
, opens a file browser
649
Need help?
Do you have a question about the FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH and is the answer not in the manual?