A Flash Developer Resource Site














Internet Commerce

Partners & Affiliates














Developer Channel

internet.com


Featured Flash FLA
Gallery Downloads 11337 Flash Movies | 1 New Flash Movies Added
What's New | Top 100

Featured FLA

» Author: Bugra Ozden
» Title: Skatalog v9 - product catalog
» Description: Create your product catalog easly and publish on your website or Create your image gallery, documents list, portfolio. Fully XML Driven
» More by Bugra Ozden


Random FLAs | Add Flash Movie
Featured Flash Site
Gallery Downloads 5828 Flash Sites | 0 New Flash Links
What's New | Top 100 Flash Site

Featured Site

» Posted in the Flash Kit Links section
» Title: Creative DW Image Show PRO
» Description: Creative DW Image Show PRO is a Dreamweaver extension which enables the user to create multimedia presentations. It combines the features of the popular Creative DW Image Show with the ability to add professional text effects to slides (similar to After Effects). The product is very customizable: the user can choose the duration of the transition effects, the slide motion start and end position, zoom and panning type for both images and texts.


Random Links | Add your own Flash Related Links
Flash Tutorials 1280 Tutorials 7 New Tutorials Added!
What's New | Top100

» Make a Flash Slide Show Screen Saver
» Simple flash making tutorial for thanksgiving
» Create flash banner for website
» Create xml slideshow with free template
» How to Insert a Multilingual Subtitle Into Your Flash Video Studio
» How to Create Cool Halloween Slideshow
» Debugging flash using the Firebug console
» Create Flash Slideshow on Blogger
» FLASH TRICKS IN WEB ADVERTISING: FLASH BANNERS
» Unknown Tag: Title10
Random Tutorial | Add Site

Sr Instructional Designer D2L-Moodle,Clearance
WSI Nationwide, Inc.
US-NJ-Fort Monmouth

Justtechjobs.com Post A Job | Post A Resume


Tutorials Home What's New Top Rated Submit myTutes Random!

Search Tutorials


Tutorials Tutorials » Dynamic_Content

Categories Proxy Scripting in Flash - Loading External Data
Author: Jeffrey F. Hill | Website: http://www.flash-db.com |

 
Page 3
«prev 1 2 3 4 next»

Part II: Building Dynamic Requests

It is assumed that the readers of this article will be able to pass information/variables from the Flash movie to the Script, the method of which they are passed does not matter (ie Get, Post, attach to end of query string) - as long as they get their. This is accomplished with the LoadVariables Actionscript function.

Once the script is called it begins the process as follows: Builds the request variables. Puts the variables into the correct format. Builds the request Method (either GET or POST). Opens a connection to the external source and sends the request. Awaits the return of Information from the request. Then formats the data and prints it out to the page - which is then returned to the Flash movie. This is building a Form without a Form.

The below script is the basis for the above process. The script was written in PHP - the procedure should be the same for all scripting languages however. As an example we will open up a connection to Yahoo - but keep in mind that this can be any URL. Also note that the 3 variables we are sending to it - can be any variables. The Line by Line comments below the script will better help you understand what this is doing.

1)  <?php
2)  $FormURL    = "http://search.yahoo.com/search";
3)  $FormMethod = "GET";   // You can specify either GET or POST on this line.
4)  $FormData['p']	= $SearchTerm;  //SearchTerm would be a variable sent from the Flash movie.
5)  $FormData['o']	= '1';
6)  $FormData['n']	= $numResult;  //numResults would also be a variable sent from the Flash movie
 //numResults would be assigned to the a variable called n - for example.
