我想使用无限滚动AS3我在this SO question讨论。我正在使用FlashCS5 IDE进行开发。通过Actionscript3加载图像两次?
我需要做的绝对最后一件事是在电影的其余部分加载完毕后从外部加载大背景图像(“header_bg_vert.jpg”),而不是要求事先加载整个动画(或者预加载标题动画)。
我的AS3如下。 “无限循环”通过将两个相同的无缝图像端到端地放置两个副本,然后在将第二个图像滚动到屏幕之后移动到前方来工作 - 目前,此代码仅显示图像的一个副本。它出什么问题了?另外,这是完成这个的最好方法吗?
非常感谢。
stop();
//load the bg image
var request:URLRequest = new URLRequest("header_bg_vert.jpg");
var s1:Loader = new Loader();
var s2:Loader = new Loader();
s1.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, loadProgress);
s1.contentLoaderInfo.addEventListener(Event.COMPLETE, loadComplete);
s2.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, loadProgress);
s2.contentLoaderInfo.addEventListener(Event.COMPLETE, loadComplete);
function loadProgress(event:ProgressEvent):void {
var percentLoaded:Number = event.bytesLoaded/event.bytesTotal;
percentLoaded = Math.round(percentLoaded * 100);
trace("Loading: "+percentLoaded+"%");
}
function loadComplete(event:Event):void {
trace("Complete");
}
s1.load(request);
s2.load(request);
//The speed of the scroll movement.
var scrollSpeed:uint = 1;
//Originally, this added two instances of the movie clip onto the stage.
//var s1:ScrollBg = new ScrollBg();
//var s2:ScrollBg = new ScrollBg();
addChild(s1);
addChild(s2);
setChildIndex(s1, 0);
setChildIndex(s2, 0);
//This positions the second movieclip next to the first one.
s1.y = 0;
s2.y = s1.height;
//Adds an event listener to the stage.
stage.addEventListener(Event.ENTER_FRAME, moveScroll);
//This function moves both the images to left. If the first and second
//images goes pass the left stage boundary then it gets moved to
//the other side of the stage.
function moveScroll(e:Event):void{
s1.y -= scrollSpeed;
s2.y -= scrollSpeed;
if(s1.y <= -s1.height){
s1.y = s1.height - scrollSpeed;
}else if(s2.y <= -s2.height){
s2.y = s2.height - scrollSpeed;
}
}
您好,先生,赢得了万亿美元的互联网。这一直在扰乱我至少一个星期。谢谢! – aendrew 2011-02-11 09:14:30