Hey!
I have a picture gallery and I’m trying to figure out how to bring on the next picture when dragging the one currently on the screen off of the screen to the left. I have code written out that works to load the picture and then you can select the picture and drag and throw it off screen. But I cant get the second picture to load successfully and move onto the screen with the motion of the first picture.
I have posted my code here but you may not need to look at it…
I appreciate any help!
//Loads picture:
private function loadPic(e:Event = null):void {
rawImage = imgData.image[imgNum].imgURL;
lastImageIndex = imgData.*.length() - 1;
imageLoaderHost = new MovieClip();
imageLoaderHost.alpha = 0;
imageLoader = new Loader();
imageLoader.load(new URLRequest(rawImage));
if (iNum == 1) {
imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, placePic);
} else if (iNum == 2) {
imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, placePic2);
} else {
imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, placePicBack);
}
frame = new Sprite();
frame.graphics.lineStyle(3, 0x000000, 100, false, LineScaleMode.NORMAL, CapsStyle.NONE, JointStyle.MITER);
frame.graphics.drawRect(1, 0, 792, 534);
imageLoaderHost.addChild(imageLoader);
imageLoaderHost.addChild(frame);
master_mc.addChild(imageLoaderHost);
}
private function placePic(event:Event):void {
imageLoader.contentLoaderInfo.removeEventListener(Event.COMPLETE, placePic);
imageReflect = new Reflect({mc:imageLoaderHost, alpha:30, ratio:90, distance:-2, updateTime:-1, reflectionDropoff:2});
imageLoaderHost.x = xPos;
TweenMax.to(imageLoaderHost, 1, {alpha:1, ease:Quad.easeInOut});
imageLoaderHost.addEventListener(MouseEvent.MOUSE_DOWN, onMouseD);
}
private function placePic2(event:Event):void {
imageLoaderHost.alpha = 1;
imageLoader.contentLoaderInfo.removeEventListener(Event.COMPLETE, placePic2);
imageLoaderHost.x = 1624;
placeReflection();
}
private function placeReflection():void {
imageReflect = new Reflect({mc:imageLoaderHost, alpha:30, ratio:90, distance:-2, updateTime:-1, reflectionDropoff:2});
//imageLoaderHost.addEventListener(MouseEvent.MOUSE_DOWN, onMouseD);
}
private function onMouseD(event:MouseEvent):void {
trace("MOUSE DOWN");
oldX =imageLoaderHost.x;
stage.addEventListener(MouseEvent.MOUSE_UP, onMouseU);
imageLoaderHost.startDrag(false, new Rectangle(-800, imageLoaderHost.y, 2280, 0));
addEventListener(Event.ENTER_FRAME, trackVelocity);
}
private function trackVelocity(event:Event):void {
trace("TRACK VELOCITY");
vx = imageLoaderHost.x - oldX;
oldX = imageLoaderHost.x;
}
private function onMouseU(event:MouseEvent):void {
trace("MOUSE UP");
stage.removeEventListener(MouseEvent.MOUSE_UP, onMouseU);
imageLoaderHost.stopDrag();
removeEventListener(Event.ENTER_FRAME, trackVelocity);
addEventListener(Event.ENTER_FRAME, onEnterframe);
imgNum = imgNum < lastImageIndex ? imgNum + 1:0;
iNum = 2;
//loadPic(); // this is giving problem because when next pics loaded it stops animating first pic and consentrates on second pic
clearIntervals();
}
private function placePicBack(event:Event):void {
imageLoaderHost.alpha = 1;
imageLoader.contentLoaderInfo.removeEventListener(Event.COMPLETE, placePicBack);
imageLoaderHost.x = -1000;
placeReflection();
}
private function onEnterframe(event:Event):void {
trace("ENTER FRAME");
imageLoaderHost.x += vx;
var left:Number = 0;
var right:Number = stage.stageWidth;
if(imageLoaderHost.x <= -800){
trace("enterframe ended left");
removeEventListener(Event.ENTER_FRAME, onEnterframe);
//TweenMax.to(imageLoaderHost, .8, {x:-1000, ease:Quad.easeOut});
}else if(imageLoaderHost.x >= 1300){
trace("enterframe ended right");
removeEventListener(Event.ENTER_FRAME, onEnterframe);
}
}