shiyon
08-21-2009, 10:01 AM
I cannot load the image for 3d view using the following code.
/*code begins*/
package com.xpectral.clips{
import flash.text.TextField;
import flash.events.*;
import flash.events.MouseEvent;
import flash.display.MovieClip;
import flash.display.DisplayObject;
import flash.utils.Timer;
import flash.display.SimpleButton;
import flash.net.FileReference;
import flash.net.URLRequest;
import flash.geom.Matrix;
import flash.geom.Rectangle;
import flash.net.FileFilter;
import flash.display.BitmapData;
import flash.display.Loader;
public class selectorImagen extends MovieClip{
public var movingX:Boolean = false;
public var locked:Boolean = true;
public var laImagen:FileReference;
public var textura:BitmapData;
public var imagenCarga:Loader
public var imagenRuta:String;
public var imagenId:uint;
public var trans:String = "";
public function selectorImagen(){
setBotones(false);
elPreloader.visible = false;
cargador.addEventListener(MouseEvent.CLICK,getBitm ap);
}
public function setBotones(modo:Boolean){
bt_go3D.visible = modo;
sx.visible = modo;
sy.visible = modo;
locker.visible = modo;
}
public function setUpEvents():void{
img.bmp.addEventListener(MouseEvent.MOUSE_DOWN,arr astra);
img.bmp.addEventListener(MouseEvent.MOUSE_UP,para) ;
sx.addEventListener(MouseEvent.MOUSE_DOWN,arrastra Sx);
sx.addEventListener(MouseEvent.MOUSE_UP,para);
sx.addEventListener(MouseEvent.MOUSE_OVER,function (e:MouseEvent){e.target.buttonMode = true;});
sy.addEventListener(MouseEvent.MOUSE_DOWN,arrastra Sy);
sy.addEventListener(MouseEvent.MOUSE_UP,para);
sy.addEventListener(MouseEvent.MOUSE_OVER,function (e:MouseEvent){e.target.buttonMode = true;});
locker.addEventListener(MouseEvent.MOUSE_OVER,func tion(e:MouseEvent){e.target.buttonMode = true;});
locker.addEventListener(MouseEvent.CLICK,setScaleM ode);
//bt_go3D.addEventListener(MouseEvent.CLICK,cargaIma gen);
this.stage.addEventListener(MouseEvent.MOUSE_UP,pa ra);
}
public function arrastra(e:MouseEvent):void{
img.bmp.startDrag();
}
public function arrastraSx(e:MouseEvent):void{
sx.startDrag(false, new Rectangle(44,454,700-11,0));
movingX = true;
}
public function arrastraSy(e:MouseEvent):void{
sy.startDrag(false, new Rectangle(786,156,0,291-11));
movingX = false;
}
public function para(e:MouseEvent):void{
img.bmp.stopDrag();
sx.stopDrag();
sy.stopDrag();
}
public function setScaleMode(e:MouseEvent):void{
if(!locked){
locked = true;
MovieClip(locker).gotoAndStop(1);
}else{
locked = false;
MovieClip(locker).gotoAndStop(2);
}
}
public function loop(e:TimerEvent):void{
var scalaX = Math.max((((sx.x-44)*200)/689)/100,0.05);
var scalaY = Math.max((((sy.y-156)*200)/280)/100,0.05);
if(!locked){
img.bmp.scaleX = scalaX;
img.bmp.scaleY = scalaY;
}else{
if(movingX){
img.bmp.scaleX = img.bmp.scaleY = scalaX;
updateSy(scalaX);
}else{
img.bmp.scaleX = img.bmp.scaleY = scalaY;
updateSx(scalaY);
}
}
}
public function updateSx(s:Number):void{
s = s*50;
sx.x = 44+((s*689)/100);
}
public function updateSy(s:Number):void{
s = s*50;
sy.y = 156+((s*280)/100);
}
public function getBitmap(e:MouseEvent):void{
MovieClip(this.parent).fondo3D.x = 286;
MovieClip(this.parent).fondo3D.y = 177;
MovieClip(this.parent).lampara.x = 290;
MovieClip(this.parent).lampara.y = 100;
trace(MovieClip(this.parent).freeBuy)
if(!MovieClip(this.parent).freeBuy){
MovieClip(this.parent).bt_save.visible = true;
MovieClip(this.parent).bt_save.addEventListener(Mo useEvent.CLICK,MovieClip(this.parent).openSave);
}else{
MovieClip(this.parent).bt_save.visible = false;
MovieClip(this.parent).add_mc.visible = true;
MovieClip(this.parent).add_mc.add_bt.addEventListe ner(MouseEvent.CLICK,MovieClip(this.parent).addCar );
}
procesaBitmap();
}
public function procesaBitmap(){
textura = new BitmapData(700,350,false,0xFEFEFE);
textura.draw(img.bmp,new Matrix(img.bmp.scaleX,0,0,img.bmp.scaleY,img.bmp.x ,img.bmp.y),null,null,new Rectangle(0,-30,700,390));
this.visible = false;
MovieClip(this.parent).fondo3D.visible = true;
MovieClip(this.parent).lampara.visible = true;
if(!MovieClip(this.parent).lampara.iniciado) MovieClip(this.parent).lampara.init3D(textura);
else MovieClip(this.parent).lampara.reInit(textura);
}
public function loadNewBitmap(ruta:String,t:String){
trans = t;
MovieClip(this.parent).fondo3D.x = 516;
MovieClip(this.parent).fondo3D.y = 177;
MovieClip(this.parent).lampara.x = 520;
MovieClip(this.parent).lampara.y = 180;
MovieClip(this.parent).fondo3D.visible = true;
MovieClip(this.parent).lampara.visible = false;
MovieClip(this.parent).bt_save.visible = false;
var request:URLRequest = new URLRequest("http://www.lampcreator.com/demo/"+ruta);
if(imagenCarga == null) imagenCarga = new Loader();
else imagenCarga.unload();
imagenCarga.contentLoaderInfo.addEventListener(Eve nt.INIT,iniciarPreview);
imagenCarga.load(request);
}
public function loadNewBitmapPreview(ruta:String,t:String){
trans = t;
MovieClip(this.parent).fondo3D.x = 36;
MovieClip(this.parent).fondo3D.y = 27;
MovieClip(this.parent).lampara.x = 40;
MovieClip(this.parent).lampara.y = 30;
MovieClip(this.parent).fondo3D.visible = true;
MovieClip(this.parent).lampara.visible = false;
var request:URLRequest = new URLRequest("http://www.lampcreator.com/demo/"+ruta);
if(imagenCarga == null) imagenCarga = new Loader();
else imagenCarga.unload();
imagenCarga.contentLoaderInfo.addEventListener(Eve nt.INIT,iniciarPreview);
imagenCarga.load(request);
}
public function iniciarPreview(e:Event){
img.bmp.addChild(imagenCarga);
var tmpA:Array = trans.split(",");
img.bmp.x = tmpA[0];
img.bmp.y = tmpA[1];
img.bmp.scaleX = tmpA[2];
img.bmp.scaleY = tmpA[3];
procesaBitmap();
}
public function test3D(e:MouseEvent):void{
this.visible = false;
MovieClip(this.parent).lampara.visible = true;
MovieClip(this.parent).fondo3D.visible = true;
MovieClip(this.parent).lampara.init3D();
}
public function cargaImagen(e:MouseEvent):void{
msg.text = "";
if(imagenCarga) imagenCarga.unload();
var imagesFilter:FileFilter = new FileFilter("Images: JPG, PNG", "*.jpg;*.png");
laImagen = new FileReference();
laImagen.addEventListener(Event.SELECT, elegidaImagen);
//file.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
laImagen.addEventListener(ProgressEvent.PROGRESS, progressHandler);
laImagen.addEventListener(DataEvent.UPLOAD_COMPLET E_DATA, completeHandler);
laImagen.browse([imagesFilter]);
}
function progressHandler(e:ProgressEvent){
elPreloader.visible = true;
var ancho:Number = (e.bytesLoaded * 354)/e.bytesTotal;
elPreloader.progressBar.width = ancho;
}
public function elegidaImagen(e:Event):void{
MovieClip(this.parent).fileName = laImagen.name;
var uploadURL:URLRequest = new URLRequest();
var valueStr:String;
var paramObj:Object = this.loaderInfo.parameters;
valueStr = String(paramObj['phpsessionid']);
uploadURL.url = "http://www.lampcreator.com/demo/grabalamp.php?PHPSESSID="+valueStr+"&id_usuario="+MovieClip(this.parent).idUser;
msg.text = "Uploading Image... Wait";
laImagen.upload(uploadURL);
}
public function completeHandler(e:DataEvent){
elPreloader.visible = false;
var datos:Array = e.data.split("&");
if(datos[0].split("=")[1] == 0) setImagen(datos[1].split("=")[1],datos[2].split("=")[1]);
else trace("Error de comunicacion "+e.data);
}
public function setImagen(ruta:String,id:uint){
msg.text = "Preparing Image... Wait"
imagenRuta = ruta;
imagenId = id;
MovieClip(this.parent).idLampara = id;
var request:URLRequest = new URLRequest("http://www.lampcreator.com/demo/"+ruta);
imagenCarga = new Loader();
imagenCarga.contentLoaderInfo.addEventListener(Eve nt.INIT,iniciarTodo);
imagenCarga.load(request);
}
public function iniciarTodo(e:Event){
msg.text = ""
img.bmp.addChild(imagenCarga);
if(MovieClip(this.parent).editing){
var tmpA:Array = MovieClip(this.parent).editData.trans.split(",");
img.bmp.x = Number(tmpA[0]);
img.bmp.y = Number(tmpA[1]);
img.bmp.scaleX = Number(tmpA[2]);
img.bmp.scaleY = Number(tmpA[3]);
updateSx(img.bmp.scaleX);
updateSy(img.bmp.scaleY);
}
setBotones(true);
setUpEvents();
var moveTimer:Timer=new Timer(30,0);
moveTimer.addEventListener(TimerEvent.TIMER,loop);
moveTimer.start();
}
public function reset(){
msg.text = "Please Load an Image First"
img.bmp.x = 0;
img.bmp.y = 51;
img.bmp.scaleX = 1;
img.bmp.scaleY = 1;
updateSx(img.bmp.scaleX);
updateSy(img.bmp.scaleY);
}
}
}
/*code ends*/
/*code begins*/
package com.xpectral.clips{
import flash.text.TextField;
import flash.events.*;
import flash.events.MouseEvent;
import flash.display.MovieClip;
import flash.display.DisplayObject;
import flash.utils.Timer;
import flash.display.SimpleButton;
import flash.net.FileReference;
import flash.net.URLRequest;
import flash.geom.Matrix;
import flash.geom.Rectangle;
import flash.net.FileFilter;
import flash.display.BitmapData;
import flash.display.Loader;
public class selectorImagen extends MovieClip{
public var movingX:Boolean = false;
public var locked:Boolean = true;
public var laImagen:FileReference;
public var textura:BitmapData;
public var imagenCarga:Loader
public var imagenRuta:String;
public var imagenId:uint;
public var trans:String = "";
public function selectorImagen(){
setBotones(false);
elPreloader.visible = false;
cargador.addEventListener(MouseEvent.CLICK,getBitm ap);
}
public function setBotones(modo:Boolean){
bt_go3D.visible = modo;
sx.visible = modo;
sy.visible = modo;
locker.visible = modo;
}
public function setUpEvents():void{
img.bmp.addEventListener(MouseEvent.MOUSE_DOWN,arr astra);
img.bmp.addEventListener(MouseEvent.MOUSE_UP,para) ;
sx.addEventListener(MouseEvent.MOUSE_DOWN,arrastra Sx);
sx.addEventListener(MouseEvent.MOUSE_UP,para);
sx.addEventListener(MouseEvent.MOUSE_OVER,function (e:MouseEvent){e.target.buttonMode = true;});
sy.addEventListener(MouseEvent.MOUSE_DOWN,arrastra Sy);
sy.addEventListener(MouseEvent.MOUSE_UP,para);
sy.addEventListener(MouseEvent.MOUSE_OVER,function (e:MouseEvent){e.target.buttonMode = true;});
locker.addEventListener(MouseEvent.MOUSE_OVER,func tion(e:MouseEvent){e.target.buttonMode = true;});
locker.addEventListener(MouseEvent.CLICK,setScaleM ode);
//bt_go3D.addEventListener(MouseEvent.CLICK,cargaIma gen);
this.stage.addEventListener(MouseEvent.MOUSE_UP,pa ra);
}
public function arrastra(e:MouseEvent):void{
img.bmp.startDrag();
}
public function arrastraSx(e:MouseEvent):void{
sx.startDrag(false, new Rectangle(44,454,700-11,0));
movingX = true;
}
public function arrastraSy(e:MouseEvent):void{
sy.startDrag(false, new Rectangle(786,156,0,291-11));
movingX = false;
}
public function para(e:MouseEvent):void{
img.bmp.stopDrag();
sx.stopDrag();
sy.stopDrag();
}
public function setScaleMode(e:MouseEvent):void{
if(!locked){
locked = true;
MovieClip(locker).gotoAndStop(1);
}else{
locked = false;
MovieClip(locker).gotoAndStop(2);
}
}
public function loop(e:TimerEvent):void{
var scalaX = Math.max((((sx.x-44)*200)/689)/100,0.05);
var scalaY = Math.max((((sy.y-156)*200)/280)/100,0.05);
if(!locked){
img.bmp.scaleX = scalaX;
img.bmp.scaleY = scalaY;
}else{
if(movingX){
img.bmp.scaleX = img.bmp.scaleY = scalaX;
updateSy(scalaX);
}else{
img.bmp.scaleX = img.bmp.scaleY = scalaY;
updateSx(scalaY);
}
}
}
public function updateSx(s:Number):void{
s = s*50;
sx.x = 44+((s*689)/100);
}
public function updateSy(s:Number):void{
s = s*50;
sy.y = 156+((s*280)/100);
}
public function getBitmap(e:MouseEvent):void{
MovieClip(this.parent).fondo3D.x = 286;
MovieClip(this.parent).fondo3D.y = 177;
MovieClip(this.parent).lampara.x = 290;
MovieClip(this.parent).lampara.y = 100;
trace(MovieClip(this.parent).freeBuy)
if(!MovieClip(this.parent).freeBuy){
MovieClip(this.parent).bt_save.visible = true;
MovieClip(this.parent).bt_save.addEventListener(Mo useEvent.CLICK,MovieClip(this.parent).openSave);
}else{
MovieClip(this.parent).bt_save.visible = false;
MovieClip(this.parent).add_mc.visible = true;
MovieClip(this.parent).add_mc.add_bt.addEventListe ner(MouseEvent.CLICK,MovieClip(this.parent).addCar );
}
procesaBitmap();
}
public function procesaBitmap(){
textura = new BitmapData(700,350,false,0xFEFEFE);
textura.draw(img.bmp,new Matrix(img.bmp.scaleX,0,0,img.bmp.scaleY,img.bmp.x ,img.bmp.y),null,null,new Rectangle(0,-30,700,390));
this.visible = false;
MovieClip(this.parent).fondo3D.visible = true;
MovieClip(this.parent).lampara.visible = true;
if(!MovieClip(this.parent).lampara.iniciado) MovieClip(this.parent).lampara.init3D(textura);
else MovieClip(this.parent).lampara.reInit(textura);
}
public function loadNewBitmap(ruta:String,t:String){
trans = t;
MovieClip(this.parent).fondo3D.x = 516;
MovieClip(this.parent).fondo3D.y = 177;
MovieClip(this.parent).lampara.x = 520;
MovieClip(this.parent).lampara.y = 180;
MovieClip(this.parent).fondo3D.visible = true;
MovieClip(this.parent).lampara.visible = false;
MovieClip(this.parent).bt_save.visible = false;
var request:URLRequest = new URLRequest("http://www.lampcreator.com/demo/"+ruta);
if(imagenCarga == null) imagenCarga = new Loader();
else imagenCarga.unload();
imagenCarga.contentLoaderInfo.addEventListener(Eve nt.INIT,iniciarPreview);
imagenCarga.load(request);
}
public function loadNewBitmapPreview(ruta:String,t:String){
trans = t;
MovieClip(this.parent).fondo3D.x = 36;
MovieClip(this.parent).fondo3D.y = 27;
MovieClip(this.parent).lampara.x = 40;
MovieClip(this.parent).lampara.y = 30;
MovieClip(this.parent).fondo3D.visible = true;
MovieClip(this.parent).lampara.visible = false;
var request:URLRequest = new URLRequest("http://www.lampcreator.com/demo/"+ruta);
if(imagenCarga == null) imagenCarga = new Loader();
else imagenCarga.unload();
imagenCarga.contentLoaderInfo.addEventListener(Eve nt.INIT,iniciarPreview);
imagenCarga.load(request);
}
public function iniciarPreview(e:Event){
img.bmp.addChild(imagenCarga);
var tmpA:Array = trans.split(",");
img.bmp.x = tmpA[0];
img.bmp.y = tmpA[1];
img.bmp.scaleX = tmpA[2];
img.bmp.scaleY = tmpA[3];
procesaBitmap();
}
public function test3D(e:MouseEvent):void{
this.visible = false;
MovieClip(this.parent).lampara.visible = true;
MovieClip(this.parent).fondo3D.visible = true;
MovieClip(this.parent).lampara.init3D();
}
public function cargaImagen(e:MouseEvent):void{
msg.text = "";
if(imagenCarga) imagenCarga.unload();
var imagesFilter:FileFilter = new FileFilter("Images: JPG, PNG", "*.jpg;*.png");
laImagen = new FileReference();
laImagen.addEventListener(Event.SELECT, elegidaImagen);
//file.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
laImagen.addEventListener(ProgressEvent.PROGRESS, progressHandler);
laImagen.addEventListener(DataEvent.UPLOAD_COMPLET E_DATA, completeHandler);
laImagen.browse([imagesFilter]);
}
function progressHandler(e:ProgressEvent){
elPreloader.visible = true;
var ancho:Number = (e.bytesLoaded * 354)/e.bytesTotal;
elPreloader.progressBar.width = ancho;
}
public function elegidaImagen(e:Event):void{
MovieClip(this.parent).fileName = laImagen.name;
var uploadURL:URLRequest = new URLRequest();
var valueStr:String;
var paramObj:Object = this.loaderInfo.parameters;
valueStr = String(paramObj['phpsessionid']);
uploadURL.url = "http://www.lampcreator.com/demo/grabalamp.php?PHPSESSID="+valueStr+"&id_usuario="+MovieClip(this.parent).idUser;
msg.text = "Uploading Image... Wait";
laImagen.upload(uploadURL);
}
public function completeHandler(e:DataEvent){
elPreloader.visible = false;
var datos:Array = e.data.split("&");
if(datos[0].split("=")[1] == 0) setImagen(datos[1].split("=")[1],datos[2].split("=")[1]);
else trace("Error de comunicacion "+e.data);
}
public function setImagen(ruta:String,id:uint){
msg.text = "Preparing Image... Wait"
imagenRuta = ruta;
imagenId = id;
MovieClip(this.parent).idLampara = id;
var request:URLRequest = new URLRequest("http://www.lampcreator.com/demo/"+ruta);
imagenCarga = new Loader();
imagenCarga.contentLoaderInfo.addEventListener(Eve nt.INIT,iniciarTodo);
imagenCarga.load(request);
}
public function iniciarTodo(e:Event){
msg.text = ""
img.bmp.addChild(imagenCarga);
if(MovieClip(this.parent).editing){
var tmpA:Array = MovieClip(this.parent).editData.trans.split(",");
img.bmp.x = Number(tmpA[0]);
img.bmp.y = Number(tmpA[1]);
img.bmp.scaleX = Number(tmpA[2]);
img.bmp.scaleY = Number(tmpA[3]);
updateSx(img.bmp.scaleX);
updateSy(img.bmp.scaleY);
}
setBotones(true);
setUpEvents();
var moveTimer:Timer=new Timer(30,0);
moveTimer.addEventListener(TimerEvent.TIMER,loop);
moveTimer.start();
}
public function reset(){
msg.text = "Please Load an Image First"
img.bmp.x = 0;
img.bmp.y = 51;
img.bmp.scaleX = 1;
img.bmp.scaleY = 1;
updateSx(img.bmp.scaleX);
updateSy(img.bmp.scaleY);
}
}
}
/*code ends*/