PDA

View Full Version : Associative Array from external data


Maxil
02-08-2003, 03:13 PM
I need to know how i can create and fill an array of this kind via external source:

myArray[0] = ["alfa",1,["subAlfa1","subAlfa2","subAlfa3"]];
myArray[1] = ["beta",1,["subBeta1","subBeta2","subBeta3"]];
...


The source can be an external text file or dynamic data form ASP

Please, give me a code snippet!!

Thanks in advance, Maxil

freddycodes
02-08-2003, 04:33 PM
IMHO I would serialize it on the server with wddx. ASP can do it with a library so look it up on google. Get the wddx_mx.as file from macromedia's site,

http://www.macromedia.com/software/flashremoting/downloads/components/



Load the data in and deserialize it and you are done. This is MX only


#include "wddx_mx.as"
myWDDX = new WDDX();
myXML = new XML();
myXML.load("yourscript.asp");
myXML.onLoad = function() {
retVal = myWDDX.deserialize(this);
}




BAm now retVal holds your data structure. Try it you will be amazed.

CyanBlue
02-08-2003, 07:02 PM
WoW.... Freddycodes always shows me something I have never heard of almost EVERYDAY, and I am MAD!!! :D

Distributed Data Exchange (WDDX) FAQ (http://www.macromedia.com/v1/handlers/index.cfm?id=5622&method=full)
here in case someone, like myself, need to know what WDDX is...
and much more information about WDDX right HERE (http://www.macromedia.com/v1/handlers/index.cfm?ID=5624&Method=Full&PageCall=/developer/index.cfm)...

Do I need to get the FMX Remoting MX Components installed to get that wddx_mx.as file, you have mentioned, freddycodes??? I don't see any other link on that page rather than the Remoting stuff...

Okay, Maxil... I have answered similar question yesterday and you might want to take a look at this thread (http://www.actionscript.org/forums/showthread.php3?s=&threadid=22462&pagenumber=2) and get the file that I have attached, testlv.zip (http://www.actionscript.org/forums/attachment.php3?s=&postid=101621), to see if this one helps you... If you go over the thread, you will know why and what that file does...

Good luck... :)

freddycodes
02-08-2003, 07:33 PM
Firstly don't confuse remoting components with remoting. Flash remoting the beast that doesn't support php and costs an arm and a leg? No. The components whcih are just a set of actionscripts you can download from that page, yes. They are free and are not "Flash remoting"

I have stumbled across the greatest thing ever today. Using XMLSocket with PHP and wddx to create a real time data exchange. I will post more as soon as I whip up a sample and a PHP to access.

CyanBlue
02-08-2003, 07:41 PM
Oh... I guess I haven't paid much attention to the naming... As you have suspected, I thought that Flash Remoting and Flash Remoting Components are the same thing... Hehe...

Downloading... Approximately 15 more minutes to download that 6MB file with 56k... Oh... I want my cable back... Sigh... Why did I move to this apartment??? :(

freddycodes
02-08-2003, 08:01 PM
BTW if you want to know how to get started with PHP and wddx and Flash
http://www.actionscript.org/tutorials/advanced/Php_procedural_functions_from_within_Flash_MX/

freddycodes
02-08-2003, 08:11 PM
This is the same thing as the tutorial but its realtime through a socket connection.

http://www.irq11.com/~louie/freddyServer/freddyServer.html

If you have a PHP binary running with --enable-wddx and --enable-sockets let me know and I will put up the source.

This one actually accesses a php class and returns data from it.

CyanBlue
02-08-2003, 11:50 PM
Geez... There is no way I can consume that much information... That's just too much... :( I'll do some experiment when the project that I am currently doing is done... Thank you for the information... :)

Got a couple of questions though...If you have a PHP binary running with --enable-wddx and --enable-sockets let me know and I will put up the source.What do you mean by that PHP binary thing??? I have downloaded and installed PHP 4.3.0 installer, which is EXE version, from the www.php.net and it has nothing to do with what you are saying, right??? You are talking about the case when I am running PHP on the Unix/Linux shell, right??? I have no idea what you meant by '--enable-wddx and --enable-sockets'... Hehehe...

The example you mentioned is kinda the same thing that I have seen from the Scripting forum...(I think jimburton started the thread...) One thing I am not quite getting is that, I think, I can create the same thing which calls MySQL database with PHP in Flash... Can you briefly go over the advantages of using WDDX rather than MySQL database???

Thank you... :)

freddycodes
02-09-2003, 02:14 AM
Yes I mean compiling your own copy of php on unix. If you are windows, you simply uncomment the line in the php.ini that says
extension php_sockets.dll



Can you briefly go over the advantages of using WDDX rather than MySQL database???


I am using a MySQL database as well. wddx is merely the transport to get the data back to flash.

The advantage is, its less work to write your php scripts as if you were doing regular html, then use those same scripts to deliver the same data back to flash.

Lets take the example of using regular xml in flash. You have to loop through the results to get the data you want in flash right? wddx, you run deserialize and it its there like magic.

Its hard for me to get it across in words, one my add, two I havea hard time communicating what I am thinking
:rolleyes:

The example above is using sockets, the difference is it passes the data across a socket instead of through http, like flash's xml and LoadVars, it uses XMLSocket.

Read that tutorial and try to set the same thing up on your machine, thats really the only way to understand it.

CyanBlue
02-09-2003, 07:35 AM
Thank you for the kind answer, freddycodes... :Dwddx, you run deserialize and it its there like magic.Wow... This sounds fantastic... The only reason why I don't use XML in Flash much is that and if I can get rid of that... WoW... :D

I see lots of places I can utilize WDDX... I'll get onto it as soon as my project is done... I probably will have to bug you many many times though... :)

OApostle
09-28-2004, 02:40 PM
PS, XML input when created with .load() generates an associative array that does exactly what your asking.

The AS syntax to get at each element in the array is a bit funky, but if you can swing it, there are added efficiency bonuses for using xml. (low parsing times).

But then you have to know what all your array element names are, and thats my problem. haven't quite figured out how to get at them without knowing them ahead of time.

check out the xml object in the dictionary see if that helps.

-OA

CyanBlue
09-28-2004, 02:58 PM
Howdy and Welcome... :)
there are added efficiency bonuses for using xml. (low parsing times).
Uh... Are you sure about that??? The main reason why I don't use XML much in Flash is because Flash is really slow in handling the large chunk of text data plus long parsing time... Maybe I am wrong??? :(

freddycodes
09-28-2004, 04:52 PM
You are not mistaken, XML parsing comes at a price. XML is fine with small xml documents. Try loading a huge one, you'll see how damn slow it is at parsing XML.

On the other hand, parsing delimited text like csv in flash is light speeds faster than XML. Believe me when I say "been there, done that"

CyanBlue
09-28-2004, 05:28 PM
Thank you for clearing that up, freddycodes... :)
Yeah... I mostly try to utilize some sort of delimitered strings rather than the XML itself as much as I can...
(Speaking of which, my backend guy is having problem escaping the XML content that I need to draw graph with... :()

freddycodes
09-28-2004, 06:34 PM
Escaping xml content? Not sure I follow.

CyanBlue
09-29-2004, 01:40 PM
Hey... :)

Sorry... Didn't have time to log into AS.org... :(

I meant something like this... I am getting the content of the XML via FlashVars like this...
<PARAM NAME=FlashVars VALUE="camID=AWSHQ& ... ... ... &obs=<graph bgcolor%3D%22FFFFFF%22 ... ... ... </graph>">
So, all the strings like ", =, & should be escaped... That's what I meant... :)