Banyak cara dalam membuat scroll
pada actionscript
di flash , nah pada pembahasan Flash scroll as3 Part 1 kali ini Pustaka flash
coba memberikan salahsatu contoh dengan efek Mask
script yang digunakan
var scrollHeight:Number = scrollTrk.height;
var contentHeight:Number = contentMain.height;
var scrollFaceHeight:Number = scrollFace.height;
var maskHeight:Number = maskedView.height;
var initPosition:Number = scrollFace.y=scrollTrk.y;
var initContentPos:Number = contentMain.y;
var finalContentPos:Number = maskHeight-contentHeight+initContentPos;
var left:Number = scrollTrk.x;
var top:Number = scrollTrk.y;
var right:Number = 0;
var bottom:Number = scrollTrk.height-scrollFaceHeight;
var bottom2:Number = scrollTrk.height-scrollFaceHeight+scrollTrk.y;
var dy:Number = 0;
var speed:Number = 10;
var moveVal:Number = (contentHeight-maskHeight)/(scrollHeight-scrollFaceHeight);
var currPos:Number
var rect1:Rectangle = new Rectangle(left,top,right,bottom)
scrollFace.addEventListener(MouseEvent.MOUSE_DOWN, scrollMouseDown)
scrollFace.addEventListener(MouseEvent.MOUSE_UP, scrollMouseUp)
tombolatas.addEventListener(MouseEvent.MOUSE_DOWN, btnUpPress)
tombolatas.addEventListener(MouseEvent.MOUSE_UP, btnUpRelease)
tombolatas.addEventListener(MouseEvent.MOUSE_OUT, btnUpOut)
tombolbawah.addEventListener(MouseEvent.MOUSE_DOWN, btnDownPress)
tombolbawah.addEventListener(MouseEvent.MOUSE_UP, btnDownRelease)
tombolbawah.addEventListener(MouseEvent.MOUSE_OUT, btnDownOut)
function scrollMouseDown(event:MouseEvent) {
currPos = this.scrollFace.y;
scrollFace.startDrag(false, rect1)
scrollFace.addEventListener(Event.ENTER_FRAME, scrollMove)
stage.addEventListener(MouseEvent.MOUSE_UP, releaseOut)
};
function scrollMove(event:Event) {
dy = Math.abs(initPosition-scrollFace.y);
contentMain.y = Math.round(dy*-1*moveVal+initContentPos);
};
function scrollMouseUp(event:MouseEvent) {
scrollFace.stopDrag();
scrollFace.removeEventListener(Event.ENTER_FRAME, scrollMove)
};
function releaseOut(event:MouseEvent) {
if (event.target == scrollFace){
}else{
scrollFace.stopDrag();
scrollFace.removeEventListener(Event.ENTER_FRAME, scrollMove)
}
stage.removeEventListener(MouseEvent.MOUSE_UP, releaseOut);
};
function btnUpPress(event:MouseEvent) {
tombolatas.addEventListener(Event.ENTER_FRAME, btnUpEnterFrame)
};
function btnUpEnterFrame(event:Event) {
if (contentMain.y>=initContentPos ||scrollFace.y<=top){
scrollFace.y = top;
}else{
scrollFace.y -= speed/moveVal;
contentMain.y += speed;
}
};
function btnUpRelease(event:MouseEvent) {
tombolatas.removeEventListener(Event.ENTER_FRAME, btnUpEnterFrame)
};
function btnUpOut(event:MouseEvent) {
tombolatas.removeEventListener(Event.ENTER_FRAME, btnUpEnterFrame)
};
function btnDownPress(event:MouseEvent) {
tombolbawah.addEventListener(Event.ENTER_FRAME, btnDownEnterFrame)
}
function btnDownEnterFrame(event:Event) {
if (contentMain.y<=finalContentPos ||scrollFace.y>=bottom){
scrollFace.y = bottom2;
}else{
scrollFace.y += speed/moveVal;
contentMain.y -= speed;
}
};
function btnDownRelease(event:MouseEvent) {
tombolbawah.removeEventListener(Event.ENTER_FRAME, btnDownEnterFrame)
};
function btnDownOut(event:MouseEvent) {
tombolbawah.removeEventListener(Event.ENTER_FRAME, btnDownEnterFrame)
};
if (contentHeight<maskHeight) {
scrollFace.visible = false;
tombolatas.enabled = false;
tombolbawah.enabled = false;
} else {
scrollFace.visible = true;
tombolatas.enabled = true;
tombolbawah.enabled = true;
}
Download
Flash scroll as3 Part 1 source code nya disini
artikel tentang
Flash scroll as3 Part 1 disusun oleh Ricko nada
di Pustaka Flash
0 komentar:
Post a Comment