2013-05-19 36 views
0

我有一個具有翻頁效果的書的腳本。但是當我從右向左翻頁時,頁面背面的白色是頁面前面的反射。你知道你讓它變成白色嗎?AS3 Pageflip特效:翻頁時翻頁

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 = []; 

for (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); 
     for (var i:int = 0; i < pages.length; i++) 
     { 
      DisplayObject(pages[i]).visible = false; 
     } 
     cont2.visible = false; 
    } 

回答

0

每個頁面應該是包含兩個對象,在正面和背面的容器:

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 back (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) 
} 

然後,你需要檢查頁面輪換一次架,並改變每個頁面的索引正面或背面相應。

你的函數聲明之前,補充一點:

addEventListener(Event.ENTER_FRAME, enterFrameListener); 

並添加此功能:

function enterFrameListener(e: Event):void { 
    for(var i:int = 0; i < pages.length; i++) { 
     if(pages[i].rotationY >= 90 && 
      pages[i].rotationY <= 270 && 
      // the page back is underneath the front. 
      pages[i].getChildAt(0) is Sprite 
     ) { 
      pages[i].addChild(pages[i].getChildAt(0)); // Move the back to the top. 
     } else if(
      (pages[i].rotationY < 90 || pages[i].rotationY > 270) && 
      // the page front is underneath the back. 
      pages[i].getChildAt(0) is Loader 
     ) { 
      pages[i].addChild(pages[i].getChildAt(0)); // Move the front to the top. 
     } 
    } 
} 
+0

它的工作,非常感謝你,我不知道該怎麼感謝你! – user2397976