0

我有一个带有翻页效果的书的脚本。但是当我从右向左翻转页面时,页面背面的白色是页面正面的反射。你知道你让它变白吗?

    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;
    }
4

1 回答 1

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.
        }
    }
}
于 2013-05-19T18:55:28.133 回答