AS3 to PHP
Hey,
Just wondering how do i integrate a php file with flash to get and recieve variables through the php file from as3?
I would like to start off by putting as3 variables into php database.
Then i would like to connect with an as3 variable from php to change the variable to something from the database.
I know PHP so that isn't a problem
Thanks.
In that case, what you are asking for is beyond the level of effort you should expect in a forum. What you are asking for requires a tutorial level of response. "Hard" is a relative term, and you can only judge that relative to yourself.
As for your appraisal of tutorials, I disagree. I would say most show the code needed to support the lesson -- the problem for you might just be that the lesson is not what you really want to take the time to learn. That the code might seem advanced to you should be a clue that what you are trying to learn about is advanced.
If you come to a forum with something to show in the way of effort, and have relevant code to show that is not working for you, then you can often get detailed help. But if you come with a general "how do I" request, you should expect to be handed directions of where to go to find a lesson. If that happens enough you might eventually learn that you don't need to ask and can find informaton on your own. I have found that the Flash help documentation, Google, and trial and error can help me solve just about anything.
Similar Messages
-
Passing variables from AS3 to PHP
Hi there
I am having some trouble in passing variables from AS3 to PHP. I am using flash and php both in the same file [try.php].
I've stuck with this for two days.. Here's what I have done. Please help!!!
header.fla [Actionscript in the timeline]
stop();
import flash.events.Event;
import flash.display.Sprite;
import flash.net.*;
var url:String = "http://localhost/0000/try.php";
var req:URLRequest = new URLRequest(url);
var loader:URLLoader = new URLLoader();
var variables:URLVariables = new URLVariables();
send_btn.addEventListener(MouseEvent.CLICK, sendForm);
function sendForm(evt:MouseEvent):void
// add the variables to our URLVariables
variables.asd = "value";
// send data via post
req.method = URLRequestMethod.POST;
req.data = variables;
loader.dataFormat = URLLoaderDataFormat.TEXT;
// add listener
loader.addEventListener(Event.COMPLETE, onLoaded);
loader.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
//send data
loader.load(req);
function onLoaded(evt:Event):void
var result_data:String = String(loader.data);
if (result_data)
trace(result_data);
else if (!result_data)
trace("error");
function ioErrorHandler(event:IOErrorEvent):void
trace("ioErrorHandler: " + event);
try.php
<body>
<object id="FlashID" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="563" height="280">
<param name="movie" value="header.swf" />
<param name="quality" value="high" />
<param name="wmode" value="opaque" />
<param name="swfversion" value="6.0.65.0" />
<!-- This param tag prompts users with Flash Player 6.0 r65 and higher to download the latest version of Flash Player. Delete it if you don’t want users to see the prompt. -->
<param name="expressinstall" value="../Scripts/expressInstall.swf" />
<!-- Next object tag is for non-IE browsers. So hide it from IE using IECC. -->
<!--[if !IE]>-->
<object type="application/x-shockwave-flash" data="header.swf" width="563" height="280">
<!--<![endif]-->
<param name="quality" value="high" />
<param name="wmode" value="opaque" />
<param name="swfversion" value="6.0.65.0" />
<param name="expressinstall" value="../Scripts/expressInstall.swf" />
<!-- The browser displays the following alternative content for users with Flash Player 6.0 and older. -->
<div>
<h4>Content on this page requires a newer version of Adobe Flash Player.</h4>
<p><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" width="112" height="33" /></a></p>
</div>
<!--[if !IE]>-->
</object>
<!--<![endif]-->
</object>
<?php
if($_POST['asd'])
echo "value of var1 is <b>".$_POST['asd']."</b>";
else
echo "bad luck";
?>
</body>
BIG THANKS!!the problem is nothing your showed. did you see a security warning that you ignored?
to test, if that's the problem go here and adjust your security settings: http://www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager04a.ht ml
if that fails, upload your files to a server and confirm everything works. then start working on your local configuration. -
I have searched for a solution over many forums and none of the code seems to work. I cannot get AS3 to work with a php script.
I am trying to create a registration form in AS3
and then have that information go to mysql database when
the submit button is pressed. Here is part of the AS3 code: var variables:URLVariables = new URLVariables;
var varSend:URLRequest = new URLRequest("register.php");
varSend.method = URLRequestMethod.POST;
varSend.data = variables;
var varLoader:URLLoader = new URLLoader;
varLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
variables.userName = user_txt.text;
variables.userPass = pass_txt.text;
variables.userEmail = email_txt.text;
varLoader.load(varSend); Here is the php script "register.php": <?php $db_host = "localhost";
$db_username = "root";
$db_pass = "";
$db_name = "userregister"; mysql_connect("$db_host","$db_username","$db_pass" ) or die ("could not connect to mysql");
mysql_select_db("$db_name") or die ("no database"); $senderName = $_POST['userName'];
$senderPass = $_POST['userPass'];
$senderEmail = $_POST['userEmail']; $sqlCommand = "INSERT INTO user (username, password, email)
VALUES('$senderName','$senderPass','$senderEmail') "; $query = mysql_query($sqlCommand) or die (mysql_error()); $my_msg = "Thanks $senderName, all data has been sent."; echo "return_msg=$my_msg"; ?>there's no problem with your flash if your textfields are passing the correct values.
you have a table named user and it's failing to add passed variables? if yes, use fixed strings (instead of passed variables) in your php and test your php code. -
Trouble linking AS3 and PHP to create email form
I am using one of the Adobe cookbooks to create an email form for my flash website. I am SO close to getting this right and need some help! I used the AS3 code below as well as the PHP code below in order to create the email form. Everything seems to be working fine, that is until I try to send an email using the form. When I input all of the text into the form, I get the actionscript default warning I wrote that states "Oh no! Something is wrong! Try again..." Hence the email will not send. What could be wrong with the script? Or does it matter where I file the PHP file, my swf file, html file, and my fla file? I tried several combinations of filing everything together, seperate, and everything in between. Help! And thanks for anyone who can help!
ACTIONSCRIPT CODE USED:
stop();
Buttons
sendbtn.buttonMode = true;
sendbtn.addEventListener(MouseEvent.CLICK, submit);
resetbtn.buttonMode = true;
resetbtn.addEventListener(MouseEvent.CLICK, reset);
Variables needed
var timer:Timer; var varLoad:URLLoader = new URLLoader;
var urlRequest:URLRequest = new URLRequest( "mail.php" );
urlRequest.method = URLRequestMethod.POST;
Functions
function init():void{
//Set all fields to empty
yourName.text = "";
fromEmail.text = "";
yourSubject.text = "";
YourMsg.text = "";
function submit(e:MouseEvent):void{
//Check to see if any of the fields are empty
if( yourName.text == "" || fromEmail.text == "" ||
yourSubject.text == "" ||YourMsg.text == "" )
{ valid.text = "All fields need to be filled.";
//Check if you're using a valid email address
else if( !checkEmail(fromEmail.text) )
{ valid.text = "Enter a valid email address"; }
else { valid.text = "Sending over the internet...";
var emailData:String = "name="
+ yourName.text + "&from="
+ fromEmail.text + "&subject="
+ yourSubject.text + "&msg=" + YourMsg.text;
var urlVars:URLVariables = new URLVariables(emailData);
urlVars.dataFormat = URLLoaderDataFormat.TEXT;
urlRequest.data = urlVars; varLoad.load( urlRequest );
varLoad.addEventListener(Event.COMPLETE, thankYou );
function reset(e:MouseEvent):void{
init(); //call the initial clear function
function checkEmail(s:String):Boolean {
//This tests for correct email address
var p:RegExp = /(\w|[_.\-])+@((\w|-)+\.)+\w{2,4}+/; var
r:Object = p.exec(s);
if( r == null ) {
return false;
return true;
function thankYou(e:Event):void {
var loader:URLLoader =
URLLoader(e.target);
var sent = new
URLVariables(loader.data).sentStatus; if( sent == "yes" )
valid.text = "Thanks for your email!";
timer = new Timer(500);
timer.addEventListener(TimerEvent.TIMER, msgSent);
timer.start();
else {
valid.text = "Oh no! Something is wrong! Try again..."; }
function msgSent(te:TimerEvent):void {
if( timer.currentCount >= 10 ) { init();
timer.removeEventListener(TimerEvent.TIMER, msgSent);
PHP CODE USED
<?php $yourName = $_POST['name'];
$fromEmail = $_POST['from'];
$yourSubject = $yourSubject = $_POST['subject'];
$YourMsg = $_POST['msg'];
if( $yourName == true ) { $sender = $fromEmail; $yourEmail ="[email protected]"; (I have changed this to my email address, although not given in example)
$ipAddress = $_SERVER['REMOTE_ADDR'];
$emailMsg = "$ipAddress \n$yourName \n$sender
\n\n$YourMsg
\n\n\n--Memo for myself--";$return = "From: $sender\r\n" .
"Reply-To:$sender \r\n" ."X-Mailer: PHP/" . phpversion();
if( mail( $yourEmail, "$yourSubject", $emailMsg, $return
echo "sentStatus=yes"; }
else { echo "sentStatus=no"; } }
{ $sender = $fromEmail; $yourEmail ="$fromEmail";
$emailMsg = "\n\n\n--Memo for the sender. i.e. this is a copy of message you sent me.--
\n\n$yourName \n$sender
\n$YourMsg \n";$return = "From: $sender\r\n" .
"Reply-To:$sender \r\n" ."X-Mailer: PHP/" . phpversion();
if( mail( $yourEmail, "$yourSubject", $emailMsg, $return
echo "sentStatus=yes"; }
else { echo "sentStatus=no"; } }
?>It may be indeed a problem of your server rsp. how it handles security issues and relative path-linking.
You wrote: "Or does it matter where I file the PHP file, my swf file, html file, and my fla file..." I suppose you mean where to put all the files.
1.Its a good beginners choice to put all the files you need (swf, html, php you don`t need the fla file on ) in the same directory of your server.
2.If you publish to html from flash there will be three tags in the html (use a texteditor to look at the html-code) that read like this:
<param name="allowScriptAccess" value="sameDomain" />
change them for testing purposes to
<param name="allowScriptAccess" value="always" />
3.On some servers to prevent malicious code php scripts are restricted to certain directorys, look up the phpinfo on your server
4.Even if swf, html and php are in one and the same directory use a "hard" path in your fla file for testing purposes, for example instead of calling "file.php" in your actionscript, call ("http://www.mydomain.com/directory/file.php"), when testing from flash you may get a better response where the problem lies -
AS3 to PHP contact form, How to?
I have my AS3 all set up as follows:
InteractiveObject(thename.getChildAt(1)).tabIndex = 1;
InteractiveObject(theemail.getChildAt(1)).tabIndex = 2;
InteractiveObject(thephone.getChildAt(1)).tabIndex = 3;
InteractiveObject(themessage.getChildAt(1)).tabIndex = 4;
/* Mouse Click Event
Clicking on the specified symbol instance executes a function in which you can add your own custom code.
Instructions:
1. Add your custom code on a new line after the line that says "// Start your custom code" below.
The code will execute when the symbol instance is clicked.
Enter_btn.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler_2);
function fl_MouseClickHandler_2(event:MouseEvent):void
if (thename.text == "" || theemail.text == "" || thephone.text == "" || themessage.text == "")
thefeedback.text = "Please fill out all fields.";
else
// Creat a variable container.
var allVars:URLVariables = new URLVariables();
allVars.name = thename.text;
allVars.email = theemail.text;
allVars.phone = thephone.text;
allVars.message = themessage.text;
// Send info to url.
var mailAddress:URLRequest = new URLRequest("http://www.thewebsite.com/mail.php");
mailAddress.data = allVars;
mailAddress.method = URLRequestMethod.POST;
sendToURL(mailAddress);
thefeedback.text = "Thank You!";
thename.text = "";
theemail.text = "";
thephone.text = "";
themessage.text = "";
and my PHP code written as follows:
<?php
//Shows where to send the email.
//Shows what the subject will be in the email.
$to = "[email protected]";
$subject = "Website Reply";
//Headers to show the information sent.
$headers = " Name: " . $POST[thename] .
$headers = " Email: " . $POST[theemail] .
$headers = " 1: " . $POST[thephone] .
$headers = " 2: " . $POST[themessage] .
// once the variables have been defined, they can be included
// in the mail function call which will send you an email
mail($to, $subject, $headers);
?>
[/PHP]
What am i doing wrong i just get an empty email?
Can someone write out the needed PHP script and explain it?
I am compleatly new to this.It may be because your PHP is looking for the wrong variables. You send...
allVars.name = blah blah;
allVars.email = etc;
allVars.phone = etc;
allVars.message = etc;
but your php is trying to process the textfield names, not the variables you sent...
$headers = " Name: " . $POST[thename] .
$headers = " Email: " . $POST[theemail] .
$headers = " 1: " . $POST[thephone] .
$headers = " 2: " . $POST[themessage] . -
Does anyone know of an example that will show me how to have
a php file save to an xml file? I want to send a php file xml data
and have that xml data saved to a xml doc on my server.
Thanks!There are loads of tutorials on having PHP save text data to
a file, which
is all you need... I'd search on 'php save text flash' for
starters.
Dave -
www.offroadfire.com
Head Developer
http://www.blurredistinction.com
Adobe Community Expert
http://www.adobe.com/communities/experts/ -
Using AS3 in PHP maybe? something, anything?
I've posted about this earlier but still haven't figured out the best way to do this and i really need to figure it out now
My users create stuff on a stage. i save the changes they make on the server. what i need is a script that automatically creates a jpeg using the changes submitted by the user (this way the user doesnt have to send large image files to the server, just the small list of changes). i will then display the image of the stage to the user.
what would be perfect is being able to use php to call in a movieclip, add the changed paramaters, create the image - all on the server. Can some one point me in the right direction? does AMFPHP allow this sort of stuff? some sort of AIR application that monitors when users submit data?
Thank you so much, this has me a bit stumped and i want to make the process as efficient as possible!About ten years ago I did something similar to this using Director. I was building a series of coloring pages on the web that were turned into web cards. At the time, Director couldn't export a bitmap graphic from the web. Director could, however, edit a text file that was sitting on a server. So I took all of the data and wrote it to the text file, one line per card. I then had another copy of Director running on a computer that would download the text file, erase the content, and then use the downloaded text to recreate the user's web cards, give them unique names, upload them to a server, and write an email to each card recipient.
You should be able to do the same thing in Flash, using a php file to write out the data, and use that data to recreate the user's work. The potential points of failure are much higher using a php script than you would have by simply uploading the graphic that the user creates. -
EMAIL: AS3 to PHP → HELP?←
HERE IS MY FLASH ACTION SCRIPT TO SEND EMAIL FOR FORM. PLEASE HELP ME TO FIND WHAT I AM DOING WRONG
[CODE]
send_btn.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler);
function fl_MouseClickHandler(event:MouseEvent):void
if (theName.text == "" || theEmail.text == "")
theFeedback.text = "*Required.";
else
// Create a variable container
var allVars:URLVariables = new URLVariables();
allVars.box1 = box_1.text;
allVars.box2 = box_2.text;
allVars.box3 = box_3.text;
allVars.box4 = box_4.text;
allVars.box5 = box_5.text;
allVars.name = theName.text;
allVars.email = theEmail.text;
//Send info to url
var mailAddress:URLRequest = new URLRequest("http://www.paintedthetown.com/email.php");
mailAddress.data = allVars;
mailAddress.method = URLRequestMethod.POST;
sendToURL(mailAddress);
theFeedback.text = "Thank you :)";
box_1.text = "";
box_2.text = "";
box_3.text = "";
box_4.text = "";
box_5.text = "";
theName.text = "";
theEmail.text = "";
[/CODE]
THIS SEEMS TO BE WORKING BECAUSE I RECEIVE EMAIL BUT IT IS EMPTY (without info)
HERES THE PHP CODE
[PHP]
<?php
//Shows where to send the email.
//Shows what the subject will be in the email.
$sendTo = "[email protected]";
$subject = "Flash Reply";
//Headers to show the information sent.
$headers = " 1: " . $POST[box_1] .
$headers = " 2: " . $POST[box_2] .
$headers = " 3: " . $POST[box_3] .
$headers = " 4: " . $POST[box_4] .
$headers = " 5: " . $POST[box_5] .
$headers = " Name: " . $POST[theName] .
$headers = " Email: " . $POST[theEmail] .
// once the variables have been defined, they can be included
// in the mail function call which will send you an email
mail($sendTo, $subject, $headers);
?>
[/PHP]
WHAT AM I DOING WRONG??Hi,
to create a message, you could use
$message = "Mail from {$_POST['name']}
Email: {$_POST['email']}
1: {$_POST{'box_1'}
2: {$_POST{'box_2'}
note: you use theEmail and email in your actions. Your php will see "email" (the one used with the URLVariables)
Please avoid putting user-supplied info (such as email) into mail headers without filtering - someone could use your server to Bcc spam messages -
Contact forms in Flash (AS3/PHP)
Hello,
I have created a form in flash (CS5) using AS3 and Php.
The test run worked absolutely fine but now I have added the form to my (original) flash movie it has a number of errors come up...
Thing is that I've just spent the last 2 hours trying to get this form to work and having no success what so ever.
So does anyone know what the following complier errors mean and how I can solve this issue?
Scene 1
1152: A conflict exists with inherited definition flash.display:DisplayObject.name in namespace public.
ComponentShim (Compiled Clip), Line 1
5000: The class 'fl.controls.TextArea' must subclass 'flash.display.MovieClip' since it is linked to a library symbol of that type.
ComponentShim (Compiled Clip), Line 1
5000: The class 'fl.controls.TextInput' must subclass 'flash.display.MovieClip' since it is linked to a library symbol of that type.
ComponentShim (Compiled Clip), Line 1
5000: The class 'fl.controls.UIScrollBar' must subclass 'flash.display.MovieClip' since it is linked to a library symbol of that type.
ComponentShim (Compiled Clip), Line 1
5000: The class 'fl.controls.Button' must subclass 'flash.display.MovieClip' since it is linked to a library symbol of that type.
Yes, I'm obviously a newbie and still getting to grips with flash so any help would be amazing!
Thank you in advance,
Josadd those components to the library of your main (ie, loading) fla.
-
Hi - Still new to flash as3 and php -
it is a contact form page - user puts in information - i am to receive it in an email address their information
as well the variables get sent back from the php to the .swf file.
I am receiving these errors and not knowing how to fix them.
any help would be much appreciated. thank you in advance really.
below are the errors in flash - as3 code - and php code setup.
errors:
ActionScript 3 + PHP: TypeError: Error #2007: Parameter text must be non-null:
at flash.text::TextField/set text()
at kwangjaekim_fla::wholeform_16/completeHandler()
at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/flash.net:URLLoader::onComplete()
my as3 code is the following:
// build variable name for the URL Variables loader
var variables:URLVariables = new URLVariables();
//Build the varSend variable
var varSend:URLRequest = new URLRequest("contact_parse.php");
varSend.method = URLRequestMethod.POST;
varSend.data = variables;
//Build the varLoader variable
var varLoader:URLLoader = new URLLoader;
varLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
varLoader.addEventListener(Event.COMPLETE, completeHandler);
//handler for the PHP script completion and return of status
function completeHandler(event:Event):void{
//value is cleared at ""
name_txt.text = "";
contact_txt.text = "";
msg_txt.text = "";
//Load the response PHP here
status_txt.text = event.target.data.return_msg;
//Add event listener for submit button click
submit_btn.addEventListener(MouseEvent.CLICK, ValidateAndSend);
//function ValidateAndSend
function ValidateAndSend(event:MouseEvent):void{
//validate fields
if(!name_txt.length){
status_txt.text = "Please Enter Your Name";
}else if(!contact_txt.length){
status_txt.text = "Please Enter Your Contact Detail";
}else if(!msg_txt.length){
status_txt.text = "Please Enter Your Message";
}else {
// ready the variables in form for sending
variables.userName = name_txt.text;
variables.userContact = contact_txt.text;
variables.userMsg = msg_txt.text;
// Send the data to PHP now
varLoader.load(varSend);
submit_btn.addEventListener(MouseEvent.CLICK, function(){MovieClip(parent).gotoAndPlay(151)});
} // Close else condition for error handling
} // Close validate and send function
my php code is the following:
<?php
// Create local PHP variables from the info the user gave in the Flash form
$senderName = $_POST['userName'];
$senderEmail = $_POST['userContact'];
$senderMessage = $_POST['userMsg'];
// Strip slashes on the Local variables
$senderName = stripslashes($senderName);
$senderContact = stripslashes($senderContact);
$senderMessage = stripslashes($senderMessage);
//!!!!!!!!!!!!!!!!!!!!!!!!! change this to my email address !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
$to = "put iny me email address";
// Place sender Email address here
$from = "$senderContact ";
$subject = "Contact from your site";
//Begin HTML Email Message
$message = <<<EOF
<html>
<body bgcolor="#FFFFFF">
<b>Name</b> = $senderName<br /><br />
<b>Contact</b> = <a href="mailto:$senderContact">$senderEmail</a><br /><br />
<b>Message</b> = $senderMessage<br />
</body>
</html>
EOF;
//end of message
$headers = "From: $from\r\n";
$headers .= "Content-type: text/html\r\n";
$to = "$to";
mail($to, $subject, $message, $headers);
exit();
?>
thank you once again
jaythank you Ned -
i put in the trace line as you mentioned -
and this is what i received -
returns: undefined
TypeError: Error #2007: Parameter text must be non-null
at flash.text::TextField/set text()
at kwangjaekim_fla::wholeform_16/completeHandler()
at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/flash.net:URLLoader::onComplete()
what does this mean exactly?
thank you for the help really -
Save data to mysql using AS3 + Flash Builder(flex) OR AS3+AMFPHP? or AS3
Hi,
i just want to confirm with you guys about saving data to mysql using Action script 3.
I am now developing RPG game that user can save data again and again to the MySQL.
I searched on the net and found few solutions:
AS3 alone using URL Loader
AS3 + Flex +Php to save data to mysql
AS3 + AMFPHP to save data to mysql
This make me confused as there are too many options but i do not know which one is better for me
or what are their limitations...
Could you guys help me on this?For developing you can use the server (install like any other software), but the Zend framework is nothing more than php files, so all you need to do is upload the framework to you hosting server and all should be well.. You may have to configure a few things, but you should be able to do that yourself.
There's plenty of documentation on installing and configuring Zend on their website.
So, only get the server edition if you don't already have a dev server (on you computer) installed, like Apache. Otherwise, just grab the framework:
http://framework.zend.com/download/latest
Select "minimal package" on the page above to only get the framework (no install). Or grab both and see what each one does but the minimal package is what you need to upload to your hosting server.
As for where Flex/Flash Builder comes in.. FB is the tool you use to create a Flash/Flex application.
Zend, AMFPHP, etc.. is used to communicate with your backend from your application, using RemoteObject
RemoteObject API
http://livedocs.adobe.com/flex/3/langref/mx/rpc/remoting/RemoteObject.html
Using RemoteObject components
http://livedocs.adobe.com/flex/3/html/help.html?content=data_access_4.html -
I'm trying to learn how to communicate between PHP and Flash and have run into a problem. The PHP file loads albums and artists from a database. I can get the PHP file to load okay, but I cannot access a certain variable from the PHP file. Here is the PHP I am using:
<?php
$dbName = "database";
$place = "localhost";
$username = "username";
$password = "password";
$link = mysql_connect ($place, $username, $password);
mysql_select_db($dbName, $link);
$genreID = 4;
$query = "SELECT g.name, a.artist, a.albumName";
$query .= " FROM albums a, genre g";
$query .= " WHERE a.genreID=g.id";
$query .= " AND g.id=" . $genreID;
$result = mysql_query($query);
$response = "resp=loaded\n";
$index = 0;
while ($row = mysql_fetch_array($result)) {
$response .= " artist " . " = " . $row['artist'];
$response .= " album " . " = " . $row['albumName'];
$response .= " genre " . " = " . $row['name']. "\n";
$index++;
$response .= "total= ".$index;
echo $response;
?>
The variable I am trying to trace in Flash from the PHP file is 'total'. Here is the actionscript I am using:
package
import flash.display.*;
import flash.net.*;
import flash.events.*;
import flash.text.TextField;
public class Albums extends MovieClip
var phpFile:String = "http://localhost/getAlbums.php";
var displayText:TextField = new TextField();
public function Albums()
// constructor code
var urlRequest:URLRequest = new URLRequest(phpFile);
var urlLoader:URLLoader = new URLLoader();
urlLoader.addEventListener(Event.COMPLETE, callServerHandler, false, 0, true);
urlLoader.load(urlRequest);
if (urlLoader)
trace("loaded url");
else
trace("error loading url");
function callServerHandler(evt:Event):void
var loader:URLLoader = URLLoader(evt.target);
var dataObj:URLVariables = new URLVariables(loader.data);
trace ("Total Albums "+dataObj.total);
When I trace this in the output window I get 'Total Albums undefined'. Why would this be? Also if I just trace 'trace ("Total Albums " +dataObj.total);' Then I get the information from the php file but where there should be spaces inbetween the information I get '%20', how can I remove those?
Thanks for any information offered.
Ben.You might consider taking what is probably considered a more standard approach for interacting with a database, where you have the PHP file echo the output in XML format and have Flash take care of parsing the XML. That way, the total can be determined by the size of the data that you collect as an array and you don't need to have PHP provide it... though you still could.
I'd like to point you to a good AS3 tutorial for this, but I haven't found one (doesn't mean there isn't... you could try searching Google using "AS3 XML PHP tutorial"). When I started down this road I used an AS2 tutorial (http://www.gotoandlearn.com/play.php?id=20 ) to get the overall concept under my belt and followed up with an AS3 XML tutorial to deal with the different way than how AS2 processes XML. -
PHP variables limit ??
is there limit for varibiles in AS3 and PHP
i have the folowing AS3 code in my flash file
var data1:Array=new Array(5000);
var data2:Array=new Array(5000);
var variables:URLVariables = new URLVariables();
var varSend:URLRequest = new URLRequest("http://localhost/New Folder1/test.php" );
varSend.method = URLRequestMethod.POST;
varSend.data = variables;
var varLoader:URLLoader = new URLLoader;
varLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
varLoader.addEventListener(Event.COMPLETE, completeHandler);
variables.varx= "w123";
varLoader.load(varSend);
function completeHandler(event:Event):void{
var phpVar1 = event.target.data.var1;
var phpVar2 = event.target.data.var2;
data1 = phpVar1.split('**');
data2 = phpVar2.split('**');
and i have im my test.php
<?php
$string= "";
$string1= "";
$maxx=0;
$m=$_POST['varx'];
$c = oci_connect("*****", "****", "**************","AL32UTF8");
$s = oci_parse($c, "select * from mytable where id='$m'");
oci_execute($s);
PutEnv("NLS_LANG=AMERICAN_AMERCAN.AL32UTF8");
while (($row = oci_fetch_array($s, OCI_BOTH)) != false)
$maxx++;
if($maxx < 114 ){
$string .=$row[0]."**";
$string1 .=$row[1]."**";
print"var1=$string";
print"&var2=$string1";
?>
every things run good if the result less than 113 record, so i write in my code above if ($maxx <113),and if i remove if statment i got this :error #2101 the string passed to urlvariables.decode() must be a urlencoded query string contacting name/value pairs
and i have in my table 520 records so i cant understand where is the prolplem is there limit in varibles
and sorry for my languagethe problem is solved i change URLLoaderDataFormat.VARIABLES to URLLoaderDataFormat.TEXT
-
Highscore list using Flash and PHP
Hi,
I want to make a highscorelist using AS3 and PHP(MySQL).
I cant find a good tutorial on internet how to make something like that but I got this so far:
import fl.controls.TextInput;
import fl.controls.TextArea;
var variables:URLVariables = new URLVariables();
variables.name = "Wil";
variables.final = 2000;
var request:URLRequest = new URLRequest();
////insert in the location of the php script ////////////////
request.url = "http://www.justenter.nl/script.php";
request.data = variables;
var loader:URLLoader = new URLLoader();
loader.load(request); //sends the request
//when the request is done loading, it goes to the completeWriting function
loader.addEventListener(Event.COMPLETE, completeWriting);
function completeWriting(event:Event):void {
var writingCompleted:TextField = new TextField;
writingCompleted.autoSize = "center";
writingCompleted.x =200;
writingCompleted.y= 200;
writingCompleted.text = event.target.data;
addChild(writingCompleted);
He is sending the score and name to the database but he is doing that when i press ctrl-enter. He is sending the data I have given in:
variables.name = "Wil";
variables.final = 2000;
I want a input textfield and a button. And When I fill in my name in the input textfield he send it to the database when I press the button.
Is there someone that can help me out?
Tnximport fl.controls.TextInput;
import fl.controls.TextArea;
var variables:URLVariables = new URLVariables();
//variables.name = "Wil";
//variables.final = 2000;
var request:URLRequest = new URLRequest();
////insert in the location of the php script ////////////////
request.url = "http://www.justenter.nl/script.php";
request.data = variables;
var loader:URLLoader = new URLLoader();
submitBtn.addEventListener(MouseEvent.CLICK,submitF); // where submitBtn is your button
function submitF(e:Event){
variables.name=nameTF.text; // where nameTF is your input texfield
variables.final = score; // where score is the variable you use to tally user score
loader.load(request); //sends the request
//when the request is done loading, it goes to the completeWriting function
loader.addEventListener(Event.COMPLETE, completeWriting);
function completeWriting(event:Event):void {
var writingCompleted:TextField = new TextField;
writingCompleted.autoSize = "center";
writingCompleted.x =200;
writingCompleted.y= 200;
writingCompleted.text = event.target.data;
addChild(writingCompleted); -
PHP files and Flash contact form
Hello,
I am creating a website in flash CS4 and I made a contact form and when I test the site out, I can type and click the submit button, so everything is fine there but it doesn't go to anything. Now I know I need a code to tell the contact form where to go, but I can't find one that works, or I may be doing something wrong. I also have been reading about PHP but I am not sure what that is. I found a site that said to put this code in the actions panel.
on(release){
getURL("http://www.mail.menaceaudio.com", "", "POST");
The www.mail.menaceaudio.com is the site for the companies email.
So when I test it out this error comes up:
1087: Syntax error: extra characters found after end of program.The code you show is AS2, not AS3. Try searching for 'as3 form php' and you should find plenty of info.
PHP is a server-side scripting language. You put PHP files on your server and can then call them from Flash...
Maybe you are looking for
-
Safe to buy AC adaptors from Ebay for Satellite M105-s3041?
Hi, I have just lost my ac-power adaptor for my Satellite M105-s3041 computer. I want to get a replacement but I bought my computer in the US and am not sure a replacement would have a UK 3-pin plug. Also similarly to another guy on here I wonder if
-
Add custom fields in header of FI documents using FI_HEADER_SUB_1300IM
Hi We are trying to add a couple of custom fields in header area of FB01 by making a copy of badi FI_HEADER_SUB_1300IM. With this method we are facing a couple of problems - The custom fields added in bkpf structure, only appears in FB01 just in the
-
*** Can I add the email app that's on the iPhone?
I am in Canada so can't buy an iPhone but am considering an iPod Touch. My 2 main concerns I'm wondering about are: 1. Can I add an email icon (through installer.app maybe) to check my email when I hit a wi-fi spot? I don't want to have to go through
-
I'm air playing from redbox instant but only audio comes up on TV no video. What can I do to fix it?
-
Calling a transaction and return
Hi all, I need to call a transaction from a report and the control has to return back to the report after the called transaction is executed. The "Call Transaction" statement does not have the option to have the return to the calling program neither