View Full Version : Load dynamic variables with AS3
veclock
06-24-2008, 10:55 PM
I need to load some arrays from a file (php I thought should be easy) but it wont work. I found an example when I googled it, copied the code and tried it out, but the loaded variables vas undefined. I didn't upload them on a server, do I have to do that when it is php?
Can I use XML to load arrays? Or what else can I use?
Please help!
fentunfont
06-25-2008, 12:44 AM
xml can be an easy way, just format the data into xml at the php end and then pump it out to flash.
increasingly though its more common to use json (javascript object notation) as its more efficient since xml requires so many extra characters.
json isnt supported natively by actionscript and only in php from versions 5.2 (i think?) but there are plenty of libraries out there that support it in both environments.
veclock
06-25-2008, 12:08 PM
Do you have any examples?
And is it only possible to send the variables if the files are uploaded on a server?
PHP like most srver side scripts works only when uploaded to a server (if the server support PHP). You can also set up a PHP testing server on your computer (means intalling PHP tester on your computer) so then you'll be able to use your PHP scripts on your computer. Google that if you are interested in this solution but other than that, you have to upload!;)
veclock
06-26-2008, 11:55 AM
I installed Apache now, and it is working fine. But the variables stay undefined... what's the problem...? :o
http://www.kirupa.com/forum/showthread.php?t=101228
u can load arrays from xml yes
you can either put array contents in xml format or put whole array in
<xml>
<first>a</first>
<sec>b</sec>
</xml>
or
<xml>
<first>array[a,b]</first>
</xml>
depending on the method you can then use E4X notation to access different nodes in the XML and say youre using method 2 you can use a loop or sub.strng to access different variables.
first method will be easiest but less dynamic
xml.first
xml.sec
I installed Apache now, and it is working fine. But the variables stay undefined... what's the problem...?
check ur url to your PHP FILE, should be localhost:port/etc etc
or leave it like file.php and move all contents [swf] to apache folder etc
veclock
06-26-2008, 02:12 PM
Thx, I'll try the XML-stuff if the php doesn't work. Oh btw, do I need to upload an xml to see if it works?
Anyways... I didn't place the files in localhost, that's probably why it didn't work...? Only problem is I don't know where localhost is. :S
Edit: your link unfortantly shows how to do it with AS2, not 3. :(
veclock
06-26-2008, 09:26 PM
The apache and php5 install works fine! I guess it's something wrong with my php code.
Never mind, I will use xml, it's much better! :)
Thanks alot for the help!
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.