16 Replies Latest reply on May 24, 2006 1:59 PM by Alexander_Fabian

    Mathematics with three Dynamic Text...

    Alexander_Fabian
      Hi!... Is my first post...

      I have three dynamic text:

      1. Loading a .txt file with a number as n.nn. [Dt1]
      2. Contain a number as nnn.nn. [Dt2]
      3. Output between 1. and 2. [Dt3]

      I load first number as loadVariablesNum("MyFile.txt", "0");...

      My AS code to output in (Dt3) is: Dt3 = Number(Dt2.text)/Number(Dt1.text);

      The Load is Ok!, but in Dt3 i just read "NaN".

      Can you help me to solve this matter?...

      Thanks in advance...
        • 1. Re: Mathematics with three Dynamic Text...
          Rothrock Level 5
          Try this:

          Dt3.text=parseFloat(Dt2.text)/parseFloat(Dt1.text);
          • 2. Re: Mathematics with three Dynamic Text...
            Alexander_Fabian Level 1
            Hi Rothrock!... Thank you by your reply...

            unfortunately the option that you provided to me doesn't work. Is not possible to see anything in output field. Exist other possibilities for this kind of variables?
            • 3. Re: Mathematics with three Dynamic Text...
              Rothrock Level 5
              Try this:

              trace("The text of Dt2 is: "+Dt2.text);
              trace("The value of Dt2 is: "+parseFloat(Dt2.text);

              Also do that for Dt1 and let me know what you get.
              • 4. Re: Mathematics with three Dynamic Text...
                Alexander_Fabian Level 1
                The text of Dt2 is: undefined
                The value of Dt2 is: NaN

                The text of Dt1 is: undefined
                The value of Dt1 is: NaN
                • 5. Re: Mathematics with three Dynamic Text...
                  Rothrock Level 5
                  So then either there is no text in Dt1 and Dt2 or the scope of your statements is wrong.

                  In the same place where you have the other traces add this:

                  trace("The current scope is: "+this);

                  When you run this in the testing environment go up to the Debug menu and List Variables. Look through and see where the Dt1 and Dt2 are declared. Compare that to the results of the above trace and post back with what you figure out.
                  • 6. Re: Mathematics with three Dynamic Text...
                    Alexander_Fabian Level 1
                    Okey!... now i get:
                    The text of Dt1 is: undefined
                    The value of Dt1 is: NaN
                    The text of Dt2 is: 240.50
                    The value of Dt2 is: 240.5
                    The current scope is: _level0

                    In debug list I get:

                    Variable _level0.Dt1 = "1.20"
                    (...)
                    type = "dynamic",
                    scroll = 1,
                    variable = "Dt1",
                    restrict = null,
                    antiAliasType = "advanced",
                    selectable = false, (...)
                    (...)
                    Modifier le texte : Cible="_level0.Dt2"
                    maxChars = null,
                    text = "240.50",
                    (...)
                    type = "dynamic",
                    scroll = 1, variable = null, restrict = null,
                    antiAliasType = "advanced", (...)

                    I thinks that Dt2 is ready, but Dt1, even though I can to see in test, is "undefined" and "NaN" in "trace"...?????...
                    What can I do to validate this field?
                    • 7. Re: Mathematics with three Dynamic Text...
                      Rothrock Level 5
                      My guess is that you aren't waiting until your external file has finished loading. How are you loading the external number?
                      • 8. Re: Mathematics with three Dynamic Text...
                        Alexander_Fabian Level 1
                        As:
                        loadVariablesNum("Myfile.txt", 0);

                        And inside of my file I have:
                        &Dt2=1.20
                        • 9. Re: Mathematics with three Dynamic Text...
                          Rothrock Level 5
                          Ya'know what? I don't actually know how to make sure that you have waited until the file "Myfile.txt" has completely loaded before you try and do anything with it. You could do something like this perhaps:

                          this.onEnterframe=function(){
                          if(Dt2 != undefined){
                          delete this.onEnterframe
                          //do the addition here
                          }
                          }

                          Instead, I would recommend using the LoadVars class (available from Flash 6 on) in that case you could use the onLoad event to make sure the file has loaded before you try and use it.
                          • 10. Re: Mathematics with three Dynamic Text...
                            NSurveyor Level 2
                            Also, I think Dt1 is actually the variable property of a textfield. Also, it seems that Dt2 is a textfield, but you are loading a value into that variable.

                            So, just to make sure.... don't put any variable names in the Properties Panel. Instead, give everything an <Instance Name>. Use Dt1, Dt2, and Dt3. Then, use the following code to load the data:

                            my_lv = new LoadVars();
                            my_lv.onLoad = function(s){
                            if(s){
                            Dt2.text = this.Dt2;
                            // HERE??? Dt3.text=parseFloat(Dt2.text)/parseFloat(Dt1.text);
                            }else{
                            trace("ERROR LOADING!");
                            }
                            };
                            my_lv.load("Myfile.txt");

                            I'm not exactly sure when you are doing your calculation... but if it's supposed to be right after the load, then put it inside the onLoad event as I have commented above.
                            • 11. Re: Mathematics with three Dynamic Text...
                              Alexander_Fabian Level 1
                              Rothrock as you told me the "NaN" (not a number) persist...

                              NSurveyor as you explain I get three errors: Undefined in Dt1 and, NaN in Dt3 and is son possible to see number loaded in Dt2.

                              I don't know... If I'll try loading a .swf with Dt1?... What do you think about it?....
                              • 12. Re: Mathematics with three Dynamic Text...
                                Deepak Joshi Level 1
                                i am asuming that the text-field's instance name is Dt1, Dt2, Dt3 and variables in text-file are Dt1, Dt2

                                • 13. Re: Mathematics with three Dynamic Text...
                                  Deepak Joshi Level 1
                                  i am asuming that the text-field's instance name is Dt1, Dt2, Dt3 and variables in text-file are Dt1, Dt2
                                  • 14. Re: Mathematics with three Dynamic Text...
                                    Alexander_Fabian Level 1
                                    Ok!... I will explain it better...
                                    A file .txt will be changed automatically. This .txt file contain a rate exchange (cost US for one EUR.). Inside .txt file I put: change=1.20.
                                    This value is loading in a DynamicText called Dt1.
                                    In same frame I create two dynamic text more: Dt2 and Dt3. Dt2 is a DynamicText with one price in EUR. (e. 210.50). The third DynamicText , Dt3, is to see price in US (output).

                                    At first, it should be so simple as: Dt3.text = (Number(Dt2.text)) / (Number(Dt1.text)); Unfortunately NAN (Not a Number) persists in field Dt3.

                                    At this way, I want to load a .txt so that updated automatically through a 'stock exchange' service.
                                    • 15. Re: Mathematics with three Dynamic Text...
                                      Alexander_Fabian Level 1
                                      Ok!... I have solved the problem in following way:
                                      My .txt (rates.txt) with following code inside:
                                      quote:

                                      &euro=1&dolar=1.20&pound=0.6825&yen=143.75&
                                      (I use three rate exchanges).

                                      In AS code I have:
                                      quote:

                                      var variables:LoadVars = new LoadVars();
                                      variables.load("rates.txt");
                                      var euro:TextField;
                                      var dolar:TextField;
                                      var pound:TextField;
                                      var yen:TextField;
                                      var totaleuro:TextField;
                                      var totaldolar:TextField;
                                      var totalpound:TextField;
                                      var totalyen:TextField;
                                      var euro_btn:Button;
                                      var dolar_btn:Button;
                                      var pound_btn:Button;
                                      var yen_btn:Button;
                                      variables.onLoad = function(exito:Boolean) {
                                      if (exito) {
                                      euro.text = this.euro;
                                      dolar.text = this.dolar;
                                      pound.text = this.pound;
                                      yen.text = this.yen;
                                      } else {
                                      trace("Isn't possible loading data");
                                      }
                                      };
                                      onEnterFrame = function () {
                                      totaleuro.text = String(Number(cantidad.text)*Number(euro.text));
                                      totaldolar.text = String(Number(cantidad.text)*Number(dolar.text));
                                      totalpound.text = String(Number(cantidad.text)*Number(pound.text));
                                      totalyen.text = String(Number(cantidad.text)*Number(yen.text));
                                      };


                                      Nevertheless, thank you for your help... I has based my code in your advises also.

                                      Alex!.
                                      • 16. Re: Mathematics with three Dynamic Text...
                                        Alexander_Fabian Level 1
                                        Ok!... I have solved the problem in following way:
                                        My .txt (rates.txt) with following code inside:
                                        quote:

                                        &euro=1&dolar=1.20&pound=0.6825&yen=143.75&
                                        (I use three rate exchanges).

                                        In AS code I have:
                                        quote:

                                        var variables:LoadVars = new LoadVars();
                                        variables.load("rates.txt");
                                        var euro:TextField;
                                        var dolar:TextField;
                                        var pound:TextField;
                                        var yen:TextField;
                                        var totaleuro:TextField;
                                        var totaldolar:TextField;
                                        var totalpound:TextField;
                                        var totalyen:TextField;
                                        var euro_btn:Button;
                                        var dolar_btn:Button;
                                        var pound_btn:Button;
                                        var yen_btn:Button;
                                        variables.onLoad = function(exito:Boolean) {
                                        if (exito) {
                                        euro.text = this.euro;
                                        dolar.text = this.dolar;
                                        pound.text = this.pound;
                                        yen.text = this.yen;
                                        } else {
                                        trace("Isn't possible loading data");
                                        }
                                        };
                                        onEnterFrame = function () {
                                        totaleuro.text = String(Number(cantidad.text)*Number(euro.text));
                                        totaldolar.text = String(Number(cantidad.text)*Number(dolar.text));
                                        totalpound.text = String(Number(cantidad.text)*Number(pound.text));
                                        totalyen.text = String(Number(cantidad.text)*Number(yen.text));
                                        };


                                        Nevertheless, thank you for your help... I has based my code in your advises also.

                                        Alex!.