Flash Vista - หนัาแรก
เว็บใหม่ล่าสุด
The Two Tales
เกี่บยวกับเว็บไซท์ | Archive
แนวิเกชั่นหลัก
หนัาแรก
ลิ้งค์มาใหม่
คะแนนสุดสุด
นิยมที่สุด
เลือกโดยบรรณาธิการ
ค้นหา

บทเรียนแฟลช
แหล่งข้อมูลแฟลช
ข่าว Flash
แฟลชเทมเพลท
แฟลชเทมเพลทอินโทร
Website Templates
แฟลชเกมส์
หนังสือแฟลช
FlashVista โพลส์
Sitemap


สุ่มลิงก์
English
The Connection by SONY
เกี่บยวกับเว็บไซท์ | Get another
FlashVista
เข้าสู่ระบบ
สมัครเป็นสมาชิก
สมัครรับจดหมายข่าว

เพิ่มลิ้งค์
แก้ไขลิ้งค์
รายการโปรด
แนะนำหมวด

โฆษณากับเรา
สนับสนุนเรา
Credits / Thanks
ติดต่อกับเรา

Flash Templates:

More Templates ...

รับจดหมายข่าว
ผู้ใช้

รหัดผ่าน



สมัครเป็นสมาชิก
ลืมรหัสผ่าน?
Partner websites
Free Hit Counter
Free Seo Tools
Free Tutorials
Free Video Tutorials
Forum signatures
Best Free Scripts
Wii Fit
Wii Fit News
Cool Tech Gadgets
Other Resources
แนะนำ
แนะนำเวบนี้ให้เพื่อน


รับจดหมายข่าว
สถานะ: ไม่ได้เข้าสู่ระบบ

Thai English German French Spanish Italian Portuguese Russian Polish Finnish Dutch Swedish Thai Romanian Traditional Chinese Simplified Chinese
ค้นหาไม่ได้เข้าสู่ระบบ
คำค้น: สิ่งที่ค้นหา: ค้นหาแบบกำหนดเงื่อนไข


How to Send Variables Between Flash and PHP


NEW Flash Tutorials in Video Format - Powered by LearnFlash.com: 45 minutes of flash tutorials now available in streaming format or download. Topics Include flash for beginners, text effects, actionscripting, audio/video, flash 8 and more.


Download the source file for this tutorial Printer version



By Joseph Miller
http://www.indivision.net

I had to learn a lot of this on my own via trial and error since there was little available on the net that adequately explained how it works. I'm hoping this guide will save someone the hours of hammering that I spent. Once you get a few fundamental things down, I think you will find, as I have, that a flash/PHP combination is easy to set up and offers a lot of flexibility. I included a very simple flash movie and script to go along with this guide. I recommend downloading and briefly going over all of the files before reading on.

How It Works

Loading variables from a PHP script is very similar to loading from a text file. The main difference is that the script performs work on a separate timeline. You can call a PHP script from a flash movie by using the LoadVariablesNum() command like so:

loadVariablesNum ("scriptA.php", 0, "POST");

Remember that your flash movie and the script are operating on separate timelines. The flash movie doesn't just stop when you make the LoadVariablesNum() command. Instead, it activates the script and keeps moving. When the script is finished operating, the data that has been printed by the script is read by the flash movie.

Loading Loop

Because the script is on a separate timeline, you need to create a loop in your flash movie that waits for the script to finish. Here is the code that I used in the sample .fla to make the loop:

if (loading eq "YES") {
gotoAndPlay (_currentframe-1);
} else {
gotoAndStop (1);
}

When you click on the button that loads the script, the sample .fla also sets the 'loading' variable to 'YES'. The movie knows when the script is done because it tells the movie that 'loading=NO'.

Setting POST

