Actionscript 3 AS3页面翻转效果:翻转时页面反转
我有一本带有翻页效果的书的脚本。但当我从右向左翻转页面时,页面的背面不是白色,而是页面正面的反射。你知道你要把它变成白色吗Actionscript 3 AS3页面翻转效果:翻转时页面反转,actionscript-3,rotation,tween,Actionscript 3,Rotation,Tween,我有一本带有翻页效果的书的脚本。但当我从右向左翻转页面时,页面的背面不是白色,而是页面正面的反射。你知道你要把它变成白色吗 import fl.transitions.Tween; import fl.transitions.easing.*; import fl.transitions.TweenEvent; import flash.display.Sprite; import flash.display.Loader; var cont:D
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;
}
导入fl.transitions.Tween;
导入fl.transitions.easing.*;
导入fl.transitions.TweenEvent;
导入flash.display.Sprite;
导入flash.display.Loader;
var cont:显示对象;
var cont2:显示对象;
var imgLoader:装载机;
变量页:数组=[];
对于(var i:int=0;i每个页面都应该是一个包含两个对象的容器,前面和后面:
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.
}
}
}
函数enterFrameListener(e:事件):无效{
对于(变量i:int=0;i=90&&
第[i]页。旋转270)&&
//首页在后面的下面。
页面[i]。getChildAt(0)是加载程序
) {
pages[i].addChild(pages[i].getChildAt(0));//将前面移到顶部。
}
}
}
成功了,非常感谢,我都不知道该如何感谢你!!