Background | Data from last write article in Flash8 (Alert component plus response function!) ~http://space.flash8.net/bbs/thread-319211-1-1.html) After a long time did not move the text, I do not know if there is no raw embroidery. This time to write PHP and Flash, here to do a brochure example-Php&flash favorites, of course, this is only to explain how to implement variables and PHP write files.
my Idea (process):Write operations: Fill in the data into the form, click the button to save-> through PHP Write file Favorite.dat (you can also change to MySQL, should not be difficult). Read data: The dot refresh button-> read all the data through PHP-> back into the flash textarea (because textarea supports simple HTML, including <a href, of course). >). Delete: Leave your homework!
Description: Because only through a PHP file, so I set a change in flash $_post[a] used to separate out is to save or refresh, if not considered delete, you can directly change, in the PHP side to judge. If it is $_post, for the write data, the corresponding $_get is read data (the refresh here). Okay, here we go:
One: Open your Flash 8 create a new movie, here we need a few components 1. A textarea-> I named: Url_textarea. Here's the properties I set up to support HTML so that my URLs can be clicked, and someone asked: "Why not use the DataGrid, because I have not learned."
2. Two textinput-> are named: Webname_txt and Url_txt.
3. The three button-> are named: Save_btn and REFRESH_BTN.
4. As well as a few label for the description.
Two: Open code written on: Import Mx.controls.Alert; Join alert to pop up a message
var send_lv = new Loadvars (); Variables sent to the server
var save_lv = new Loadvars (); To save information returned from the server when saving
var refresh_lv = new Loadvars (); Information returned from the server when refreshing
/**
* Set the action to add a button
*/
Append_btn.onrelease = function () {
SEND_LV.A = "Save"; Using the Save method
Send_lv.name = Webname_txt.text; Site name
Send_lv.url = Url_txt.text; Url
Send_lv.sendandload ("favorite.php", Save_lv, "POST"); Send data to PHP
Webname_txt.text = Url_txt.text = ""; Empty text box
}
/**
* Set Refresh button
*/
Refresh_btn.onrelease = function () {
SEND_LV.A = "Refresh"; Refresh method
Send_lv.sendandload ("favorite.php", Refresh_lv, "POST"); Return data
}
Preservation effect
Save_lv.onload = function (Success:boolean)
{
if (success) {
Save_lv.msg is a message that is returned from PHP
Mx.controls.Alert.show (save_lv.msg, "Debug message", Alert.yes, _root, False, "Prueba", Alert.ok);
}
else {
Mx.controls.Alert.show ("error, failed to load", "Debug message", Alert.yes, _root, False, "Prueba", Alert.ok);
}
}
Refresh Response
Refresh_lv.onload = function (Success:boolean)
{
if (success) {
Mx.controls.Alert.show (refresh_lv.msg, "Debug message", Alert.yes, _root, False, "Prueba", Alert.ok); Pop-up information
Show in TextArea
Url_textarea.text = Refresh_lv.data;
}
else {
Mx.controls.Alert.show ("error, failed to load", "Debug message", Alert.yes, _root, False, "Prueba", Alert.ok);
}
}
Stop ();
Three: write that favorite.php I like to use the editor: EditPlus introduced to everyone to use, write code:
<?php
/***
* PHP & Flash Favorites
*
* The function to be implemented here is to use Flash to display and read text from PHP to
* To achieve a favorite folder function
*
* Storage structure of data
* $name | $url | $date |&| $name | $url | $date ....
*/
/**
* Implementation of Added functionality
* @ $name: Favorite site Name
* @ $url: Web site
*/
function append ($name, $url) {
$fp = fopen ("Favorite.dat", "A +"); Add mode
$flag = fwrite ($fp, "$name | $url |". Time (). "| &| "); Is the addition successful?
Fclose ($FP);
return $flag;
}
/***
* Realize read function
* Return: Array
*/
function Get_data () {
$f = "Favorite.dat"; The file to read
$fp = fopen ($f, ' R ');
$tmpdata = Fread ($fp, FileSize ($f)); Read all
Fclose ($FP);
$detail = Explode (' |&| ', $tmpdata); Decomposing data
For ($i =0 $i <sizeof ($detail)-1; $i + +) {
$out = Explode (' | ', $detail [$i]); One more time and it'll be ready to print.
$date =date ("y/m/d", $out [2]); Format Date
$ret _data. = "<a href= ' $out [1] ' > $out [0]</a>-[$date]<br>"; Format the data
}
Return "&data= $ret _data";
}
/***
* Determine what method is to save the data or click the Refresh button!
*/
if ($_post[a] = = "Save") {
if (append ($_post[name],$_post[url])) {
echo "Msg= Yes, has been saved";
}
else{
echo "msg= embarrassed, technical reason, failed to save:-(";
}
}
ElseIf ($_post[a] = = "Refresh") {
echo "msg= data come in, receive ..." Get_data ();
}
?> here is a point: be sure to remember to build a favorite.dat, because fopen (FP, ' A + '), here A + mode can not create new files, so you have to build good!
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.