lil_bugga
10-14-2010, 01:14 AM
I'm trying to create a form of dynamic gallery for my portfolio. My aim is to have all the content with a database (or linked from a database in some cases i.e. the database stores a link to an external file containing a description)
At the moment I have the php/mysql side of things working and it returns the information that I want. The bit I having issues with are on the flash/actionscript side of things. I'm still pretty new to both but feel I need to push myself with a project like this so that I actually do learn.
Anyway I went and created a dynamic text field (with text in for demo), saved it into a button movie clip and having made a note of position deleted it off the stage leaving it stored inside the libary.
Is there a way to change the textual content of the movie clip, I want the php code to return four words and then for each of those words to be displayed from the movieclip that is loaded to stage using as3.
Hopefully I've not baffled you guys, I dont think I explained it all that well.
Eye for Video
10-14-2010, 05:27 PM
Have not had much experience in PHP/Actionscript but here are a couple links to get yu started:
http://www.kirupa.com/developer/actionscript/flashphpxml_integration.htm
and
http://www.actionscript.org/resources/articles/141/1/Introduction-to-Flash-and-PHP/Page1.html
Lots of Flash and .xml integration tuts out there also.
EfV
BestFlashStock
10-15-2010, 08:46 AM
Hi, if you want to load variables into a Flash movie from a server-side script like PHP.
Recipe 19.2. Loading Variables from a Server-Side Script
Problem
You want to load variables into a Flash movie from a server-side script (ColdFusion, Perl, PHP, etc.).
Solution
Use the URLLoader.load( ) method in conjunction with DataFormat.VARIABLES as the dataFormat to read URL-encoded data generated by a server-side script into a Flash movie.
If you use PHP, perform output using echo or print from within a processing directive, such as:
<?php
$someText = "test";
echo "someText=$someText";
?>
and in AS3 do something like this
Recipe 19.2. Loading Variables from a Server-Side Script
Problem
You want to load variables into a Flash movie from a server-side script (ColdFusion, Perl, PHP, etc.).
Solution
Use the URLLoader.load( ) method in conjunction with DataFormat.VARIABLES as the dataFormat to read URL-encoded data generated by a server-side script into a Flash movie.
Discussion
The ActionScript to load variables from a server-side script is exactly the same as that used to load variables from a text file. When you call the load( ) method, you should pass it the URL of the script from which you want to load the variables, and then handle the results by listening for the complete event as shown in Recipe 19.1.
When the values for variables are generated from a database or another resource accessible only to the server, use server-side scripts as the source for variables loaded into the Flash Player. The script that you use must output URL-encoded data only, beginning from the first character. If you are writing a CGI script in Perl, the result is URL-encoded, so you won't need to make any special adjustments; for example:
#!/usr/bin/perl
# In a more practical example this value would be retrieved
# from a database or other server-side resource.
$someText = "test";
# Define the Content-Type header.
print "Content-Type: text/plain\n\n";
# Output the name-value pair.
print "someText=$someText";
However, when you use a ColdFusion page to generate variables to load into your movie, you need to take steps to ensure that it outputs URL-encoded data and that the output begins from the first character. Otherwise, extra whitespace characters may precede the output of the URL-encoded data, causing improperly decoded values. Here is what you should do:
Include the <cfsetting enablecfoutputonly="yes"> tag at the beginning of the document.
Make sure to enclose any values you want to output within a <cfoutput> element.
Place the whole document in a <cfprocessingdirective suppresswhitespace="yes"> tag. This ensures that no extra whitespace characters are output.
For example:
<cfsetting enablecfoutputonly="yes">
<cfprocessingdirective suppresswhitespace="yes">
<cfset someText = "test">
<cfoutput>someText=#someText#</cfoutput>
</cfprocessingdirective>
If you use PHP, perform output using echo or print from within a processing directive, such as:
<?php
$someText = "test";
echo "someText=$someText";
?>
Other preprocessor markup languages may or may not require additional steps to ensure proper output. JSP and ASP (.NET and classic) do not require any special considerations. One trick that seems to work in most cases is to simply surround each name/value pair with ampersands. This ensures that the variable delimiter is present so the variables can be correctly decoded by the Flash Player. This solution should work regardless of the language/platform you are using (ASP, JSP, CFML, etc.). For example, if you don't want to use the <cfprocessingdirective> and <cfsetting> tags in your ColdFusion page, you should be able to rewrite the preceding ColdFusion example as follows (note the ampersands in bold):
<cfset someText="test">
<cfoutput>&someText=#someText#&</cfoutput>
In each of the preceding examples, the server-side script returns a single variable, someText, to the Flash Player. The following example uses ActionScript code to load the variable from a script and display it in the movie:
package {
import flash.events.*;
import flash.net.*;
import flash.util.trace;
public class Example( ) {
public function Example( ) {
// Create the URLLoader instance to be able to load data
var loader:URLLoader = new URLLoader( );
// Define the event handler to be invoked when the load completes
loader.addEventListener( Event.COMPLETE, handleComplete );
// Configure the loader to load URL-encoded variables
loader.dataFormat = DataFormat.VARIABLES;
// Attempt to load some data
loader.load( new URLRequest( "getSomeText.cfm" ) );
}
private function handleComplete( event:Event ):void {
// Cast the event target as a URLLoader instance because that is
// what generated the event.
var loader:URLLoader = URLLoader( event.target );
// Access the variable(s) that were loaded by referencing the
// variable name off the data property of the URLLoader instance.
trace( "someText = " + loader.data.someText );
}
}
}
Best Flash Files (http://www.bestflashstock.com)