13 Replies Latest reply: Oct 24, 2013 5:57 AM by kglad RSS

    list component to txt file

    vari25 Community Member
      import flash.events.MouseEvent;
      import flash.net.FileReference;
      import flash.display.MovieClip;
       var arr:Array = new Array(square_mc,circle_mc,rect_mc);
      var file:FileReference = new FileReference();
      
      square_mc.visible = false;
      circle_mc.visible = false;
      rect_mc.visible = false;
      
      function ex():void
      {
       for (var i:uint = 0; i < arr.length; i++)
       {
        // Here We are creating four eventlisteners with a function  dispNm
        square_btn.addEventListener(MouseEvent.CLICK,dispNm);
        circle_btn.addEventListener(MouseEvent.CLICK,dispNm1);
        rect_btn.addEventListener(MouseEvent.CLICK, dispNm2);  
       }
      }
      ex();
      function dispNm(e:MouseEvent):void
      {
          trace(e.target.name);
       list.addItem({label:"Square"});
       square_mc.visible = true;
       circle_mc.visible = false;
       rect_mc.visible = false;
      }
      function dispNm1(e:MouseEvent):void
      {
          trace(e.target.name);
       list.addItem({label:"Circle"});
       square_mc.visible = false;
       circle_mc.visible = true;
       rect_mc.visible = false;
      }
      function dispNm2(e:MouseEvent):void
      {
          trace(e.target.name);
       list.addItem({label:"Rectangle"});
       square_mc.visible = false;
       circle_mc.visible = false;
       rect_mc.visible = true;
       
      }
      save.addEventListener(MouseEvent.CLICK, saved)
      function saved(event:MouseEvent):void
      {
       var file:FileReference = new FileReference();
          file.save(list.label.name, "example.txt");
      }
      

      I have this for code.

       

      I want the visible movieclips on stage to be added in .txt file when clicking the save button.

      not all moviclips only vsisble ones. That too, I want this to be saved to server automatically.

       

      What to do? Any idea please.

       

      Please help.

       

      Thanks in advance.

        • 1. Re: list component to txt file
          kglad CommunityMVP

          you can't save movieclips in a text file.  do you want to save their names in a text file?

          • 2. Re: list component to txt file
            vari25 Community Member

            exactly..Yes!!!!

             

            Or feeding data automatically into a excel sheet.

             

            Please advise.

             

            Thank You.

            • 3. Re: list component to txt file
              kglad CommunityMVP

              use the urlloader class to save those names to your server-side script.

              • 4. Re: list component to txt file
                vari25 Community Member

                Thank You.

                 

                Pardon for my ignorance in this.

                 

                But how to set up the flash file i.e., Movieclips should be defined in a variable or ...?

                 

                 

                submit.addEventListener(MouseEvent.CLICK, sendData);
                function sendData(event:MouseEvent):void
                {
                  var urlreq:URLRequest = new URLRequest ("http://www.mydomain.com/file.asp");
                  urlreq.method = URLRequestMethod.POST; 
                  var urlvars:URLVariables = new URLVariables(); 
                urlvars.uname = nametxt.text;
                  urlvars.apellido = aptxt.text;
                  urlvars.email = emtxt.text;
                  urlvars.cedula = cctxt.text;
                  urlvars.score = scoretxt.text;
                  urlreq.data = urlvars;      
                  var loader:URLLoader = new URLLoader (urlreq); 
                  loader.addEventListener(Event.COMPLETE, completed); 
                  loader.dataFormat = URLLoaderDataFormat.VARIABLES; 
                  loader.load(urlreq); 
                }
                function completed (event:Event):void
                {
                  var variables:URLVariables = new URLVariables( event.target.data );
                  resptxt.text = variables.done;
                }
                
                

                 

                How to get this work in my flash file.

                 

                 

                I have a portfolio to submit, Please help.

                 

                Any help would be apprecaited.

                 

                Thank you in advance.

                • 5. Re: list component to txt file
                  kglad CommunityMVP

                  use:

                   

                   

                   

                   

                  submit.addEventListener(MouseEvent.CLICK, sendData);
                  function sendData(event:MouseEvent):void
                  {
                  //use a local path
                     var urlreq:URLRequest = new URLRequest ("/file.asp");   urlreq.method = URLRequestMethod.POST;   var urlvars:URLVariables = new URLVariables();
                  var visableNum:int=0;
                  for(var i:int=0;i<arr.length;i++){
                  if(arr[i].visible){
                  urlvars["visible_mc"+visableNum++]=arr[i].name;
                  }
                  }
                  urlvars.uname = nametxt.text;   urlvars.apellido = aptxt.text;   urlvars.email = emtxt.text;   urlvars.cedula = cctxt.text;   urlvars.score = scoretxt.text;   urlreq.data = urlvars;        var loader:URLLoader = new URLLoader (urlreq);   loader.addEventListener(Event.COMPLETE, completed);   loader.dataFormat = URLLoaderDataFormat.VARIABLES;   loader.load(urlreq); } function completed (event:Event):void {   var variables:URLVariables = new URLVariables( event.target.data );   resptxt.text = variables.done; }

                   

                  • 6. Re: list component to txt file
                    vari25 Community Member

                    Thank You.

                     

                    The below urlvars r not required?

                     

                    As this script was suggested by some friend, I have no idea.

                     

                    So the above code:

                     

                    submit.addEventListener(MouseEvent.CLICK, sendData);

                    function sendData(event:MouseEvent):void

                    {

                    //use a local path

                       var urlreq:URLRequest = new URLRequest ("/file.asp");

                      urlreq.method = URLRequestMethod.POST;

                      var urlvars:URLVariables = new URLVariables();

                    var mcNameA:Array=["square_mc","circle_mc","rect_mc"];

                    var visableNum:int=0;

                    for(var i:int=0;i<mcNameA.length;i++){

                    if(this[mcNameA[i].visible){

                    urlvars["visible_mc"+visableNum++]=mcNameA[i];

                    }

                    }

                    }

                     

                    Then the asp server side script will call the movieclips names to a database file, right?

                     

                    And another doubt, If I have multiple movieclips visible on stage, then all the mc's visible would be feeded to that asp file right?

                     

                    Thank You in advance.

                     

                    The script above is what required to send the visible movieclips on stage to a asp file?

                     

                    Or anything else is to be added?

                     

                    Kindly advise.

                     

                    Thank You.

                    • 7. Re: list component to txt file
                      kglad CommunityMVP

                      urlvariables (or some other object) is required to assign a data property to your urlrequest and is used in the code i showed to send data to your asp file.  if your asp file looks for POST'ed variable/value pairs and writes the values to a text file, then all should work.

                       

                      in the code i suggested, i'm sending the variables, visible_mc0, visible_mc1, .. etc with values = the names of the visible movieclips listed in arr.  you copied the code i first posted.  i later amended that code a few minutes later to use your arr array.

                       

                      here it is the code without the extraneous lines:

                       

                      submit.addEventListener(MouseEvent.CLICK, sendData);
                      function sendData(event:MouseEvent):void
                      {
                      //use a local path
                         var urlreq:URLRequest = new URLRequest ("/file.asp");
                        urlreq.method = URLRequestMethod.POST;
                        var urlvars:URLVariables = new URLVariables();
                      var visableNum:int=0;
                      for(var i:int=0;i<arr.length;i++){
                      if(arr[i].visible){
                      urlvars["visible_mc"+visableNum++]=arr[i].name;  // <- this is where i use your urlvariables to assign variables/values
                      }
                      }
                        urlreq.data = urlvars;   //<- data property assign to your urlrequest
                        var loader:URLLoader = new URLLoader (urlreq);
                        loader.addEventListener(Event.COMPLETE, completed);
                        loader.dataFormat = URLLoaderDataFormat.VARIABLES;
                        loader.load(urlreq);
                      }
                      function completed (event:Event):void
                      {
                        resptxt.text = event.target.data;
                      }

                      • 8. Re: list component to txt file
                        vari25 Community Member

                        Thank You so much for the kind reply.

                        • 9. Re: list component to txt file
                          kglad CommunityMVP

                          you're welcome.

                          • 10. Re: list component to txt file
                            vari25 Community Member

                            Error #2044: Unhandled ioError:. text=Error #2032: Stream Error. URL: file:///file.asp

                            at output_txt_ex1_fla::MainTimeline/sendData()

                             

                             

                            This is an error FLash throwing

                            What to do?

                             

                            Please help

                            • 11. Re: list component to txt file
                              kglad CommunityMVP

                              you should test that on your file server that supports asp.

                               

                              if you're running an asp server locally, you have an incorrect path to file.asp.

                              • 12. Re: list component to txt file
                                vari25 Community Member

                                Thank u .

                                 

                                I would check that.

                                • 13. Re: list component to txt file
                                  kglad CommunityMVP

                                  you're welcome.