View Full Version : Flash Questionnaire exports to XML
Hi,
Whats I need is a questionnaire in Flash that gathers the information and exports it to XML. Have any of you guys ever come across this?
Seems pretty tricky!
nDanil
11-24-2008, 05:03 PM
The trick thing about that is that flash cannot save files on a computer. So to dave collected data, you need to create a connection to a data service and send there your data to be stored.
Hey,
I'm today's new guy with a problem!
What I need is to make a questionnaire form in Flash that, when completed and submitted, exports the information entered by the user into an XML document.
Any ideas? I'm pretty lost needless to say!
Thanks for any help!
Hey,
I'm today's new guy with a problem!
What I need is to make a questionnaire form in Flash that, when completed and submitted, exports the information entered by the user into an XML document.
Any ideas? I'm pretty lost needless to say!
Thanks for any help!
wvxvw
12-05-2008, 10:25 AM
import fl.controls.Button;
var tf:TextField;
function generateForm():void
{
tf = new TextField();
tf.type = TextFieldType.INPUT;
tf.width = 300;
tf.height = 20;
tf.border = true;
tf.text = "Type your answer here";
addChild(tf);
var button:Button = new Button();
button.label = "Submit";
button.addEventListener(MouseEvent.CLICK, submitForm);
button.y = 30;
addChild(button);
}
function generateFormXML():XML
{
return <answer time={new Date().getTime()}>{tf.text}</answer>;
}
function submitForm(event:MouseEvent):void
{
var request:URLRequest = new URLRequest("whereToSubmit");
request.data = generateFormXML().toXMLString();
var loader:URLLoader = new URLLoader();
loader.load(request);
}
generateForm();
For this example to work you need Button component in the library. To do that hit Ctrl + F7, select the component, drag it to the stage, select it and hit Delete.
matbury
12-05-2008, 10:34 AM
Hi aj77,
Assuming that you already know how to create input text fields and get the input text from them, all you have to do is create an XML object in ActionScript 3.0 and use E4X notation to insert the text from the text fields into it.
I'd recommend designing your XML format first (i.e. the names and positions of the XML nodes) and then write your ActionScript to create it:
var myXML:XML = new XML();
myXML.myRootNode.myOtherNode.myFirstNameNode = "Eric";
myXML.myRootNode.myOtherNode.myLastNameNode = "Berne";
myXML.myRootNode.myOtherNode.myStreetNode = "101 Volkspielen Strasse";
trace(myXML);
This should return something like (I haven't tested this!):
<myOtherNode>
<myFirstNameNode>Eric<myFirstNameNode>
<myLastNameNode>Berne<myLastNameNode>
<myStreetNode>101 Volkspielen Strasse<myStreetNode>
</myOtherNode>
You can then send this XML object to a server-side PHP script to either write it to an XML file or convert and store it in a database.
You can see some examples of E4X in ActionScript 3.0 in Adobe docs: http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/XML.html#includeExamplesSummary
CyanBlue
12-05-2008, 11:04 AM
Please do not create multiple threads with the same qeustion... We don't allow that in this forum... Crossposts merged...
I see that you have posted the question on multiple forums that might not be correct place for your problem, AS2 and AS3 for example... AS2 and AS3 are totally different beast and the solution will be different most of the time... You might want to mention what version of ActionScript you are using, and whether this is a web application or a desktop application so that people can help you better and other people won't waste their time for something that you won't be ble to use...
Thanks for your help guys.
Apologies for posting multiple threads, I wasn't sure which was the correct one. It won't happen again.
Cheers!
Hey wvxvw,
Because I'm 100% new to this, is it the case that an XML form will have already to exist to export to, or will this generate one?
Thanks again for the help I'm chipping away at it!
import fl.controls.Button;
var tf:TextField;
function generateForm():void
{
tf = new TextField();
tf.type = TextFieldType.INPUT;
tf.width = 300;
tf.height = 20;
tf.border = true;
tf.text = "Type your answer here";
addChild(tf);
var button:Button = new Button();
button.label = "Submit";
button.addEventListener(MouseEvent.CLICK, submitForm);
button.y = 30;
addChild(button);
}
function generateFormXML():XML
{
return <answer time={new Date().getTime()}>{tf.text}</answer>;
}
function submitForm(event:MouseEvent):void
{
var request:URLRequest = new URLRequest("whereToSubmit");
request.data = generateFormXML().toXMLString();
var loader:URLLoader = new URLLoader();
loader.load(request);
}
generateForm();
wvxvw
12-05-2008, 01:17 PM
Huh... first, you can simply copy and paste the code and see what it does.
(What it does: it creates a single input text field and once you click the submit button it tries to send the generated XML to the "whereToSubmit" URL).
Also bear in mind that:
- to test this example you will need to configure your player security settings.
- if you want to be able to run test on your local computer, you will need a server installed on your computer (Apache for example), have it support for some server scripting language (PHP for example).
- have a server script ready to accept form's input.
Then, OK... there's no such thing as "form" in AS, so, you need to build that functionality using some lower level API, or you can switch to using Flex framework, where this and many other objects familiar to the web developer do exist.
yeah cheers I did that right away and I've been tinkering with it since then (adding extra fields etc)
I guess i can test it on a PHP configured server online, that won't be an issue.
Then, OK... there's no such thing as "form" in AS, so, you need to build that functionality using some lower level API, or you can switch to using Flex framework, where this and many other objects familiar to the web developer do exist.
You mean like just build a standard flash form using ui components and have it submit to the actionscript? Would that be possible? I've build them that export to a PHP mailer before I guess that could be useful...
Thanks again dude you're really digging me out of a hole here! :)
wvxvw
12-05-2008, 02:27 PM
Yes, something like that. I.e. HTML <form> has a sort of built in functionality of collecting the form's input, creating and sending the request, whereas the developer only needs to call document.forms[0].submit(). In AS you'd need to do all that work by yourself, or, as I mentioned, you can use an existing framework.
Would you like to know how to do it in Flex, here're the docs + example:
http://livedocs.adobe.com/flex/3/langref/mx/containers/Form.html
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.