The process for creating the administration movie is almost identical for creating the NewsReader movie. The first thing to do is create the same textfields that are in the NewsReader movie. Create a dynamic textfield on the stage with the dimensions of width=400, height=300. Give this textfield an instance name of "article".Create another dynamic textfield with the dimensions of width=400, height=20 and place it above the article textfield. Give this textfield an instance name of "title". There are two extra objects needed in the admin movie. A button to send the data and a textfield to inform you that the data was saved successfully. Create a dynamic textfield named "msg"... width=200 height=20. Create a button and give it an instance name of "myButton". You can arrange these objects on the stage however you would like. Once everything is named and positioned, insert a new layer and name it "actions". Now it's time to provide the actionscript to power the first frame of this movie. Paste this code onto the first frame of the actions layer.
stop();
//Create the loadVars object to hold the data
container = new LoadVars();
//Create a variable to hold the file name for the data to be saved
container.myFileName = "saveAndLoad.txt";
container.myFilePath = "http://ntdesigns.net/";
//Handle the data when loaded
container.onLoad = function(success) {
if (!success) {
trace("Failed to load");
_root.article.text = "Failed to load. Please try again.";
} else {
trace("Data is loaded");
//populate the textfields with the container data
_root.title.text = _root.container.title;
_root.article.text = _root.container.article;
_root.msg.text = _root.container.msg;
}
}
//Load the textfile containing the data
container.load("http://ntdesigns.net/saveAndLoad.txt");
//Button event to update the textfile and NewsReader movie
myButton.onRelease = function() {
//send the name/value pairs to the text file
container.title = "&title="+_root.title.text;
container.article = "&article="+escape(_root.article.text);
//call the PHP script to write the data to the textfile
//generic "yoursite.com" is used as a demo path
container.sendAndLoad("http://yoursite.com/newsSaver.php", _root.container, POST);
//create a local connection to the NewsReader movie to update it real time
//This is an optional feature I added but is not necessary for the overall method to work.
myLocalConnection = new LocalConnection();
//send the updated data
myLocalConnection.send("incoming message", "onReceive1");
//close the connection
myLocalConnection.close();
//custom function to clear the return message from the PHP script
myInterval=setInterval(myLoad, 4000);
//repopulate the container data
container.load("http://yoursite.com/saveAndLoad.txt");
_root.nextFrame();
}
//Custom function to clear msg textfield
myLoad = function () {
_root.msg.text = "";
clearInterval(myInterval);
}
Notice the last line of code in the button handler is "_root.nextFrame". We need to provide a small delay for the data to be saved. Insert a new keyframe on frame 2 of the timeline.Paste this code onto the keyframe.
Remove the textfields and create a single movieclip.The movieclip will give a visual representation of the data being saved. Inside the new movieclip, create a shape tween of a bar growing in size. We dont want a stop action on the first frame because we want the movieclip to play as soon as the main timeline is sent to keyframe
2.On the last frame of this shape tween, put a stop action.Paste this code onto the last frame of the shape tween.
stop();
upDate.text="Click the link below to update your browser cache.";
_root.msg.text="Save Successful!";
We need to create a couple of textfields inside the movieclip to inform the user that the save is successful and provide a link to view the textfile in a browswer window to update the users cache. Insert a new layer above the shape tween.Insert a keyframe above the last frame of the shape tween. This is where we want to create our textfield. Create a dynamic textfield, height=20 width=450 and give it and instance name of "upDate".Create another dynamic textfield of the same dimensions and place it below the "upDate" textfield. For this textfield, we are going to use a variable name instead of an instance name. This makes transfering the variables from the main timeline to the needed textfield easy. Give this textfield a variable name of "_root.url". Now we need a button to allow the user to view the updated text file. Create a button of the same dimensions as the "_root.url" textfield.The button can be defined graphically however you like as long as the "_root.url" textfield is viewable. You can use a button with a blank first frame. On the button, paste this code.
on (release) {
getURL(_root.url)
}
We are almost done! Return to frame 2 of the main timeline. Change the instance name of the save button to "myBack_Btn". You have already pasted the code onto frame 2 to to handle the events for this button.Save this file as "NewsReaderAdmin" into the same folder with the NewsReader.fla. Now, the only thing left to do is to create the text file and the PHP script. The text file is easy enough. Create a textfile in the folder and name it "saveAndLoad". The only thing that needs to be modified on this file is when it is uploaded to your website. The chmod(permissions) for the text file need to be set to read/write capable(777).The textfile is used by both the NewsReader and NewsReaderAdmin movies. The PHP script will open the textfile and save the data to the textfile. The PHP file should be named "mySaver". Copy the code below to the PHP file.
Once everything is constructed, it must be uploaded to your website to test. Make sure to update the file path with the path to your website. The textfile permissions need to be set to read/write capable(777). This is just a simple external text editor but any content in a flash movie can be made externally editable with this method. The advantages may not be apparent with this limited demo, but allowing a customer to update content on their website without the need for a developer to modify an .fla file will allow you to create applications that can be self managed.
We hope the information helped you. If you have any questions
or comments, please don't hesitate to post them on the
Forums section Submit your Tutorial at Click Here