7)  $QueryString = "";
8)  foreach ($FormData as $name => $value) {
9)     	if (strlen($QueryString)> 0)
10)      		$QueryString .= '&';
11)    		$QueryString .= $name.'='.urlencode($value);
12)  }
13)  $url         = parse_url($FormURL);
14)  $request     = $FormMethod." ";
15)  switch ($FormMethod) {
16)   	case 'GET':
17)      	       $request .= $url['path']."?".$QueryString." HTTP/1.1\r\n".
18)             "Host: ".$url['host']."\r\n\r\n";
19)      	       break;
20)    	case 'POST':
21)      	       $request .= $url['path']." HTTP/1.1\r\n".
22)             "Host: ".$url['host']."\r\n".
23)             "Content-type: application/x-www-form-urlencoded\r\n".
24)             "Content-length: ".strlen($QueryString)."\r\n\r\n".
25)             $QueryString;
26)      	       break;
27)   	default:
28)      		die("Must specify a form method");
29)  }
30)  $fp = fsockopen($url['host'], 80, $err_num, $err_msg, 30);
 // Submit form data
31)   	fputs($fp, $request);
 // Get the response
32)   	while (!feof($fp))
33)      		$response .= fgets($fp, 1024);
34)   	fclose($fp);
35)  Print "Results=$response";

Line 1: Starts off the script.

Line 2: Indicates which URL to request.

Line 3: Tells the script what request method to use - either "GET" or "POST".

Lines 4-6: These are variable/value combinations that you will be sending. You can either specify these in the script or send them from the Flash movie. As an example for this case - the variable 'SearchTerm' is sent from the Flash movie and assigned to a variable called 'o' which Yahoo bases the query on. These however can be any variable/value combo. Their is no real limit on how many of these you can have. Their will be a limit on the amount of data they contain if your sending a request via "GET" but in almost all case's you'll never reach that limit.

Lines 8-12: Builds the Query String that you will be sending.

Line 13: Parse's the URL and returns it's individual parts or components.

Line 14: Starts to build the request.

Lines 15-29: This is a switch statement (much like and If/then statement). If the request method is "GET" it will build a request using the "GET" method. If the request is "POST" it will build the request using the "POST" method. This is determined by what you specify in Line 3. Building the request method in this way simulates (exactly) what it would look like if you where to use a Form to submit this same data. This form however does not require any user interaction - and can technically be run at any time.

Line 30: The fsockopen function opens a socket connection to the URL we specified in line 2 of the script. It then assigns this info to a file pointer ($fp). This is then used in the next couple of lines.

Line 31: The next line uses the fputs function, this submits the request that we built in lines 15-29 to the connection we opened in line 30.

Lines 32-34: After we submit the request - the page will send back the results. These lines read in those results Line by Line and assign them to the variable $response.

Line 35: This will print out all of the data contained in the $response variable to the page. In this case - The results of this script would look exactly like what the web page who's URL we entered in on line 2 - Except on our server. As I mentioned earlier most of the time this data will come back as HTML (since most websites do not go out of their way to create a format that can easily be read by flash) - The hard part is formatting and parsing that data so that Flash can display it.

If you had a Dynamic text area called 'Results' in your flash movie - and you used LoadVariables to call this script - then the dynamic Text area called 'Results' would contain all the text data contained in the $response.

Wow that was sort of confusing. If you start playing around with the script and sending query's to different URL's it will become easier to see how to retrieve the Info back to the Flash movie. If you have any questions on this script you can ask them Here.

«prev 1 2 3 4 next»

» Level Advanced

Added: : 2002-04-05
Rating: 7.08 Votes: 27
Hits: 1736
» Author
Jeffrey Hill is a freelance web developer from Boulder, Colorado. He specializes in creating and developing dynamic database driven Flash content, applications, and content management systems. Specialty's include SQL, PHP, Perl, and XML.
» Download
Download the files used in this tutorial.
Download (18 kb)
Get conversion and unzipping tools for PC and Mac here!

» Forums
More help? Search our boards for quick answers!

Please rate this tutorial, 10 is the top rating, you can also click the comments link to read/write a review.
10 9 8 7 6 5 4 3 2 1
Read or Post Comments
 
   
 

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs