Bueno ya que no puedo dejar archivos adjuntos te dejo la clase aca, tu archivo AS se tiene que llamar CargarImagenes y en el fla lo unico que necesitas tener es un boton (componente) en la biblioteca.
Código PHP:
// Created by Personagorda para Foros del Web.
package
{
import fl.controls.Button;
import flash.display.Bitmap;
import flash.display.Loader;
import flash.display.MovieClip;
import flash.net.FileFilter;
import flash.net.FileReference;
import flash.text.TextField;
import flash.text.TextFieldType;
import flash.events.MouseEvent;
import flash.events.Event;
public class CargarImagenes extends MovieClip
{
private static const MAX_WIDTH : Number = 640;
private static const MAX_HEIGHT : Number = 350;
private var fileRef: FileReference;
private var fileFilter: FileFilter;
private var loader: Loader;
private var bitmap: Bitmap;
private var browseBtn: Button;
private var browseTxt: TextField;
private var removeBtn: Button;
public function CargarImagenes ( )
{
iniciar ( ) ;
}
private function iniciar ( ) : void
{
//Personalizas el escenario.
browseTxt = new TextField ( ) ;
browseTxt.type = TextFieldType.INPUT;
browseTxt.x = 0;
browseTxt.y = 0;
browseTxt.height = 21;
browseTxt.width = 100;
browseTxt.border = true;
browseTxt.background = true;
browseTxt.textColor = 0x000000;
addChild ( browseTxt ) ;
browseBtn = new Button ( ) ;
browseBtn.label = "Browse";
browseBtn.name = "browse";
browseBtn.x = 148;
browseBtn.y = 0;
browseBtn.useHandCursor = true;
browseBtn.addEventListener ( MouseEvent.CLICK, handleMouseEvent ) ;
addChild ( browseBtn ) ;
removeBtn = new Button ();
removeBtn.label = "Remove Image";
removeBtn.name = "Remove Image";
removeBtn.x = 250;
removeBtn.y = 0;
removeBtn.useHandCursor = true;
removeBtn.addEventListener( MouseEvent.CLICK, removeIMG );
addChild ( removeBtn )
fileFilter = new FileFilter ( "Image", "*.jpg;*.gif;*.png;" ) ;
}
private function removeIMG (evt:MouseEvent):void
{
removeChild ( bitmap );
browseTxt.text = "";
}
private function handleMouseEvent ( evt : MouseEvent ) : void
{
switch ( String ( evt.target.name ))
{
case "browse" :
fileRef = new FileReference ( ) ;
fileRef.browse ( [fileFilter] ) ;
fileRef.addEventListener ( Event.SELECT, onImageSelect) ;
trace ( "Browse" ) ;
break;
}
}
private function onImageSelect ( evt : Event ) : void
{
fileRef.load ( ) ;
fileRef.addEventListener ( Event.COMPLETE, onDataLoaded ) ;
browseTxt.text = String ( evt.target.name ) ;
}
private function onDataLoaded ( evt : Event ) : void
{
var tempFileRef : FileReference = FileReference ( evt.target ) ;
loader = new Loader ( ) ;
loader.contentLoaderInfo.addEventListener ( Event.COMPLETE, onImageLoaded ) ;
loader.loadBytes ( tempFileRef.data ) ;
}
private function onImageLoaded ( evt : Event ) : void
{
bitmap = Bitmap ( evt.target.content ) ;
bitmap.smoothing = true;
bitmap.x = 0;
bitmap.y = 100;
addChild ( bitmap ) ;
//Ajustas la medida si es necesario.
if ( bitmap.width > MAX_WIDTH || bitmap.height > MAX_HEIGHT ) {
resizeBitmap ( bitmap ) ;
}
}
private function resizeBitmap( target : Bitmap ) : void
{
if ( target.height > target.width ) {
target.width = MAX_WIDTH;
target.scaleY = target.scaleX;
} else if ( target.width >= target.height ) {
target.height = MAX_HEIGHT;
target.scaleX = target.scaleY;
}
}
}
}