Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / Flash / Data Integration / March 2007



Tip: Looking for answers? Try searching our database.

passing variables from a php file into an array

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
leaguer44 - 21 Mar 2007 03:12 GMT
hey guys,

i have successfully created a php file that reads and echoes the contents of a
directory in the string

var1=value2&var2-value2...

how would i got about passing these values into an array?
BorosAdam - 21 Mar 2007 17:52 GMT
you pass all the values as a huge string each value separated with a special
'separator' like '****' for example and then you can split the string in
flash... like this:
in php you have this string to pass to flash:
mydata=value1****value2****value3****value4 (and so on)
than in flash:
var myArray:Array = mydata.split("****");

is it enough? clear now?

adam
leaguer44 - 21 Mar 2007 18:29 GMT
thanks for the tip but when i try to trace the array to see if it was created
it says "undefined"

_root.createTextField("txtPos", 1, 5, 40, 100, 20);

var myData:LoadVars = new LoadVars();

myData.onLoad = function(success:Boolean){

     if(success) {

          var myArray:Array = this.split("****");
          trace(myArray);

     } else {

          txtPos.text = "Error loading data";

          }

}

myData.load("http://localhost/readdir.php");
BorosAdam - 22 Mar 2007 10:05 GMT
yes, because you try to split the LoadVars object! watch, you write:
myData.onLoad.... and then: this.split... in this case the word 'this' refers
to myData but your string is INSIDE myData! for example if you write in php:
stringed=value1****value2****value3... and so on, then in flash:

myData.onLoad = function (ok){
  if (ok){
    trace(myData.stringed);
    var myArray:Array = myData.stringed.split("****");   //or you can use:
this.stringed...
  }
}

because the received variable ("stringed" in the example) is placed INSIDE the
LoadVars object!!! clear? :)

adam
leaguer44 - 22 Mar 2007 16:04 GMT
makes sense...thanks...and i got it working but i have another question

so the only way i can reference that array data is by putting the code that
needs to use that data inside that If statement that checks if it was loaded
successfully?...or is there away to make the array global?
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.