Skip to main content
Inspiring
August 2, 2013
Answered

A question about conditional if

  • August 2, 2013
  • 1 reply
  • 777 views

Hi guys

I have a function that checks if something is happening before keep on going...

Now, my question is, if I want it to check 3 conditions, instead of one only, how do I have to code it?

Here is what I have:

function hRelease(event:MouseEvent):void {

    var item5:MovieClip=letritaH(event.target);

    item5.stopDrag();      

    if (targeth.hitTestPoint(item5.x,item5.y)) {

        item5.x=targeth.x;

        item5.y=targeth.y;

        myTween.stop();

        addChild (flecha2);

        var t1:Timer=new Timer(1000,1);

        t1.addEventListener(TimerEvent.TIMER,removeFl);

        t1.start();

        function removeFl(e:TimerEvent):void{

        if (flecha2.parent) {

            flecha2.parent.removeChild(flecha2);}

        }

    } else {

       item5.x=276;

       item5.y=(stage.stageHeight - 100);

    }

}

and what I want to do is: before the "myTween.stop();" I want it to check if i.x=273, letrao.x=447, and letral.x=575,50

Thanks once again for all your help

This topic has been closed for replies.
Correct answer Ned Murphy

To check all three in one conditional you would use:

   if(i.x == 273 && letrao.x == 447 && letral.x == 575){

Two other things...

1) you should not nest named functions within other functions

2) Within that function that you are nesting, you are testing if an object has a parent using...

  

       if (flecha2.parent) {

IF fletcha2 is an object in the timeline such that you can target it that way, that timeline is the parent, so there is no need to test for its parent, nor do you need to target its parent to remove it.  YOu can just target fletcha2 directly to test for its existence and to remove it.

1 reply

Ned Murphy
Ned MurphyCorrect answer
Legend
August 2, 2013

To check all three in one conditional you would use:

   if(i.x == 273 && letrao.x == 447 && letral.x == 575){

Two other things...

1) you should not nest named functions within other functions

2) Within that function that you are nesting, you are testing if an object has a parent using...

  

       if (flecha2.parent) {

IF fletcha2 is an object in the timeline such that you can target it that way, that timeline is the parent, so there is no need to test for its parent, nor do you need to target its parent to remove it.  YOu can just target fletcha2 directly to test for its existence and to remove it.

SirMarleyAuthor
Inspiring
August 3, 2013

Great!!!!

I did as you said and it is working fine.

Let me ask you, to better understand:

1) Why should not I put one function inside another?

2) Before I asked here, I tried to define that if myself, but writing one = instead of two == ... what is the meaning of = and ==?

By the way, thanks a lot!!!!

Ned Murphy
Legend
August 3, 2013

You're welcome

1) The non-technical answer - It can mess up the scope of things, leading to problems that have you scratching your head and going cross-eyed wondering what could be wrong.

2)  =     assigns a value to whatever precedes it.

     ==   compares the equality of two values