Help with two pretty simple pieces ( I think)
Hey guys, been out of the coding loop for quite a bit. Doing a quick proof of concept and have two simple code pieces to put together. Here's what I"m trying to accomplish.
1) mimic a simple parallax webpage, drag up and down to view content
2) have the ability within each content "band" to go left and right if necessary
so here's what I've done:
- built a large parent movieclip called ONEPAYLAYOUT in the code.
- have sub/child movieclips called bands.
- found code to allow me to scroll up and down
1) so with the code from a tutorial, it does what I need for the scrolling but for some reason, right when you launch it jumps down to band 2. I have no clue why. Band 1 is perfectly aligned with the stage, so it should launch and just stay put. So I don't know if anyone can see in the code below why it does some auto adjustment. My code is below, hope someone can see the issue.
2) a future direction helper. If I put a button in somehting like band 2 to have a trigger for band 2 to go to it's second keyframe, a different picture. I know that with the event listener on the main parent movieclip it does not work or pick up the click of a child/nested movieclilp. I know this has to have been done a million times because I see it all over the web and in apps. Any ideas?
import flash.events.MouseEvent;
import flash.geom.Point;
import flash.events.Event;
import flash.geom.Rectangle;
var destination:Point=new Point();
var dragging:Boolean=false;
var speed:Number=5;
var offset:Point=new Point(); // our offset
ONEPAGELAYOUT.addEventListener(MouseEvent.MOUSE_DOWN,startdrag);
stage.addEventListener(MouseEvent.MOUSE_UP,stopdrag);
ONEPAGELAYOUT.addEventListener(Event.ENTER_FRAME,followmouse);
var bounds:Rectangle=new Rectangle(0,719.95,stage.stageWidth,stage.stageHeight);
function followmouse(e:Event):void{
if(dragging){
destination.y=mouseY;
}
ONEPAGELAYOUT.y-=(ONEPAGELAYOUT.y-(destination.y-offset.y))/speed;
if(ONEPAGELAYOUT.y>bounds.top){
ONEPAGELAYOUT.y=bounds.top;
}
if(ONEPAGELAYOUT.y<-ONEPAGELAYOUT.height+bounds.bottom){
ONEPAGELAYOUT.y=-ONEPAGELAYOUT.height+bounds.bottom;
}
}
function startdrag(e:MouseEvent):void{
offset.y=ONEPAGELAYOUT.mouseY*ONEPAGELAYOUT.scaleY;
dragging=true;
}
function stopdrag(e:MouseEvent):void{
dragging=false;
}
