Solved

Create an xml file from a flash file

Posted on 2008-06-16
7
219 Views
Last Modified: 2011-10-03
K, so i am working on this project where all the calculations were going to be calculated and used in the flash file to use and display.  The scope has changed now so they want the results set to be exported to an xml file and the parsing and interface will be done somewhere else.  I work in php and know how I would do this in php but i have already written all the code in flash for the calculations and i dont want to spend the time to convert it all.  Is there anyway in flash to write an xml file to a server etc or would it be easiest to pass the information into php or something and try doing it that way.  How would i go about doing that if that was the best way?
0
Comment
Question by:Brant Snow
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
7 Comments
 
LVL 29

Expert Comment

by:fibo
ID: 21795991
The idea of working from data ->  php -> flash -> xml would frighten me, and I would shortuct the flash part. Most of the computations done there would probably easily be translated as php and xml...
0
 
LVL 43

Expert Comment

by:Rob
ID: 21798631
No you can do this easily with Flash by building the xml in flash based on your calculations and then send that data to PHP.

Use the XML class
// create an XML document
var doc:XML = new XML();
// create three XML nodes using createElement()
var element1:XMLNode = doc.createElement("element1");
var element2:XMLNode = doc.createElement("element2");
var element3:XMLNode = doc.createElement("element3");
// place the new nodes into the XML tree
doc.appendChild(element1);
element1.appendChild(element2);
element1.appendChild(element3);
// create two XML text nodes using createTextNode()
var textNode1:XMLNode = doc.createTextNode("textNode1 String value");
var textNode2:XMLNode = doc.createTextNode("textNode2 String value");
// place the new nodes into the XML tree
element2.appendChild(textNode1);
element3.appendChild(textNode2);
trace(doc);
// output (with line breaks added between tags):
// <element1>
// <element2>textNode1 String value</element2>
// <element3>textNode2 String value</element3>
// </element1>

Open in new window

0
 
LVL 43

Expert Comment

by:Rob
ID: 21798638
then you can use the sendAndLoad() function to send the xml to php.  this will wait for a reply from the php page.  if you don't need a response from the server then just use send()
var login_str:String = "<login username=\""+username_txt.text+"\"
password=\""+password_txt.text+"\" />";
var my_xml:XML = new XML(login_str);
var myLoginReply_xml:XML = new XML();
myLoginReply_xml.ignoreWhite = true;
myLoginReply_xml.onLoad = myOnLoad;
my_xml.sendAndLoad("http://www.flash-mx.com/mm/login_xml.php",
myLoginReply_xml);
function myOnLoad(success:Boolean) {
if (success) {
if ((myLoginReply_xml.firstChild.nodeName == "packet") &&
(myLoginReply_xml.firstChild.attributes.success == "true")) {
gotoAndStop("loggedIn");
} else {
gotoAndStop("loginFailed");
}
} else {
gotoAndStop("connectionFailed");
}
}

Open in new window

0
Major Incident Management Communications

Major incidents and IT service outages cost companies millions. Often the solution to minimizing damage is automated communication. Find out more in our Major Incident Management Communications infographic.

 
LVL 43

Accepted Solution

by:
Rob earned 500 total points
ID: 21798666
then in php you can pick up this XML in the $_POST['HTTP_RAW_POST_DATA'] variable

the other way to do this is to use the LoadVars object which just allows you to send variables to php like this:

var lv:LoadVars = new LoadVars();

lv.xml = "<element2>textNode1 String value</element2>";
lv.type = "Describe the type";

lv.send("http://mydomain.com/myscript.php");

so that in php you have

$_POST['xml'];
$_POST['type'];

etc
0
 
LVL 4

Author Comment

by:Brant Snow
ID: 21804156
But when i send the xml over to the php i didnt see you reference a file.  Where can i use $_POST['xml'];
$_POST['type'];?  

When it is waiting for a response from the php as you said what page or coding is that directed at?
0
 
LVL 43

Expert Comment

by:Rob
ID: 21810377
There isn't a need to reference a file as flash has built in capabilities to create an xml document on the fly, just like you would in php
0
 
LVL 43

Expert Comment

by:Rob
ID: 21818105
There are 2 ways you can send data and xml to PHP

1) using the XML class

2) using the LoadVars class
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SQL Stored Procedure Speed Improvements 6 55
Health check of winows and webservces 5 52
Change background images after 5 seconds. 12 48
SSL unsecure page mystery 17 47
The last time I worked with Flash and Socket connections was in AS1. A recent project required flash connecting to a Socket, and sending receiving information - we figured it would be easy enough - we all know about the socket policy documents and c…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The viewer will learn how to count occurrences of each item in an array.
The goal of the tutorial is to teach the user how to select the video input device. Make sure you have an input device that in connected and work and recognized by Adobe Flash Media Live Encoder and select it in the “video input” menu.

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question