Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

list component to txt file

Guest
Oct 21, 2013 Oct 21, 2013
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.

TOPICS
ActionScript
2.6K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Oct 22, 2013 Oct 22, 2013

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

...
Translate
Community Expert ,
Oct 21, 2013 Oct 21, 2013

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Oct 21, 2013 Oct 21, 2013

exactly..Yes!!!!

Or feeding data automatically into a excel sheet.

Please advise.

Thank You.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 21, 2013 Oct 21, 2013

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Oct 21, 2013 Oct 21, 2013

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 21, 2013 Oct 21, 2013

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Oct 21, 2013 Oct 21, 2013

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 22, 2013 Oct 22, 2013

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;
}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Oct 22, 2013 Oct 22, 2013

Thank You so much for the kind reply.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 23, 2013 Oct 23, 2013

you're welcome.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Oct 23, 2013 Oct 23, 2013

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 23, 2013 Oct 23, 2013

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Oct 24, 2013 Oct 24, 2013

Thank u .

I would check that.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 24, 2013 Oct 24, 2013
LATEST

you're welcome.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines