Skip to main content
Participant
June 8, 2015
Answered

I am trying to code an if statement that allows multiple conditions, but what I have tried will not work.

  • June 8, 2015
  • 1 reply
  • 579 views

This is what I have

if((Knife2.visible=true)&&(Gun2.visible=true)&&(Note2.visible=true)&&(Phone2.visible=true)){

  Next.visible=true

}

I have different click events that makes each of these symbols visible, I want it to recognize when each of these are visible and then show "Next" could somebody please help me with this, its urgent.

This topic has been closed for replies.
Correct answer kglad

your if-statement executes before any of your buttons are clicked.  fix that:

Next01.visible=false

Knife2.visible=false

Gun2.visible=false

Note2.visible=false

Phone2.visible=false

function checkF():void{

if((Knife2.visible==true)&&(Gun2.visible==true)&&(Note2.visible==true)&&(Phone2.visible==t rue) ){

  Next01.visible=true

}

}

Knife.addEventListener(MouseEvent.CLICK, KnifeHide);

function KnifeHide(event:MouseEvent):void

{

  Knife.visible=false;

    Knife2.visible=true

checkF()

}

Gun.addEventListener(MouseEvent.CLICK, GunHide);

function GunHide(event:MouseEvent):void

{

  Gun.visible=false;

    Gun2.visible=true

checkF()

}

Note.addEventListener(MouseEvent.CLICK, NoteHide);

function NoteHide(event:MouseEvent):void

{

  Note.visible=false;

    Note2.visible=true

checkF()

}

Phone.addEventListener(MouseEvent.CLICK, PhoneHide);

function PhoneHide(event:MouseEvent):void

{

  Phone.visible=false;

    Phone2.visible=true

checkF()

}

(p.s when using the adobe forums, please mark helpful/correct responses, if there are any.)

1 reply

kglad
Community Expert
Community Expert
June 8, 2015

use the double equal (==) to test for equality:

drew simpson wrote:

This is what I have

if((Knife2.visible==true)&&(Gun2.visible==true)&&(Note2.visible==true)&&(Phone2.visible==true) ){

  Next.visible=true

}

//or with booleans:

if((Knife2.visible)&&(Gun2.visible&&(Note2.visible)&&(Phone2.visible) ){

  Next.visible=true

}

xXsim00XxAuthor
Participant
June 9, 2015

Unfortunately it doesn't work, il show you my whole code, I am very new to AS.

I have this:

Next01.visible=false

Knife2.visible=false

Gun2.visible=false

Note2.visible=false

Phone2.visible=false

if((Knife2.visible==true)&&(Gun2.visible==true)&&(Note2.visible==true)&&(Phone2.visible==true) ){

  Next01.visible=true

}

Knife.addEventListener(MouseEvent.CLICK, KnifeHide);

function KnifeHide(event:MouseEvent):void

{

  Knife.visible=false;

    Knife2.visible=true

}

Gun.addEventListener(MouseEvent.CLICK, GunHide);

function GunHide(event:MouseEvent):void

{

  Gun.visible=false;

    Gun2.visible=true

}

Note.addEventListener(MouseEvent.CLICK, NoteHide);

function NoteHide(event:MouseEvent):void

{

  Note.visible=false;

    Note2.visible=true

}

Phone.addEventListener(MouseEvent.CLICK, PhoneHide);

function PhoneHide(event:MouseEvent):void

{

  Phone.visible=false;

    Phone2.visible=true

}

I cannot see why it wont work, I click on all the items to show them, but the if statement will not make the "Next01" appear.

kglad
Community Expert
Community Expert
June 9, 2015

Thank you so much for your help!!


you're welcome.