AS3儿童问题的if语句 [英] AS3 child issue with if statements

查看:109
本文介绍了AS3儿童问题的if语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好了,有人可以解释什么是错我的code以下,没有错误,但它没有做什么,我想要它做的。予需要它来在屏幕上显示一个movieclip时称为randint变量,它是由随机产生的,大于或等于0.5。如果不是那么它不会显示。 code:

 的addEventListener(Event.ENTER_FRAME,char_coll);
功能char_coll(EV:事件):无效
{
    如果(currentFrame == 2)
    {
        如果(randint&GT = 0.5){
            VAR W1:woman1 =新woman1();
            randint =的Math.random();
            如果(w1.hitTestObject(支架)){
                w1.gotoAndPlay(1);
                cash1 = cash1 + 1;
        }
        }

    }
};
 

解决方案

randint 设置if语句中。这意味着 randint 总是undefiend,因为它必须是> = 0.5 设置为任意值(样一个catch 22)。

这code应该工作:

 的addEventListener(Event.ENTER_FRAME,char_coll);
功能char_coll(EV:事件):无效
{
    如果(currentFrame == 2)
    {
        VAR randint:数=的Math.random();
        如果(randint&GT = 0.5){
            VAR W1:woman1 =新woman1();
            stage.addChild(W1);
            如果(w1.hitTestObject(支架)){
                w1.gotoAndPlay(1);
                cash1 = cash1 + 1;
            }
        }

    }
};
 

那当然,你必须添加 W1 的addChild()阶段使用,您可以参见下面的变种 W1:woman1 =新woman1();

希望它能帮助!

Alright, can someone explain what is wrong with my code below, there is no errors, but it's not doing what I want it to do. I need it to display a movieclip on the screen when a variable called "randint", which is generated by random, is greater than or equal to 0.5. If it's not then it doesn't get displayed. Code:

addEventListener(Event.ENTER_FRAME, char_coll);
function char_coll(ev : Event) : void
{
    if(currentFrame==2)
    {
        if (randint >= 0.5){
            var w1:woman1 = new woman1();
            randint = Math.random();
            if(w1.hitTestObject(stand)){
                w1.gotoAndPlay(1);
                cash1 = cash1 + 1;
        }
        }

    }
};

解决方案

randint is set inside the if statement. This means that randint always is undefiend, because it has to be >= 0.5 to be set to any value (kind of a catch 22).

This code should work:

addEventListener(Event.ENTER_FRAME, char_coll);
function char_coll(ev : Event) : void
{
    if(currentFrame==2)
    {
        var randint:Number = Math.random();
        if (randint >= 0.5){
            var w1:woman1 = new woman1();
            stage.addChild(w1);
            if(w1.hitTestObject(stand)){
                w1.gotoAndPlay(1);
                cash1 = cash1 + 1;
            }
        }

    }
};

Then of course you have to add w1 to the stage using addChild() as you can se below var w1:woman1 = new woman1();

hope it helps!

这篇关于AS3儿童问题的if语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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