有一种简单的方法可以使影片剪辑在Flash中识别自己吗? (AS2) [英] Is there a simple way to make a movie clip identify itself in Flash? (AS2)

查看:335
本文介绍了有一种简单的方法可以使影片剪辑在Flash中识别自己吗? (AS2)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用ActionScript 2.0制作一个非常简单的基于回合的战斗游戏。



我是非常新的代码,只有非常有限的Visual Basic知识,所以我会高兴地承认我不知道我在做什么。我已经有了一个开始,但是我决定重写整个事情,因为我不能轻易地改变敌人和关卡。



我产生了同样的结果敌人两次使用_root.attachMovie,并确定他们为 Enemy1 Enemy2 。在产卵后,我试图让他们认出自己:

  _root.Enemy1.identify =Enemy1
_root.Enemy1.identify =Enemy1

使用调试器,这显然是可行的(在movieclip中,他们有一个变量叫识别哪个正确的标签),但是当我尝试使用if语句,所以我可以把他们在自己的个人立场,它根本不工作;它直接翻过去。我在电影剪辑中的代码是:

$ $ p $ if(identify ==Enemy1){

函数poschange(){

_root.Enemy1._x = _root.Enemy1.POSX;

_root.Enemy1._y = _root.Enemy1.POSY;

_root.Enemy1.swapDepths(_root.Enemy1.POSY);


$ b} else if(identify ==Enemy2){

function poschange(){

_root.Enemy2._x = _root.Enemy2.POSX;

_root.Enemy2._y = _root.Enemy2.POSY;

_root.Enemy2.swapDepths(_root.Enemy2.POSY);




poschange();

poschange函数适用于玩家角色,显然是失败的。

有没有更简单的方法让影片剪辑识别自己的ID,所以我不必使用这个方法,或者是有什么问题我的代码?

解决方案

个人而言,我会远离使用内联函数。我会写一个poschange函数来接受敌人,就像这样,

 函数poschange(enemy){
enemy._x = enemy.POSX;
enemy._y = enemy.POSY;
enemy.swapDepths(enemy.POSY);

$ / code>

你可以从if语句中调用它,如

  if(identify ==Enemy1){
poschange(_root.Enemy1);
}
else if(identify ==Enemy2){
poschange(_root.Enemy2);
}

但是这可能不一定是,也不能解决你的问题。在if语句的时候,你从哪里获得标识属性?如果你是从一个实际的敌对物体得到它,为什么不忘记if语句并运行poschange(curEnemy)或者类似的?


I'm making a very simple turn based battle game using ActionScript 2.0.

I'm VERY new to code, with only very limited Visual Basic knowledge, so I'll happily admit I don't really know what I'm doing. I've got a start, but I decided to rewrite the entire thing because I wouldn't be able to cycle enemies and levels easily.

I've spawned the same enemy twice using _root.attachMovie, and identified them as Enemy1 and Enemy2. After spawning them, I tried to make them identify themselves with:

_root.Enemy1.identify = "Enemy1"
_root.Enemy1.identify = "Enemy1"

Using the debugger, this apparently works (within the movieclip, they have a variable called identify which correctly labels them), yet when I try to use an if statement so I can put them in their own individual positions, it simply does not work; it skims straight over. The code I have within the movie clips is:

 if (identify == "Enemy1") {

    function poschange() {

        _root.Enemy1._x = _root.Enemy1.POSX;

        _root.Enemy1._y = _root.Enemy1.POSY;

        _root.Enemy1.swapDepths(_root.Enemy1.POSY);

    }

} else if (identify == "Enemy2") {

    function poschange() {

        _root.Enemy2._x = _root.Enemy2.POSX;

        _root.Enemy2._y = _root.Enemy2.POSY;

        _root.Enemy2.swapDepths(_root.Enemy2.POSY);

    }

}

poschange();

The poschange functions works fine for the player characters, it's just this if statement to identify which enemy it is apparently fails.

Is there any easier way for a movie clip to identify its own ID so I don't have to use this method, or is there just something wrong with my code?

解决方案

Personally, I'd stay away from using an inline function in that way. I'd write a poschange function that takes in the enemy, like such,

function poschange(enemy) {
    enemy._x = enemy.POSX;
    enemy._y = enemy.POSY;
    enemy.swapDepths(enemy.POSY);
}

And you'd call it from your if statement like,

if (identify == "Enemy1") {
    poschange(_root.Enemy1);
}
else if(identify == "Enemy2") {
    poschange(_root.Enemy2);
}

But that may not necessarily be, nor solve your problem. At the time of the if statement, where are you getting the 'identify' property from? If you're getting it from an actual enemy object, why not forget about the if statement and run poschange(curEnemy), or similar?

这篇关于有一种简单的方法可以使影片剪辑在Flash中识别自己吗? (AS2)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