Comunidad de diseño web y desarrollo en internet online

Redimensionar imagenes al subirlas a un flash

Citar            
MensajeEscrito el 24 Jun 2009 07:54 am
Tengo un problemilla.

Tengo un flash por el cual la gente puede subir una imagen a la web y ser mostrada. Todo funciona, excepto que la imagen no se redimensiona al tamaño del mc y sale con scroll. Quiero que esa imagen se ajuste al tamaño del mc. Alguien me puede echar una mano.

Este es el codigo Flash.

Código :

//Allow this domain
System.security.allowDomain("http://localhost/");
import flash.net.FileReference;
// The listener object listens for FileReference events.
var listener:Object = new Object();

// When the user selects a file, the onSelect() method is called, and
// passed a reference to the FileReference object.
listener.onSelect = function(selectedFile:FileReference):Void {
  //clean statusArea and details area
  statusArea.text = details.text = ""
  // Flash is attempting to upload the image.
  statusArea.text += "Subiendo imagen " + selectedFile.name + "\n";
  // Upload the file to the PHP script on the server.
  selectedFile.upload("upload.php");
};

// the file is starting to upload.
listener.onOpen = function(selectedFile:FileReference):Void {
  statusArea.text += "Subiendo " + selectedFile.name + "\n";
};
//Possible file upload errors
listener.onHTTPError = function(file:FileReference, httpError:Number):Void {
   imagePane.contentPath = "error";
   imagePane.content.errorMSG.text = "HTTPError number: "+httpError +"\nFile: "+ file.name;
}

listener.onIOError = function(file:FileReference):Void {
   imagePane.contentPath = "error";
   imagePane.content.errorMSG.text = "IOError: "+ file.name;
}

listener.onSecurityError = function(file:FileReference, errorString:String):Void {
   imagePane.contentPath = "error";
   imagePane.content.errorMSG.text = "SecurityError: "+SecurityError+"\nFile: "+ file.name;   
}

// the file has uploaded
listener.onComplete = function(selectedFile:FileReference):Void {
  // Notify the user that Flash is starting to download the image.
  statusArea.text += "Subida terminada.\nNow downloading " + selectedFile.name + " to player\n";
  //Show file details
  details.text = ""
  for(i in selectedFile) details.text +="<b>"+i+":</b> "+selectedFile[i]+"\n"
  // Call the custom downloadImage() function.
  downloadImage(selectedFile.name);
};

var imageFile:FileReference = new FileReference();
imageFile.addListener(listener);

uploadBtn.onPress = uploadImage;
imagePane.addEventListener("completado", imageDownloaded);

// Call the uploadImage() function, opens a file browser dialog.
function uploadImage(event:Object):Void {
  imageFile.browse([{description: "Image Files", extension: "*.jpg;*.gif;*.png"}]);
}

// If the image does not download, the event object's total property
// will equal -1. In that case, display am error message
function imageDownloaded(event:Object):Void {
  if(event.total == -1) {
    imagePane.contentPath = "error";   
  }
}

// show uploaded image in scrollPane
function downloadImage(file:Object):Void {
  imagePane.contentPath =  "./files/" + file;
  
  setProperty("imageFile", _width, "150");

}

stop()



y este el código php.

Código PHP :

<?php
//create the directory if doesn't exists (should have write permissons)
if(!is_dir("./files")) mkdir("./files", 0755); 
//move the uploaded file
move_uploaded_file($_FILES['Filedata']['tmp_name'], "./files/".$_FILES['Filedata']['name']);
chmod("./files/".$_FILES['Filedata']['name'], 0777);
?>

Por yuryuflo

2 de clabLevel



 

firefox
Citar            
MensajeEscrito el 24 Jun 2009 08:42 am
Cuando termines de subir la imagen (en el evento onComplete), lee la imagen del servidor mediante MovieClipLoader, con esta clase puedes saber cuando la imagen se descargó y se ha leído el primer frame dentro del movieClip (evento onLoadInit) entonces en este momento redimensionas el movieClip que la contiene.

Mira este post.

Por elchininet

Claber

3921 de clabLevel

17 tutoriales

Genero:Masculino  

Front-end developer at Booking.com

firefox
Citar            
MensajeEscrito el 24 Jun 2009 02:18 pm
He insertado el código que habia en el link a continuación de onComplete y sigue sin redireccionarla. Tengo que modificar algo del código como el nombre del mc donde se carga la foto o cambiar foto1.jpg por el nombre de la variable?

Muchas gracias de antemano, sólo me falta esto para poder colgar la web.

Código ActionScript :

// the file has uploaded
listener.onComplete = function(selectedFile:FileReference):Void {
   
var myMC:MovieClip = _root.createEmptyMovieClip("myMC", _root.getNextHighestDepth());

var loader:MovieClipLoader = new MovieClipLoader();
var listener:Object = new Object();

listener.onLoadInit = function(target:MovieClip):Void{
   
   target._width = 200;
   target._yscale = target._xscale;
   
}

loader.addListener(listener);
loader.loadClip("foto1.jpg", myMC);
   
   
   
  // Notify the user that Flash is starting to download the image.
  statusArea.text += "Subida terminada.\nNow downloading " + selectedFile.name + " to player\n";
  //Show file details
  details.text = ""
  for(i in selectedFile) details.text +="<b>"+i+":</b> "+selectedFile[i]+"\n"
  // Call the custom downloadImage() function.
  downloadImage(selectedFile.name);

Por yuryuflo

2 de clabLevel



 

firefox
Citar            
MensajeEscrito el 24 Jun 2009 09:09 pm
Debes en vez de "foto1.jpg" poner el nombre de la imagen que acabas de subir, de lo contrario flash no podrá leerla. Debes leer la imagen en el movieClip que tu quieras, en este caso está creando un movieClip en blanco en la raiz de la escena, en tu caso puedes utilizar un movieClip que ya existe o puedes crear uno nuevo.

Por elchininet

Claber

3921 de clabLevel

17 tutoriales

Genero:Masculino  

Front-end developer at Booking.com

firefox
Citar            
MensajeEscrito el 25 Jun 2009 08:58 am
Sigue sin funcionarme.
He probado subiendo una foto llamada foto1.jpg, con el mc que crea, cambiándole el nombre, poniendo la variable a foto1.jpg para que me coja cada vez la foto que suba. Pero me estoy volviendo loco. jejeje

Por yuryuflo

2 de clabLevel



 

firefox
Citar            
MensajeEscrito el 26 Jun 2009 08:11 am
Crea el ejemplo en local (sin subir la foto), sólo leéla y redimensiónala, cuando tengas esto solucionado entras en lo más complicado que es subirla y después leerla. Sólo veo que en tu php subes la imagen a una carpeta llamada "files" y en el último código intentabas leer la imagen donde mismo está el SWF.

Por elchininet

Claber

3921 de clabLevel

17 tutoriales

Genero:Masculino  

Front-end developer at Booking.com

firefox

 

Cristalab BabyBlue v4 + V4 © 2011 Cristalab
Powered by ClabEngines v4, HTML5, love and ponies.