Trouble with php create xml file
Posted: Wed Dec 10, 2008 6:11 am
Hi Folks,
Im having trouble overide an xml file once i create it in php. You see what im trying do is put a value in avariable and make them dynamic so that when the button is pressed they dynamically change the xml when its pressed. This is because i want it the xml to hold information for bar chart which is display in flash which changes depending on user input e.g. sorta like a poll. Thing is the xml wont overide and doesnt change. It simple creates the xml and never changes it. How can i be able to overide the xml if i change any of the variables?
You see im creating a flash application that for my thesis is based around the golden ratio. The app teaches the user all about the golden ratio and then the user can eventually pick from a number of shapes (e.g. a button underneath the shape) to prove the user will always pics the most asthetically pleasing shapes made by the ratio. This inturn is displayed to the user in a bar chart that shows most people that have user the app previously picks that shape. I need the data to be saved in an xml because the chart pulls the values in from the xml and displays it in the swf for the user to see. So far i have the flash parsing to a php and then creating an xml with the values.here is my code so far :
Flash
stop();
var test:Number = 0;
this.chart_btn.onRelease = function(){
test += 1;
var result_lv:LoadVars = new LoadVars();
result_lv.onLoad = function(success:Boolean) {
if (success) {
status_txt.text = result_lv.return_msg;
// reset any values to start fresh here if needed
} else {
status_txt.text = "Sorry, cannot connect to the php file";
}
};
// Im just testing it on one value and one button at the moments e.g. test
var send_lv:LoadVars = new LoadVars();
send_lv.value1 = test
send_lv.value2 = "7"
send_lv.value3 = "2"
send_lv.value4 = "1"
send_lv.value5 = "9"
send_lv.sendAndLoad("parse_my_xml.php", result_lv, "POST");
gotoAndPlay("chart");
}
PHP
<?php
// Access the variables sent from flash here and place them into local php variables
$value1 = $_POST['value1'];
$value2 = $_POST['value2'];
$value3 = $_POST['value3'];
$value4 = $_POST['value4'];
$value5 = $_POST['value5'];
$xml_content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<chart>
<series>
<value xid=\"131\">A</value >
<value xid=\"132\">B</value >
<value xid=\"133\">C</value >
<value xid=\"134\">D</value >
<value xid=\"135\">E</value >
</series>
<graphs>
<graph gid=\"1\">
<value xid=\"131\">$value1</value>
<value xid=\"132\">$value2</value>
<value xid=\"133\">$value3</value>
<value xid=\"134\" color=\"#318DBD\">$value4</value>
<value xid=\"135\" color=\"#318DBD\">$value5</value>
</graph>
</graphs>
</chart>";
// XML file will be created in the same directory where this PHP file lives
$file_handle = fopen('amcolumn_data.xml','w');
fwrite($file_handle,$xml_content);
fclose($file_handle);
// Print message back to flash here automatically
$my_msg = "OK, file written, and it is on server waiting.";
print "&return_msg=$my_msg";
?>
im only testing one variable at the moment as you can see, just to chang the first variable dynamically. Should my php overide the xml evertime that button is pressed? or should i use a different command to do this? This has been wrecking my head for days . Im at the stage where i cant change my direction now due to time contraints, if i can just overide that xml everything the buttons clicked i will be sorted. I really hope you can help as im desperate
.
Peter
Im having trouble overide an xml file once i create it in php. You see what im trying do is put a value in avariable and make them dynamic so that when the button is pressed they dynamically change the xml when its pressed. This is because i want it the xml to hold information for bar chart which is display in flash which changes depending on user input e.g. sorta like a poll. Thing is the xml wont overide and doesnt change. It simple creates the xml and never changes it. How can i be able to overide the xml if i change any of the variables?
You see im creating a flash application that for my thesis is based around the golden ratio. The app teaches the user all about the golden ratio and then the user can eventually pick from a number of shapes (e.g. a button underneath the shape) to prove the user will always pics the most asthetically pleasing shapes made by the ratio. This inturn is displayed to the user in a bar chart that shows most people that have user the app previously picks that shape. I need the data to be saved in an xml because the chart pulls the values in from the xml and displays it in the swf for the user to see. So far i have the flash parsing to a php and then creating an xml with the values.here is my code so far :
Flash
stop();
var test:Number = 0;
this.chart_btn.onRelease = function(){
test += 1;
var result_lv:LoadVars = new LoadVars();
result_lv.onLoad = function(success:Boolean) {
if (success) {
status_txt.text = result_lv.return_msg;
// reset any values to start fresh here if needed
} else {
status_txt.text = "Sorry, cannot connect to the php file";
}
};
// Im just testing it on one value and one button at the moments e.g. test
var send_lv:LoadVars = new LoadVars();
send_lv.value1 = test
send_lv.value2 = "7"
send_lv.value3 = "2"
send_lv.value4 = "1"
send_lv.value5 = "9"
send_lv.sendAndLoad("parse_my_xml.php", result_lv, "POST");
gotoAndPlay("chart");
}
PHP
<?php
// Access the variables sent from flash here and place them into local php variables
$value1 = $_POST['value1'];
$value2 = $_POST['value2'];
$value3 = $_POST['value3'];
$value4 = $_POST['value4'];
$value5 = $_POST['value5'];
$xml_content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<chart>
<series>
<value xid=\"131\">A</value >
<value xid=\"132\">B</value >
<value xid=\"133\">C</value >
<value xid=\"134\">D</value >
<value xid=\"135\">E</value >
</series>
<graphs>
<graph gid=\"1\">
<value xid=\"131\">$value1</value>
<value xid=\"132\">$value2</value>
<value xid=\"133\">$value3</value>
<value xid=\"134\" color=\"#318DBD\">$value4</value>
<value xid=\"135\" color=\"#318DBD\">$value5</value>
</graph>
</graphs>
</chart>";
// XML file will be created in the same directory where this PHP file lives
$file_handle = fopen('amcolumn_data.xml','w');
fwrite($file_handle,$xml_content);
fclose($file_handle);
// Print message back to flash here automatically
$my_msg = "OK, file written, and it is on server waiting.";
print "&return_msg=$my_msg";
?>
im only testing one variable at the moment as you can see, just to chang the first variable dynamically. Should my php overide the xml evertime that button is pressed? or should i use a different command to do this? This has been wrecking my head for days . Im at the stage where i cant change my direction now due to time contraints, if i can just overide that xml everything the buttons clicked i will be sorted. I really hope you can help as im desperate
Peter