• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
Locked
0

How to Save Uploaded image to the server from Flash As3

Community Beginner ,
Nov 14, 2015 Nov 14, 2015

Copy link to clipboard

Copied

Hi everyone!!

While browsing & uploading images from local drive I need to save the uploaded image in a folder at server (PHP)

It has to be done automatically once the uploading is finished.


Thanks

Here is the code:

import flash.events.MouseEvent;

import flash.net.FileReference;

import flash.net.FileFilter;

import flash.utils.ByteArray;

import flash.events.MouseEvent;

import flash.events.Event;

import flash.events.IOErrorEvent;

import flash.display.MovieClip;

import fl.controls.ProgressBarMode;

var mFileReference:FileReference;

// Setup button to handle browsing

browseButton.buttonMode=true;

browseButton.mouseChildren=false;

browseButton.addEventListener(MouseEvent.CLICK, onBrowseButtonClicked);

// Hide progress bar

progressBar.visible=false;

// This function is called when the BROWSE button is clicked.

function onBrowseButtonClicked(event:MouseEvent):void

{

  trace("onBrowse");

  mFileReference=new FileReference();

  mFileReference.addEventListener(Event.SELECT, onFileSelected);

  var swfTypeFilter:FileFilter = new FileFilter("SWF/JPG/PNG Files","*.jpeg; *.jpg;*.gif;*.png");

  var allTypeFilter:FileFilter = new FileFilter("All Files (*.*)","*.*");

  mFileReference.browse([swfTypeFilter, allTypeFilter]);

}

// This function is called after user selected a file in the file browser dialog.

function onFileSelected(event:Event):void

{

  trace("onFileSelected");

  // This callback will be called when the file is uploaded and ready to use

  mFileReference.addEventListener(Event.COMPLETE, onFileLoaded);

  // This callback will be called if there's error during uploading

  mFileReference.addEventListener(IOErrorEvent.IO_ERROR, onFileLoadError);

  // Optional callback to track progress of uploading

  mFileReference.addEventListener(ProgressEvent.PROGRESS, onProgress);

  // Tells the FileReference to load the file

  mFileReference.load();

  // Show progress bar

  progressBar.visible=true;

  progressBar.mode=ProgressBarMode.MANUAL;

  progressBar.minimum=0;

  progressBar.maximum=100;

  browseButton.visible=false;

}

// This function is called to notify us of the uploading progress

function onProgress(event:ProgressEvent):void

{

  var percentLoaded:Number=event.bytesLoaded/event.bytesTotal*100;

  trace("loaded: "+percentLoaded+"%");

  progressBar.setProgress(percentLoaded, 100);

}

// This function is called after the file has been uploaded.

function onFileLoaded(event:Event):void

{

  var fileReference:FileReference=event.target as FileReference;

  // These steps below are to pass the data as DisplayObject

  // These steps below are specific to this example.

  var data:ByteArray=fileReference["data"];

  trace("File loaded");

  mFileReference.removeEventListener(Event.COMPLETE, onFileLoaded);

  mFileReference.removeEventListener(IOErrorEvent.IO_ERROR, onFileLoadError);

  mFileReference.removeEventListener(ProgressEvent.PROGRESS, onProgress);

  browseButton.visible=true;

  var movieClipLoader:Loader=new Loader();

  movieClipLoader.loadBytes(data);

  movieClipLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onMovieClipLoaderComplete);

}

function onFileLoadError(event:Event):void

{

  // Hide progress bar

  progressBar.visible=false;

  browseButton.visible=true;

  mFileReference.removeEventListener(Event.COMPLETE, onFileLoaded);

  mFileReference.removeEventListener(IOErrorEvent.IO_ERROR, onFileLoadError);

  mFileReference.removeEventListener(ProgressEvent.PROGRESS, onProgress);

  trace("File load error");

// This function below is specific to this example.

// It does the processing required to display the swf/png/jpeg file that we have just loaded.

function onMovieClipLoaderComplete(event:Event):void

{

  // Hide progress bar

  progressBar.visible=false;

  var loadedContent:DisplayObject=event.target.content;

  var loader:Loader=event.target.loader as Loader;

  // Fit to stage

  trace("loadedContent.width="+loadedContent.width);

  loadedContent.scaleX=container.width/loadedContent.width;

  loadedContent.scaleY=container.height/loadedContent.height;

  trace("loadedContent.scaleX="+loadedContent.scaleX);

  trace("loadedContent.width="+loadedContent.width);

  trace("this.stage.width="+this.stage.width);

  container.addChild(loader);

}

Views

866

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines