目标是让背景不断循环(侧面滚动式游戏)。我在网上发现了一些代码,它在Flash的“动作”面板中工作,但我被告知我的“动作”面板中没有任何内容,并且我的所有代码都必须在ActionScript文件(.as)中。有没有办法在actionscript文件中而不是在操作窗口中执行此代码?怎么样? - 非常感谢,我真的很感激!
//The speed of the scroll movement.
var scrollSpeed:uint = 2;
//This adds two instances of the movie clip onto the stage.
var s1:ScrollBg = new ScrollBg();
var s2:ScrollBg = new ScrollBg();
addChild(s1);
addChild(s2);
//This positions the second movieclip next to the first one.
s1.x = 0;
s2.x = s1.width;
//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.x -= scrollSpeed;
s2.x -= scrollSpeed;
if(s1.x < -s1.width){
s1.x = s1.width;
}else if(s2.x < -s2.width){
s2.x = s2.width;
}
}
答案 0 :(得分:0)
package {
import flash.display.MovieClip;
import flash.events.Event;
public class Main extends MovieClip{
//The speed of the scroll movement.
var scrollSpeed:uint = 2;
//This adds two instances of the movie clip onto the stage.
var s1:ScrollBg = new ScrollBg();
var s2:ScrollBg = new ScrollBg();
addChild(s1);
addChild(s2);
//This positions the second movieclip next to the first one.
s1.x = 0;
s2.x = s1.width;
//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.x -= scrollSpeed;
s2.x -= scrollSpeed;
if(s1.x < -s1.width){
s1.x = s1.width;
}else if(s2.x < -s2.width){
s2.x = s2.width;
}
}
}
}
更改您拥有的内容并将其作为.as文件保存到主.fla所在的同一文件夹中。
修改强> 另外,请确保在主.fla文件中主类设置为Main.as,如果您不知道它在哪里,那么只需查找它。