9 Replies Latest reply: Sep 18, 2012 10:50 PM by kglad RSS

    store data in backend with flash & AS3

    rahimhaji Community Member

      hi friends,

       

      Greetings! Actually iam doing an elearning application, while reading our flash screen, student has to pass their comments to the instructor, it will store in data base and continue reading same screen. if i use post it will navigate to another aspx screen this will last the student where they read. pls advice me...how can i do this? is there any way to store data in db back end direct..?

       

      Thanks in advance..

       

      Regards,

       

      Syed

        • 1. Re: store data in backend with flash & AS3
          kglad CommunityMVP

          yes, you can use the as3 urlLoader() class to post variables/values to server-side script (like php) which then adds the data to your db.

          • 2. Re: store data in backend with flash & AS3
            rahimhaji Community Member

            hi kglad,

             

            thks for ur reply and advice, if i use urlLoader, should i use navigateToUrl? if i use navigate to url, it will open another new aspx page. i dont want that. Whatever is there in the screen it has to be there as it is. but i need to pass the variable/value to the server while reading the lessons. pls advice me.

             

            Thanks in advance,

            Syed

            • 3. Re: store data in backend with flash & AS3
              kglad CommunityMVP

              don't use navigateToURL(), use urlLoader().  it won't open another browser window.

              • 4. Re: store data in backend with flash & AS3
                rahimhaji Community Member

                Dear Friends,

                 

                iam loading my swf file in aspx file on the browser, when i click a button i will pass 2 variables to database and close or unload. If the user close the browser withtout click on that button i want to post that values and save in the dtabase. how can i do that pls explain me.

                 

                find below the code i used to store data when i click a button.

                 

                 

                var variables:URLVariables = new URLVariables();

                var varSend:URLRequest = new URLRequest("lmsHome.aspx");

                var varLoader:URLLoader = new URLLoader;

                varSend.method = URLRequestMethod.POST;

                varSend.data = variables;

                 

                frdbut.addEventListener(MouseEvent.CLICK,sendMessage);

                 

                function sendMessage(event:MouseEvent):void {

                    variables.elecode = lescode;

                    variables.eleduration = "2:0"

                    varLoader.load(varSend);

                }

                 

                 

                Thanks in advance,

                Syed Abdul Rahim

                • 5. Re: store data in backend with flash & AS3
                  kglad CommunityMVP

                  you can use the javascript onunload method to detect when users close that window and you can use the actionscript externalinterface class to communicate between javascript and actionscript.

                  • 6. Re: store data in backend with flash & AS3
                    rahimhaji Community Member

                    Dear Mr.kglad,

                     

                    Greetings! Thks for the reply, i tried, it is working as javascript, i mean when i close the browser it is working, but when i opend the file or refress, it is not working, i mean, i cannot pass any variale or run a function in flash.

                     

                    pls tell me how to clear this problem, i want to run a function existing in flash while closing or refreshing the brower where the flash swf is loaded.

                     

                    find below my code:

                     

                    flash code:

                     

                    import flash.external.ExternalInterface;

                    import flash.external.*;

                    ExternalInterface.call("show_alert","1234");

                     

                    javascript code:

                     

                    <script language="javascript">AC_FL_RunContent = 0;</script>

                    <script src="AC_RunActiveContent.js" language="javascript"></script>

                    <script type="text/javascript" language="javascript">

                        function show_alert(s){

                            alert(s);

                            alert("This is a test..");

                        }

                    </script>

                    </head>

                    <body bgcolor="#ffffff" onUnload="show_alert('ind');">

                     

                    Regards,

                    Syed Abdul rahim

                    • 7. Re: store data in backend with flash & AS3
                      kglad CommunityMVP

                      if you want so pass 'ind' to show_alert() on loading and reloading, you can use:

                       

                      <body bgcolor="#ffffff" onload="show_alert('ind');" onUnload="show_alert('ind');">

                      • 8. Re: store data in backend with flash & AS3
                        rahimhaji Community Member

                        hi thks for the reply,

                         

                        i want to run a function existing in flash while closing or refreshing the web brower where the flash swf is loaded.

                         

                        pls help me..

                         

                        Thanks in advance,

                         

                        Syed Abdul rahim

                        • 9. Re: store data in backend with flash & AS3
                          kglad CommunityMVP

                          call a different javascript function that uses the callback method of the externalinterface class.  the help files have sample code.

                           

                          note: use the embedding html shown (or swfobject) to embed your swf.