AS3儿童问题的if语句语句、儿童、问题、if

由网友(风吹沙、蝶恋花)分享简介:好了,有人可以解释什么是错我的code以下,没有错误,但它没有做什么,我想要它做的。予需要它来在屏幕上显示一个movieclip时称为randint变量,它是由随机产生的,大于或等于0.5。如果不是那么它不会显示。 code:的addEventListener(Event.ENTER_FRAME,char_coll);...

好了,有人可以解释什么是错我的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;
            }
        }

    }
};
 
关于c 的if语句嵌套的if与else非法配对问题

那当然,你必须添加 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!

阅读全文

相关推荐

最新文章