accessing php variables with actionscript

  • M12
  • Born
  • Born
  • M12
  • Posts: 1

Post 3+ Months Ago

I'm still learning how actionscript and php work together. Here are some sample files:

http://eltania.net/m12/testPHP.php
http://eltania.net/m12/test.swf

flash source:
http://eltania.net/m12/test.fla

The swf file is supposed to display a variable named "testData", located in the PHP file. But right now, it only reads "undefined". I would appreciate any help, since the deadline of a project is approaching. Thanks heaps man.

To make things easy, here is the actionscript source:

testData_load = new LoadVars();

testData_load.onLoad = function () {
var tdata = testData_load["testData"];
}

_root.testData_load.load("testPHP.php");

this.txt = _root.tdata; <-- (this line sets the text to display the variable's value)

And here is the PHP code:

<html>
<body>
<?php
$testData = "working";
echo "testData=".$testData;
?>
</body>
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • IceCold
  • Guru
  • Guru
  • User avatar
  • Posts: 1254
  • Loc: Ro

Post 3+ Months Ago

The php output format is ok.
The flash code is ok, except one thing: the scope of the variable tdata.
You declare tdata inside a function, so it is only available in that function.
Remove the "var" from there and it will work, since if it is not declared as variable in the function, flash assumes that it is a variable available for the current movieclip.
You can have also
Code: [ Select ]
var tdata:String;
testData_load = new LoadVars();
testData_load.onLoad = function () {
tdata = testData_load["testData"];
}
testData_load.load("testPHP.php");
this.txt = tdata; <-- (this line sets the text to display the variable's value)
  1. var tdata:String;
  2. testData_load = new LoadVars();
  3. testData_load.onLoad = function () {
  4. tdata = testData_load["testData"];
  5. }
  6. testData_load.load("testPHP.php");
  7. this.txt = tdata; <-- (this line sets the text to display the variable's value)

Post Information

  • Total Posts in this topic: 2 posts
  • Users browsing this forum: No registered users and 6 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.