You may have scripts that do not need variables from the flash movie. In that case, you can leave the LoadVariablesNum() option set to 'Don't Send Variables'. Otherwise, you will need to set this option to 'POST' if you want variables to be sent into the script. Keep in mind that only the variables from the movieclip that contains the LoadVariablesNum() command will be sent!

Variables In PHP

Variables in a PHP script have a '$' in front of them. For example, the variable named 'who' in flash will be '$who' in the PHP script.

The 'Print' Statement

The data that the flash movie will eventually read is placed using 'print' statements. For an example of how print statements are used, refer to the file named: scriptA.php. Also note that all print statements in the script will be read at the same time. It's easy to make the mistake of thinking that you can control the actions of the flash movie according to the placement of a print statement. For example, in the sample files, I have it set up so that the 'loading' variable is set to 'NO' at the end of the script. If the script contained more commands after this print statement, they would also be included in the data that gets sent to the flash movie. In addition, if I put the line at the beginning of the script, it would really make no apparent difference to the output either.

Be sure to format your print statements so that the separate variables won't get 'smashed' together. Imagine that the results of the script will most likely look like one, continuous line. For example, if your script includes:

Print "dogs=fun";
Print "cats=boring";

The resulting data that the flash movie will read will look like:

dogs=funcats=boring

Because the movie won't be able to distinguish where variables start and end, you will end up with undesirable results. To make it work, you must include '&' between statements. For example, you might arrange the above data like this:

Print "&dogs=fun";
Print "&cats=boring";
Print "&fish=food";

The resulting data will now look like this:

&dogs=fun&cats=boring&fish=food

The '&' between the variable statements allows flash to read them each as separate statements.

Final Notes

I tried to narrow the information in this tutorial down to the things that caught me up the most. If you need to learn more about PHP, PHP.net and DevShed are great places to start. I will also answer questions posted on the forum at INDIVISION. Good luck and I hope this helps.

(เพิ่มไปแล้ว: 10-27-2003, ฮิต: 2, คะแนน: 3.24, โหวด: 62, คำวิจารณ์: 9)
เพิ่มในรายการโปรด แนะนำให้เพื่อน

คำวิจารณ์: (9)

i get this :

".$result;

print "

can someone explain what is wrong?

(เพิ่มไปแล้ว: 10-26-2006 ผู้ใช้: Guest)

i've got this, too:

".$result;

print "

(เพิ่มไปแล้ว: 08-15-2006 ผู้ใช้: Guest)

i get this in the textbox:

".result$;

print "

(เพิ่มไปแล้ว: 07-16-2006 ผู้ใช้: Guest)

Excellent!! Easy to Understand
(เพิ่มไปแล้ว: 04-15-2006 ผู้ใช้: Guest)

It would be easier with PHPObject - ghostwire.com/go/28
(เพิ่มไปแล้ว: 08-17-2005 ผู้ใช้: Guest)

Have been trying to find something like this for days nearly gave up, thank you very much.
(เพิ่มไปแล้ว: 04-07-2005 ผู้ใช้: Guest)

Thanks a lot!
Thats just the kind of simple and to-the-point tutorial i was looking for!

(เพิ่มไปแล้ว: 03-30-2005 ผู้ใช้: Guest)

that's OK, but what i I want to send variables containing '&' characters ?
(เพิ่มไปแล้ว: 03-27-2005 ผู้ใช้: Guest)

You will need to encode the special characters - instead of "&" you must write "%26". Read more about it at Macromedia:
http://www.macromedia.com/cfusion/knowledgebase/index.cfm?id=tn_14143

(เพิ่มไปแล้ว: 03-27-2005 ผู้ใช้: Philarmon )


เขียนคำวิจารณ์
Please note:
We review EVERY comment before it appears on the site, so please dont waste your time by posting spam links :)
No URLs allowed, no HTML please.

If you register or login first, your review will contain your nickname


ให้คะแนน



ดีที่สุด
ดีมาก
ดี
พอได้
ไม่ดี,ไม่สมบูรณ์