9 Replies Latest reply on Feb 7, 2009 12:34 PM by Newsgroup_User

    Actionscript in Flex Limitations?

    alice_data Level 1
      Hi,

      I have a question on what is the limitation of the number of functions being called in Flex using Actionscript. Is there a certain number of if statements nesting only allowed in a single private function? I have a function call as in the following, and I wanted to add some other Alert statements to show users if there is an error in the process, but it appears that the file writing process is so long that I never see the Alert.show pop up.

      Could anyone here please tell me what I might have done wrong here? If there is a limit to how many functions I can insert due to "time issues," is there a way I can get around it?

      Thanks for your help.



      Attached Code:

      Main Event Handler:

      private function clickHandler3(event:ItemClickEvent):void {
      if (String(event.index) == '0') {
      currentState="";
      }
      if (String(event.index) == '1') {
      scenario_find.send();
      currentState="Scenario Show";
      }
      if (String(event.index) == '2') {
      scenario_save(0); //The user would only save the scenario
      }
      if (String(event.index) == '3') {
      //The user would save and run the scenario
      scenario_name.send();
      filename1.text= scenario_name.lastResult.scenarios.filename;
      scenario_save(1); //Save record and output the file to filename1.text
      //Execute the exe file and input entries back to the database
      }
      }

      Child Function of Scenario Save:
      private function scenario_save(x:int):void{

      var pop:int= scenario_load.lastResult.scenarios.number_entries;
      var pop2:int=scenario_load.lastResult.scenarios.number_entries-1;
      number1.text= pop.toString();
      if (pop2 == 0) { //if there is only one item, no index produced
      i1.text= i.toString();
      population1.text=scenario_load.lastResult.scenarios.scenario.population;
      region_id1.text=scenario_load.lastResult.scenarios.scenario.region_id;
      query1.text= "UPDATE My_Scenario SET Population='" + population1.text + "' WHERE Region_id='" + region_id1.text + "' AND ID='" + id1.text + "'";
      hello1.text=region_id1.text + "\t" + population1.text;
      update_record.send();
      if (x==0) {
      //Don't do anything, since there is nothing to run
      } else if (x==1) {
      execute_scenario.send();
      }
      }
      else {
      for (var i:int=0;i<=pop;i++) { //if there are more than one item, indices would be produced
      i1.text= i.toString();
      population1.text=scenario_load.lastResult.scenarios.scenario.population;
      region_id1.text=scenario_load.lastResult.scenarios.scenario.region_id;
      query1.text= "UPDATE My_Scenario SET Population='" + population1.text + "' WHERE Region_id='" + region_id1.text + "' AND ID='" + id1.text + "'";
      hello1.text=region_id1.text + "\t" + population1.text;
      update_record.send();
      if (x==0) {
      //Don't do anything, since there is nothing to run
      } else if (x==1) {
      execute_scenario.send();
      //I want to add some other alert statements here
      }
      }
      }
      }


        • 1. Re: Actionscript in Flex Limitations?
          levancho Level 3
          your problem is here:
          quote:


          scenario_name.send();
          filename1.text= scenario_name.lastResult.scenarios.filename;
          scenario_save(1); //Save record and output the file to filename1.text


          you cant just send a service and next line read the result,
          you need listen to its result Event and resume there.
          • 2. Actionscript in Flex Limitations?
            alice_data Level 1
            Hi,

            I think when I tried to execute the function with the error you mentioned, there are not any errors generated.What I do notice that currently since my scenario_save(1) contains running run_scenario.send(), I do get a lot of Microsoft exe shut down errors since run_scenario.send() compiles results with PHP containing shell_exec() of an exe file.

            Just to clarify, does this mean that what I was doing before fails to get run_scenario.send() from scenario_save(1) executed properly or to display second or third messager from not using result and fail in scenario_name.send()?

            Thanks for your help.

            Alice
            • 3. Re: Actionscript in Flex Limitations?
              Level 7

              "alice_data" <webforumsuser@macromedia.com> wrote in message
              news:glr3mp$fn4$1@forums.macromedia.com...
              > Hi,
              >
              > I think when I tried to that, I don't think I have any errors generated.
              > About what you said, do I have to do something like result or fail and
              > determine what to do next?
              >
              > However, this does not seem to solve my problem of what happens when I
              > try
              > to execute the scenario_save(1) with more Alert.show that I would like to
              > display but doesn't. Is there something else I am not catching here?
              >
              > Thanks for your help.

              There are no actual Alert.show() calls in the code you posted, so it's hard
              to say what the problem is.


              • 4. Re: Actionscript in Flex Limitations?
                alice_data Level 1
                Hi, Amy:

                Thanks for trying to help me with this problem. I have attached the code and have it commented for you to see which part of the Alert.show is not being executed. One note is that if I put it before scenario_save(1), I do see the Alert.show statement on the screen. Am I experiencing what the other user here is saying?

                Thanks for your help.

                Alice
                • 5. Re: Actionscript in Flex Limitations?
                  Level 7

                  "alice_data" <webforumsuser@macromedia.com> wrote in message
                  news:glsdaa$4lg$1@forums.macromedia.com...
                  > Hi, Amy:
                  >
                  > Thanks for trying to help me with this problem. I have attached the code
                  > and
                  > have it commented for you to see which part of the Alert.show is not being
                  > executed. One note is that if I put it before scenario_save(1), I do see
                  > the
                  > Alert.show statement on the screen. Am I experiencing what the other user
                  > here
                  > is saying?

                  First, I'll try to see if I can answer your question, then I'll give you a
                  few random thoughts that you can keep or discard.

                  scenario_save() is a function that contains a lot of logic in it. Part of
                  this logic is a series of if statements, only one of which contains an
                  Alert.show(). I'd be willing to bet that the reason you're not seeing the
                  Alert.show() is because it's not going down that branch.

                  Now for the random thoughts.

                  One way that you can make this sort of thing easier to debug is to use
                  switch statements intead of if statements. The logic will also run faster.

                  Try something like

                  switch (x) {
                  case 0:
                  Alert.show('nothing to do');
                  break;
                  case 1:
                  execute_scenario.send();
                  Alert.show("Process is completed");
                  break;
                  default:
                  //loop and save
                  Alert.show('records saved');
                  }

                  No matter what happens in this construction, you'll get an alert. If you do
                  the same with the if pop2==0, then you should be able to figure out why your
                  logic isn't going where you think it is.

                  I also noticed that you seem to be sending the sql to a page that's set up
                  to run any sql sent to it. This is just an open invitation to any hacker to
                  send your page a post parameter that says "DELETE * FROM Market." I would
                  strongly discourage this practice, as tempting as it might be to not have to
                  put much effort into your php code.

                  What I do is to use stored queries and create a get page and a set page that
                  will then run the query and return the result. This is much harder to hack,
                  as the hacker has to know what the name of the query is and what the
                  parameters all mean. Problem is, I'm not sure if mySQL supports
                  parameterized stored queries.

                  You may also want to look into moving into typed RemoteObjects. This is
                  definitely more work on the server side, but when the data gets back to the
                  client side it is already packaged as tidy objects of your own types.

                  HTH;

                  Amy


                  • 6. Re: Actionscript in Flex Limitations?
                    alice_data Level 1
                    Hi, Amy:

                    Thanks for your insights, and I have been seriously investigating on using switch statements in this case to solve my problems. Looks like the first part of the issue I originally had with Alert.show not showing up in the parent clickHandler3 function no longer exist. However, When I executed my application, I don't think scenario_save() has been doing anything, since I could not see the Alert.show statement been disclosed in the switch(pop2), and neither is any of the lines been written like I expected, but I do see the Alert.show in the switch(x) by executing the Alert.show from case 1 as anticipated.

                    I have marked the sections using comments, and I wonder if I am allowed to use nested switch statements over another in Actionscript.

                    Thanks for your help again.

                    Alice

                    • 7. Re: Actionscript in Flex Limitations?
                      Level 7
                      Have you tried stepping through it in the debugger?
                      http://flexdiary.blogspot.com/2008/01/flex-debugging-tutorial.html

                      "alice_data" <webforumsuser@macromedia.com> wrote in message
                      news:gm4j9o$cgq$1@forums.macromedia.com...
                      > Hi, Amy:
                      >
                      > Thanks for your insights, and I have been seriously investigating on
                      > using
                      > switch statements in this case to solve my problems. Looks like the first
                      > part
                      > of the issue I originally had with Alert.show not showing up in the parent
                      > clickHandler3 function no longer exist. However, When I executed my
                      > application, I don't think scenario_save() has been doing anything, since
                      > I
                      > could not see the Alert.show statement been disclosed in the switch(pop2),
                      > and
                      > neither is any of the lines been written like I expected, but I do see the
                      > Alert.show in the switch(x) by executing the Alert.show from case 1 as
                      > anticipated.
                      >
                      > I have marked the sections using comments, and I wonder if I am allowed
                      > to
                      > use nested switch statements over another in Actionscript.
                      >
                      > Thanks for your help again.
                      >
                      > Alice
                      >
                      >
                      >
                      > private function clickHandler3(event:ItemClickEvent):void {
                      > switch(String(event.index)){
                      > case '0':
                      > Alert.show("You will be returned to the original state");
                      > currentState="";
                      > break;
                      > case '1':
                      > Alert.show("You will be returned back to the listing
                      > results");
                      > scenario_find.send();
                      > currentState="Scenario Show";
                      > break;
                      > case '2':
                      > Alert.show("You will be saving the scenario");
                      > scenario_save(0); //The user would only save the
                      > scenario
                      >
                      > break;
                      > case '3':
                      > scenario_name1.text=
                      > scenario_load.lastResult.scenarios.scenario_name;
                      > //The user would save and run the scenario
                      >
                      > scenario_name.send();
                      > filename1.text=
                      > scenario_name.lastResult.scenarios.filename;
                      > scenario_save(1); //Save record and output the file to
                      > filename1.text
                      > //Execute the exe file and input entries back to the
                      > database
                      > Alert.show("Thank you!");
                      > break;
                      > default:
                      > currentState="";
                      > break;
                      > }
                      > }
                      >
                      > private function scenario_save(x:int):void{
                      >
                      > var pop:int= scenario_load.lastResult.scenarios.number_entries;
                      > var pop2:int=scenario_load.lastResult.scenarios.number_entries-1;
                      > number1.text= pop.toString();
                      > switch (pop2) {
                      > case 0:
                      > //if there is only one item, no index produced
                      > i1.text= i.toString();
                      >
                      > population1.text=scenario_load.lastResult.scenarios.scenario.population;
                      >
                      > region_id1.text=scenario_load.lastResult.scenarios.scenario.region_id;
                      > market1.text=scenario_load.lastResult.scenarios.scenario.market;
                      > query1.text= "UPDATE Scenario_elements SET Market='" + market1.text + "'
                      > WHERE ID='" + id1.text + "'";
                      > hello1.text=region_id1.text + "\t" + population1.text + "\t" +
                      > market1.text
                      > + "\t";
                      > update_record.send();
                      > Alert.show("Query is " + query1.text);
                      > break;
                      > case (pop2 != 0):
                      > for (var i:int=0;i<=pop;i++) { //if there are more than one
                      > item, indices would be produced
                      > i1.text= i.toString();
                      >
                      > population1.text=scenario_load.lastResult.scenarios.scenario .population;
                      >
                      > region_id1.text=scenario_load.lastResult.scenarios.scenario
                      .region_id;
                      > market1.text=scenario_load.lastResult.scenarios.scenario .market;
                      > query1.text= "UPDATE Scenario_elements SET Market='" + market1.text + "'
                      > WHERE ID='" + id1.text + "'";
                      > hello1.text=region_id1.text + "\t" + population1.text + "\t" +
                      > market1.text
                      > + "\t";
                      > update_record.send();
                      > Alert.show("Query is " + query1.text);
                      > }
                      > break;
                      > default:
                      > //Don't do anything
                      > }
                      > switch (x) {
                      > case 0:
                      > Alert.show("You are saving a scenario");
                      > //Don't do anything, since there is nothing to run
                      > break;
                      > case 1:
                      > Alert.show("You are running a scenario");
                      > execute_scenario.send();
                      > break;
                      > default:
                      > //Don't do a thing
                      > break;
                      > }
                      > }
                      >


                      • 8. Actionscript in Flex Limitations?
                        alice_data Level 1
                        Hi, Amy:

                        Thanks for the heads up, and it looks as if originally my Flex software had some errors in it causing me unable to see the errors hidden behind the scene. I have taken another member's answer in this thread's suggestion on implementing the "result" event in my HTTPService, and now I get no more errors.

                        Thanks.
                        • 9. Re: Actionscript in Flex Limitations?
                          Level 7

                          "alice_data" <webforumsuser@macromedia.com> wrote in message
                          news:gm78tc$nam$1@forums.macromedia.com...
                          > Hi, Amy:
                          >
                          > I did try to use the debugger, but it appears that I don't get to see
                          > any of
                          > the error messages. What is even more odd is that the rest of the
                          > functions in
                          > the sequence calling in the ones I have commented out never get executed
                          > or
                          > printed out even when they weren't commented.
                          >
                          > Is it possible that I am confusing the code executing here with the
                          > logic?
                          >
                          > Thanks for your help.
                          >
                          > Alice
                          >
                          > private function clickHandler3(event:ItemClickEvent):void {
                          > switch(String(event.index)){
                          > case "0":
                          > Alert.show("You will be returned to the original state");
                          > currentState="";
                          > break;
                          > case "1":
                          > Alert.show("You will be returned back to the listing
                          > results");
                          > scenario_find.send();
                          > currentState="Scenario Show";
                          > break;
                          > case "2":
                          > Alert.show("You will be saving the scenario");
                          > scenario_save(0); //The user would only save the
                          > scenario
                          >
                          > break;
                          > case "3":
                          > scenario_name1.text=
                          > scenario_load.lastResult.scenarios.scenario_name;
                          > Alert.show("Scenario Name: " + scenario_name1.text);
                          > //The user would save and run the scenario
                          >
                          > scenario_name.send();
                          >
                          > filename1.text=scenario_name.lastResult.scenario.filename;
                          > //Gives me an error
                          > Alert.show("Filename " + filename1.text);
                          > scenario_save(1); //Save record and output the file
                          > to
                          > filename1.text
                          > //Execute the exe file and input entries back to the
                          > database
                          > // Alert.show("Scenario Run Completed");
                          > break;
                          > default:
                          > currentState="";
                          > break;
                          > }
                          > }

                          I'm sorry, I didn't forget about you, but I just started a new gig, so if I
                          think a post will take me more than about 30 seconds to answer I save it for
                          later.

                          What I would do is to put a break point at the switch statement. Then, I'd
                          look in the variables window at the event variable and then look at its
                          index property. I highly suspect that you will find the problem there. If
                          not, look at other variables that could be causing the problem. Also, use
                          the step over button to go through your code one line at a time and see
                          where it is going.

                          HTH;

                          Amy