actionscript 3 - AS3 Pageflip effect: Page reversed when flipped -
i have script book page flip effect. when flip page right left, of page insted of white reflex front of page. know make white?
import fl.transitions.tween; import fl.transitions.easing.*; import fl.transitions.tweenevent; import flash.display.sprite; import flash.display.loader; var cont:displayobject; var cont2:displayobject; var imgloader:loader; var pages:array = []; (var i:int=0; i<=4; i++) { imgloader = new loader(); imgloader.contentloaderinfo.addeventlistener(event.init, onloadjpeg); imgloader.load(new urlrequest(""+i+".png")); } var imgloader2:loader; imgloader2 = new loader(); imgloader2.contentloaderinfo.addeventlistener(event.init, onloadsketch); imgloader2.load(new urlrequest("voltaatrassketchbook.png")); function onloadjpeg(e : event):void { cont = e.target.loader;//obter o loader associado ao loaderinfo cont.x = 250; cont.y = 50; cont.width = (445 - 100) / 2; cont.height = (604 - 100) / 2; addchild(cont); cont.addeventlistener(mouseevent.mouse_up, flippage); pages.push(cont); } function onloadsketch(e : event):void { cont2 = e.target.loader;//obter o loader associado ao loaderinfo cont2.x = 450; cont2.y = 300; cont2.width = 181 / 2; cont2.height = 127 / 2; addchild(cont2); cont2.addeventlistener(mouseevent.mouse_up, volta); } function flippage(e:mouseevent):void { setchildindex(displayobject(e.currenttarget), this.numchildren - 1); if (e.currenttarget.rotationy == 0) { var mytween:tween = new tween(e.currenttarget,"rotationy",regular.easeinout,0,180,1,true); } if (e.currenttarget.rotationy == 180) { var mytween:tween = new tween(e.currenttarget,"rotationy",regular.easeinout,180,0,1,true); } } function volta(e: mouseevent):void { gotoandstop(1); (var i:int = 0; < pages.length; i++) { displayobject(pages[i]).visible = false; } cont2.visible = false; }
each page should container contains 2 objects, front , back:
function onloadjpeg(e : event):void { // create container. var page:sprite = new sprite(); page.x = 250; page.y = 50; // create front. var front:loader = e.target.loader front.width = (445 - 100) / 2; front.height = (604 - 100) / 2; // create (a white rectangle). var back:sprite = new sprite(); back.graphics.beginfill(0xffffff); back.graphics.linestyle(); back.graphics.drawrect(0, 0, (445 - 100) / 2, (604 - 100) / 2); back.graphics.endfill(); page.addchild(back); page.addchild(front); addchild(page); page.addeventlistener(mouseevent.mouse_up, flippage); pages.push(page) }
then need check page rotations once every frame, , change index of each page's front or accordingly.
add before function declarations:
addeventlistener(event.enter_frame, enterframelistener);
and add function:
function enterframelistener(e: event):void { for(var i:int = 0; < pages.length; i++) { if(pages[i].rotationy >= 90 && pages[i].rotationy <= 270 && // page underneath front. pages[i].getchildat(0) sprite ) { pages[i].addchild(pages[i].getchildat(0)); // move top. } else if( (pages[i].rotationy < 90 || pages[i].rotationy > 270) && // page front underneath back. pages[i].getchildat(0) loader ) { pages[i].addchild(pages[i].getchildat(0)); // move front top. } } }
Comments
Post a Comment