12 Replies Latest reply on Oct 28, 2009 8:18 AM by Tareq_1993

    Condition (if)

    Tareq_1993 Level 1

      Hello

      I've made 2 boxes

      1 dynamic called (Result)

      and 1 input called (Enter)

       

      I want a condition, if Enter is bigger than 0 I get result big, if it was less, I get result small, if it equals 0 I get result medium.

       

      How can that be scripted?

      (Flash CS4, action script 2)

       

      thanks alot

        • 1. Re: Condition (if)
          Ned Murphy Adobe Community Professional & MVP

          I am not sure what you mean when you say 2 boxes, but if they are textfields, then you will refer to what's in them using textFieldName.text, where textFieldName is whatever instance name you assign

           

           

          if(Enter < 0){

               Result = "small";

          } else if(Enter > 0){

               Result = "big";

          } else {

               Result = "medium";

          }

          1 person found this helpful
          • 2. Re: Condition (if)
            Tareq_1993 Level 1

            hey

            thanks for trying to help.

            But, it gave all the time answer Medium, so I tried to remove the third choice.

            After I've done that, it was leaving the dynamic box blank (no answer)

            so I dun know why is that....

            Can you help please?...

             

             

            and yea, they r text fields, one of them u insert a number inside, and the other is dynamic box, the result should appear in.

            • 3. Re: Condition (if)
              Ned Murphy Adobe Community Professional & MVP

              What makes the result appear?  Do you click a button?  HAve you assigned instance names to the textfields via the properties panel?

              1 person found this helpful
              • 4. Re: Condition (if)
                Ned Murphy Adobe Community Professional & MVP

                There is no telling what you have created and what code you might need to use as a result.  I have created an example file for you.  Study it to see what I did for the textfields and how I acquire, test, and assign the values.

                 

                http://www.nedwebs.com/Flash/AS2_Enter_Result.fla

                 

                There are a variety of ways one could approach this, so I don't expect what I did will match what you are doing, but at least you will have something that works that you might be able to build from.

                1 person found this helpful
                • 5. Re: Condition (if)
                  Tareq_1993 Level 1

                  Thanks alot.

                  It really worked.

                  The different thing I was doing, is, I was putting var name, instead of instance name.

                  Anyway, what's the difference between var name and instance name?

                  Thanks alot.

                  • 6. Re: Condition (if)
                    Ned Murphy Adobe Community Professional & MVP

                    The var name is what it implies, it is a variable that gets associated with the textfield text entry as a value.  The text property is a String value of what is contained in the textfield.  It is generally a better practice to avoid using the var as it doesn't always behave as expected... using the text property is much more reliable.

                    • 7. Re: Condition (if)
                      Tareq_1993 Level 1

                      Although I didn't understand what you meant.

                      But, thanks alot

                       

                      One more simple question, and here my steps might end.

                       

                      You have replied to my past posts, and I consider you may know what I was, and still, trying to do.

                       

                      4 input boxes.

                      North - South - East - West.

                       

                      4 Dynamic Boxes

                      Fx - Fy - Ft - Fc

                       

                      Fx = East - West

                      Fy =  North - South

                      Ft = root (power 2 (Fx) + (power 2 (Fu))

                       

                      if (Ft>0)

                      Fc = Big

                       

                      else if (Ft<0)

                      Fc = Small

                       

                      else

                      Fc = medium

                       

                       

                       

                       

                      I've tried alot, in over 15 different coding way, but it didn't work.

                      instance and var thing really confuse me.

                      However, if 1 step works, the other doesn;t.

                      But seperately they work perfect.

                      So, can you instuct me and put me on the right way?

                      or Just do me a basic code, and ill understand it

                       

                      thanks alot

                      • 8. Re: Condition (if)
                        Tareq_1993 Level 1

                        errrrr mate?

                        its ok, dun give me full code, just tell me way to make if conditions using var name, without using instance, thanks alot

                         

                        • 9. Re: Condition (if)
                          Ned Murphy Adobe Community Professional & MVP

                          Errr... why would you expect me to create the full code for anything for you--your last "simple question" seemed more like a task to create the code for your complete design... well beyond the scope of your original posting and my intentions in helping in these forums.

                           

                          I won't show you how to use the var name approach because I do not promote using var names for textfields... they are unreliable.

                          • 10. Re: Condition (if)
                            Tareq_1993 Level 1

                            Sorry mate, since I am not native, maybe what I wrote isn't exactly what I meant.

                            I meant, instead of keep trying and we get no results, u can save ur time.

                            Not task at all.

                             

                            Well, I;ve tried many ways, but, I do the mathematical stuff using var name, and u showed me how to do (if) using instance name.

                            so, I cant make all that in one scene, which I want.

                             

                            so now, either I learn how to do mathmatics (+ / pow / square root) using instance.

                            Or just learn how to do (if) conditions using var.

                             

                            And thanks alot by the way, you have helped me much so far.

                            • 11. Re: Condition (if)
                              Ned Murphy Adobe Community Professional & MVP

                              I always avoid using the var option for textfields.  If I need to use variables from textfields I create them separately as variables and assign the textfield.text value to them.  If it is a number in the textfield I will assign it by casting it as a number value... example

                               

                              var someVariable1 = Number(textfield1.text);

                              var someVariable2 = Number(textfield2.text);

                               

                              var someVariable3 = someVariable1 + someVariable2;

                              • 12. Re: Condition (if)
                                Tareq_1993 Level 1

                                Hello

                                I appreciate you try to help me.

                                I tried to create one, but the dynamic field was being still empty, didn't get any answer in it. you can see it:

                                http://www.4shared.com/file/144377237/ac351ab3/Example.html

                                thanks alot