I’m building a news section in a Flash website that loads news from a text file. So I made a News Update page in Flash to update the news file via PHP. What I want to do is have the Flash movie only display the 4 latest news entries. My problem is that I don’t know what to change in the PHP script to make the variable entries in the text file increase so Flash can identify new updates from old ones. ie title1, title2, title3…
Here is the PHP code:
<?php
$title = $_POST['Title'];
$comments = $_POST['Comments'];
$toSave = "Title=$title&Comments=$comments&";
$fp = fopen("news.txt", "a+");
fwrite($fp, $toSave);
fclose($fp);
?>
Here is the Actionscript of the movie I use to save the data:
submit.onPress = function(){
if(Title.text!="" && Comments.text !=""){
myData.Title = Title.text
myData.Comments = Comments.text
myData.sendAndLoad("save.php", myData, "POST")
}
}
stop()
& here is the actionscript of the movie that dynamically loads the text file:
myData = new LoadVars()
myData.load("news.txt")
myData.ref = this
myData.onLoad = function(success){
if(success){
for(var i=0; i<this.cant; i++){
this.ref["Title_txt"+i].htmlText = "<b>"+this["Title"+i]+"</b>"
this.ref["Comments_txt"+i].text = this["Comments"+i]
}
} else trace("Error loading data")
}
stop()
Notice how the “load file” has +i to determine which variable to load into which text box? I have 4 title text boxes & 4 comment text boxes setup in the “load file”, & I need to change the “save” script & PHP script so it makes sure only the latest 4 news entries display in the movie…
I am not very proficient with scripting, please help!