[英]Actionscript in timeline not working as intended
I had some AS3 code that I wanted to move to the timeline rather than having an external file but it's not working at all, whereas it did in the .as file: 我有一些AS3代码,我想移至时间线,而不要使用外部文件,但它根本无法工作,而在.as文件中却可以:
public class EnemyShip extends MovieClip
{
var speed:Number;
var shot = new ShotSound();
function EnemyShip()
{
this.x = 800;
this.y = Math.random() * 275 + 75;
speed = Math.random()*5 + 9;
addEventListener("enterFrame", enterFrame);
addEventListener(MouseEvent.MOUSE_DOWN, mouseShoot);
}
function enterFrame(e:Event)
{
this.x -= speed;
if(this.x < -100)
{
removeEventListener("enterFrame", enterFrame);
Main.gameLayer.removeChild(this);
}
}
function kill()
{
var explosion = new Explosion();
Main.gameLayer.addChild(explosion);
explosion.x = this.x;
explosion.y = this.y;
removeEventListener("enterFrame", enterFrame);
Main.gameLayer.removeChild(this);
Main.updateScore(1);
shot.play();
}
function mouseShoot(event:MouseEvent)
{
kill();
}
That is the code and I've tried adapting it to work in the timeline but nothing happens. 那是代码,我尝试过对其进行修改以使其在时间轴上工作,但是什么也没有发生。 I tried adding the code to the EnemyShip
movieclip itself as well as adding it to the in game scene but it doesn't work. 我尝试将代码添加到EnemyShip
影片剪辑本身,以及将其添加到游戏场景中,但是它不起作用。 Any suggestions? 有什么建议么?
This is a bit sad, using an external class is a cleaner way to do things, but you decide. 这有点令人难过,使用外部类是做事的一种更干净的方法,但是您可以决定。
Remove every class wrapper and put this code on the first frame of your symbol: 删除每个类包装,并将此代码放在符号的第一帧上:
var speed:Number;
var shot = new ShotSound();
this.x = 800;
this.y = Math.random() * 275 + 75;
speed = Math.random()*5 + 9;
addEventListener("enterFrame", enterFrame);
addEventListener(MouseEvent.MOUSE_DOWN, mouseShoot);
function enterFrame(e:Event)
{
this.x -= speed;
if(this.x < -100)
{
removeEventListener("enterFrame", enterFrame);
Main.gameLayer.removeChild(this);
}
}
function kill()
{
var explosion = new Explosion();
Main.gameLayer.addChild(explosion);
explosion.x = this.x;
explosion.y = this.y;
removeEventListener("enterFrame", enterFrame);
Main.gameLayer.removeChild(this);
Main.updateScore(1);
shot.play();
}
function mouseShoot(event:MouseEvent)
{
kill();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.