Copy link to clipboard
Copied
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 dispNmsquare_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.
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
...Copy link to clipboard
Copied
you can't save movieclips in a text file. do you want to save their names in a text file?
Copy link to clipboard
Copied
exactly..Yes!!!!
Or feeding data automatically into a excel sheet.
Please advise.
Thank You.
Copy link to clipboard
Copied
use the urlloader class to save those names to your server-side script.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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; }
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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;
}
Copy link to clipboard
Copied
Thank You so much for the kind reply.
Copy link to clipboard
Copied
you're welcome.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Thank u .
I would check that.
Copy link to clipboard
Copied
you're welcome.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now