Copy link to clipboard
Copied
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!!
Copy link to clipboard
Copied
there's no problem with the code you showed (except maybe that path to your php file).
Copy link to clipboard
Copied
Hey mate thanks for the reply. The path is correct as well..
Both try.php and header.swf are in 0000 directory.
hard to figure out the problem.
Copy link to clipboard
Copied
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.html
if that fails, upload your files to a server and confirm everything works. then start working on your local configuration.
Copy link to clipboard
Copied
Hi kglad
I changed the settings.. didnt help.
I uploaded on the server and checked.. it is not working.
I'm uploading the files.. Any help would be highly appreciated.
http://infinitywebconsultants.com.au/AS3_PHP.zip
Thanks
Copy link to clipboard
Copied
i don't download and correct files unless i'm hired.
but here's your file working (click button to call your php file): http://www.kglad.com/Files/forums/Untitled-1.html