Skip to main content
October 21, 2013
Answered

list component to txt file

  • October 21, 2013
  • 1 reply
  • 2725 views
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.

This topic has been closed for replies.
Correct answer kglad

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.visible){

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

}

}

}

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.


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.visible){
urlvars["visible_mc"+visableNum++]=arr.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;
}

1 reply

kglad
Community Expert
Community Expert
October 21, 2013

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

October 21, 2013

exactly..Yes!!!!

Or feeding data automatically into a excel sheet.

Please advise.

Thank You.

kglad
Community Expert
Community Expert
October 21, 2013

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