Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 06-10-2012, 05:44 PM   #1
NgemeO
Registered User
 
Join Date: Sep 2011
Posts: 5
Default How can I make a button do multiple things?

Hello guys. I'm bad at AS and I'm looking for a solution to my problem. Yes, I am an if-sentence spammer.

ActionScript Code:
function button_1 (evt:MouseEvent){     if (place1.selectedItem.label == "New York");     if (place2.selectedItem.label == "London");     if (ticket.selectedItem.label == "English");     gotoAndStop(3);                 if (place1.selectedItem.label == "London");     if (place2.selectedItem.label == "New York");     if (ticket.selectedItem.label == "English");     gotoAndStop(4)         }

How do I differentiate between the two paragraphs? Or will I have to solve it in another way?
NgemeO is offline   Reply With Quote
Old 06-10-2012, 07:37 PM   #2
henke37
Senior Member
 
henke37's Avatar
 
Join Date: Mar 2009
Location: Sweden
Posts: 10,886
Send a message via Skype™ to henke37
Default

Use the boolean and operator.
__________________
Signature: I wrote a pair of articles about the timeline.
henke37 is offline   Reply With Quote
Old 06-10-2012, 07:50 PM   #3
NgemeO
Registered User
 
Join Date: Sep 2011
Posts: 5
Default

Quote:
Originally Posted by henke37 View Post
Use the boolean and operator.
Hi! Thanks for reply.
Can you give an example?
NgemeO is offline   Reply With Quote
Old 06-10-2012, 08:38 PM   #4
NgemeO
Registered User
 
Join Date: Sep 2011
Posts: 5
Default

I really need help guys. If I don't figure this out I'm probably going to fail my test. I've been on this all day and haven't figured out a solution
NgemeO is offline   Reply With Quote
Old 06-10-2012, 10:13 PM   #5
iamgotenks
Super Saiyan
 
iamgotenks's Avatar
 
Join Date: Nov 2011
Location: New Zealand
Posts: 345
Default

ok, well, there is a lot you can learn here about boolean equations, but I'll just do the simple stuff for ya

&& means 'and',
|| means 'or'.
> greater than
>= greater or equal to
< less than
<= less than or equal to
!= not equal to

with boolean operations, you can also use brackets to make it more readable and help with grouping equations (which is very helpful when learning - I'll use excessive brackets so it's more clear what's happening)

basically, the if statement needs a (boolean) "true" value to execute.

so;

ActionScript Code:
if ( true ) {     trace("this will execute every time"); } if ( false ) {     trace("this will never execute, ever"); }
so, we just basically work out our boolean equation and shrink it until it's either true or false, we'll start by taking an overly complicated if statement and working it out and shrinking it to see what happens;
if ( ( (10 > 5) && (10 > 50) ) || ( ( 100 > 5000) || (100 == 100) ) )
if ( (true && false) || (false || true) )
if ( (true && false ) || true )
if ( false || true )
if ( true )

so,
true or true == true
true or false == true
true and true == true
true and false == false

ActionScript Code:
var myNumber:int = 22; var yourNumber:int = 33; var otherNumber:int = 55; var negNumber:int = -44; if ( (myNumber < yourNumber) && (myNumber > 0) ) {      trace("yourNumber is greater than myNumber and myNumber is greater than 0"); } //remember, || this means 'or' //so, /* if ( (     22      >       33       ) or (      22     >      55         ) or (       22    > -44           ) ) if ( (             false              ) or (            false                ) or (             true              ) ) */ if ( (myNumber > yourNumber) || (myNumber > otherNumber) || (myNumber > negNumber) ) {      trace("myNumber is greater than at least one of the other numbers"); } /*you can also mix them up if ( (      22     >          33    ) or (  (   22       <      33       )  && (     22      > 0) ) ) if ( (            false               ) or (  (           true               ) &&  (      true       ) ) ) if ( (            false               ) or (                                     true                      ) ) */ if ( (myNumber > yourNumber) || ( (myNumber < yourNumber) && (myNumber > 0) ) ) {         trace("true"); }

Hopefully this is enough to get you started. This is just the surface of boolean algebra, I'll leave the more advanced stuff out. You can look into that when you're more experienced
iamgotenks is offline   Reply With Quote
Old 06-10-2012, 10:38 PM   #6
NgemeO
Registered User
 
Join Date: Sep 2011
Posts: 5
Default

Wow! Thanks for a great reply! I just wrote the longest if-sentences in history, I'm sure my teacher wouldn't like it.

Again, thanks! This will definitely make a better impression.

Think of yourself as a savior, and I thank you!
NgemeO is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 01:45 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.