Estoy tratando de modificar un AS 3 de una galeria de fotos de tipo muero en 3D
EL tema es que cuando apreto una imagen, para que me haga zoom, al volver apretarlo es como que guardo el valor del zoom que se hizo la ultima vez y suma nuevamente ese valor entonces hace el doble de zoom, osea si hago varios clicks las imagenes desaparecen del campo de vision. Nose que estará mal en el código en la parte de function imagepress. tambien me gustaria que se movieran las imagenes solo cuando apreto el mouse y no cuando muevo el mouse sobre la pantalla, osea que solo se despacen onMouseClick y no onMouseOver pero nose que parte debo modificar
Código PHP:
stop();
import fl.transitions.Tween;
import fl.transitions.easing.*;
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.display.*;
import flash.events.Event;
import flash.display.Shape;
import flash.display.MovieClip;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.DisplayObject;
import flash.display.Loader;
import flash.events.Event;
import flash.geom.Point;
import flash.net.URLRequest;
import flash.net.URLLoader;
import flash.geom.ColorTransform;
import gs.*;
import org.papervision3d.scenes.*;
import org.papervision3d.cameras.*;
import org.papervision3d.objects.*;
import org.papervision3d.materials.*;
import org.papervision3d.materials.BitmapMaterial;
import org.papervision3d.view.BasicView;
import org.papervision3d.objects.primitives.Plane;
var container:Sprite = new Sprite();
container.x = 0;
container.y = 0;
addChild(container);
var scene:Scene3D = new MovieScene3D(container);
var cam:FreeCamera3D = new FreeCamera3D();
var new_zoom:Number;
cam.zoom = 1;
var planedictionary:Dictionary = new Dictionary(true);
var maxRows:Number = 3;
var yaxis:Number = 0;
var anglenumber:Number = 100;
var image = new Array();
var planes = new Array();
var reflectionplanes = new Array();
var i:Number;
var max:Number;
var li:Number = 0;
var center:Number = 6.4;
var zoom:Number = 10;
var zoomdistance:Number = 17;
var cameramove:Boolean = true;
var camerapositionX:Number;
var camerapositionY:Number;
var showimage:Boolean = true;
var imageholder;
var xposition:Number;
var yposition:Number;
var imagewidth:Number = 140;
var imageheight:Number = 105;
var imagewidthdistance:Number = imagewidth + 10;
var imageheightdistance:Number = imageheight + 10;
var reflectionplane:Boolean = true;
var imageglowholder;
var imageglow:Boolean = true;
var loadimagedata:Loader;
var displayimage:Number;
var ycamposition:Number;
var xcamposition:Number;
var zcamposition:Number;
var counter:Number = 0;
var XML_Load:XML = new XML();
var loader:URLLoader = new URLLoader();
loader.load(new URLRequest("imagenes.xml"));
loader.addEventListener(Event.COMPLETE, init);
function init(e:Event):void {
XML_Load = XML(loader.data);
max = XML_Load.data.length();
loaddata("fotos/" + XML_Load.data[counter].@imagepath);
image.push(XML_Load.data[counter].@imagepath.toString());
var displayimage:Number = Math.ceil(max/3);
};
function loaddata(loadedimage:String) {
loadimagedata = new Loader();
loadimagedata.contentLoaderInfo.addEventListener(Event.COMPLETE, loaded);
loadimagedata.load(new URLRequest(loadedimage));
};
function loaded(e:Event) {
var bmd:BitmapData = Bitmap(loadimagedata.content).bitmapData;
var bm:BitmapMaterial = new BitmapMaterial(bmd);
bm.oneSide = true;
bm.smooth = true;
var plane:Plane = new Plane(bm, imagewidth, imageheight, 2, 2);
scene.addChild(plane);
planes.push(plane);
var planeMC:Sprite = plane.container;
planeMC.name = "" + counter;
planedictionary[planeMC] = plane;
planeMC.buttonMode = true;
planeMC.addEventListener(MouseEvent.ROLL_OVER, imagerollover);
planeMC.addEventListener(MouseEvent.ROLL_OUT, imagerollout);
planeMC.addEventListener(MouseEvent.CLICK, imagepress);
camerapositionX = ((imagewidthdistance * Math.ceil(max/3)) - imagewidthdistance) * 0.5;
camerapositionY = ((imageheightdistance * maxRows) - imageheightdistance) * 0.5;
if(reflectionplane == true) {
var bmdReflection:BitmapData = new BitmapData(bmd.width, bmd.height * 2, false, 0);
bmdReflection.draw(bmd);
var alpha:Number = 1.0;
var flipMatrix:Matrix = new Matrix(1, 0, 0, -1, 0, bmd.height);
bmdReflection.draw(bmd, flipMatrix, new ColorTransform(alpha, alpha, alpha, 1, 0, 0, 0, 0));
var holder:Shape = new Shape();
var gradientMatrix:Matrix = new Matrix();
gradientMatrix.createGradientBox(bmd.width, bmd.height, Math.PI/2);
holder.graphics.beginGradientFill(GradientType.LINEAR, [0x000000, 0x000000], [0.8, 1], [0x00, 0xFF], gradientMatrix);
holder.graphics.drawRect(0, 0, bmd.width, bmd.height * 2);
holder.graphics.endFill();
var m:Matrix = new Matrix();
m.translate(0, 0);
bmdReflection.draw(holder, m);
var ReflectionMaterial = new BitmapMaterial(bmdReflection);
ReflectionMaterial.smooth = true;
var planereflection:Plane = new Plane(ReflectionMaterial, imagewidth, imageheight * 2, 4, 4);
scene.addChild(planereflection);
planereflection.x = li * imagewidthdistance - camerapositionX;
planereflection.y = -320;
reflectionplanes.push(planereflection);
var planeReflect:Sprite = planereflection.container;
planeReflect.name = "" + counter;
planedictionary[planeReflect] = planereflection;
planeReflect.alpha = 1.0;
}
plane.x = li * imagewidthdistance - camerapositionX;
li++;
plane.y = yaxis - camerapositionY - imageheight * 0.5 + 5;
if((counter+1) % Math.ceil(max/3) == 0) {
reflectionplane = false;
li = 0;
yaxis += imageheightdistance;
}
counter++;
(counter < max) ? loaddata("fotos/" + XML_Load.data[counter].@imagepath) : null;
};
function imagerollover(e:MouseEvent) {
var imagesprite:Sprite = e.target as Sprite;
if(showimage == true) {
}
};
function imagerollout(e:MouseEvent) {
var imagesprite:Sprite = e.target as Sprite;
if(showimage == true) {
}
};
function imagepress(e:MouseEvent) {
var imagesprite:Sprite = e.target as Sprite;
if(showimage == true) {
showimage = false;
imageholder = imagesprite.name;
imageglowholder = imagesprite;
xposition = planes[imagesprite.name].x;
yposition = planes[imagesprite.name].y;
ycamposition = cam.y;
xcamposition = cam.x;
zcamposition = cam.z;
if(imageglow == true) {
TweenMax.to(imagesprite, 1, {glowFilter:{color:0xFFFFFF, alpha:1.0, blurX:8, blurY:8, strength:5}});
}
TweenMax.to(planes[imagesprite.name], 1, {z: -250});
TweenMax.to(reflectionplanes[imagesprite.name], 1, {z: -250});
TweenMax.to(cam, 2, {x:xposition, y:yposition, z:zcamposition+350, rotationY:0});
}
else {
if(planes[imagesprite.name] == planes[imageholder]) {
TweenMax.to(planes[imageholder], 1, {z: 0});
TweenMax.to(reflectionplanes[imageholder], 1, {z: 0});
TweenMax.to(cam, 2, {x:xcamposition, y:ycamposition, z:zcamposition, rotationY:0});
imagesprite["filters"] = null;
showimage = true;
}
if(planes[imagesprite.name] != planes[imageholder]) {
TweenMax.to(planes[imageholder], 1, {z: 0});
TweenMax.to(reflectionplanes[imageholder], 1, {z: 0});
imageglowholder["filters"] = null;
imageholder = imagesprite.name;
imageglowholder = imagesprite;
xposition = planes[imagesprite.name].x;
yposition = planes[imagesprite.name].y;
if(imageglow == true) {
TweenMax.to(imagesprite, 1, {glowFilter:{color:0xFFFFFF, alpha:1.0, blurX:8, blurY:8, strength:5}});
}
TweenMax.to(planes[imagesprite.name], 1, {z: -250});
TweenMax.to(reflectionplanes[imagesprite.name], 1, {z: -250});
TweenMax.to(cam, 2, {x:xposition, y:yposition, z:zcamposition+350, rotationY:0});
}
}
};
cam.z = -stage.stageHeight * 4/3;
cam.y = -(imageheight*3+10*(3-1))/2+120;
cam.extra = {x:100, ry:100, y:-(imageheight*3+10*(3-1))/2+120};
stage.addEventListener(MouseEvent.MOUSE_WHEEL, CameraZoom);
function CameraZoom(e:MouseEvent) {
var newzoom:Number = zoomdistance + e.delta/5;
if(newzoom < 3) {
newzoom = 3;
}
if(newzoom > 18) {
newzoom = 18;
}
zoomdistance = newzoom;
};
addEventListener(Event.ENTER_FRAME, render);
function render(e:Event):void {
if(showimage == true) {
var position:Number = stage.mouseX/stage.stageWidth * 2-1;
cam.extra.ry = position * -10;
cam.extra.x += position * -10;
if(cam.extra.x < 0 - (camerapositionX - imagewidthdistance)) {
cam.extra.ry = 0;
cam.extra.x = 0 - (camerapositionX - imagewidthdistance);
}
if(cam.extra.x > 0 + (camerapositionX - imagewidthdistance)) {
cam.extra.ry = 0;
cam.extra.x = 0 + (camerapositionX - imagewidthdistance);
}
cam.x += (cam.extra.x - cam.x)/5;
cam.rotationY += (cam.extra.ry - cam.rotationY)/8;
}
cam.zoom += (zoomdistance-cam.zoom)/5;
scene.renderCamera(cam);
};