Using Actionscript 3 to connect to a database

落花浮王杯 提交于 2019-12-06 05:38:20

Unless you're running your Actionscript on the server side (I doubt that), connecting to a database directly wouldn't be very smart at all. To connect to a database from client side Actionscript you'd have to open your server to accept database connections from everyone, and you'd have to store access data in your swf files and that would be a disastrous combination in case someone disassembles the swf files.

If the size of the XML is prohibitive, you can always split it somehow, or if it is impossible, you can get the data from the server through PHP or anything else running on the server, for example, you'd give the relevant parameters in the request to the PHP file and the server side script then queries the database, builds XML text (that is a subset of the complete data, based on the given parameters) that can be consumed by the Actionscript.

If you plan to deploy your flash content to a website, you should use some sort of backend - otherwise you would have a potential security problem. I use remoting with AMFPHP, it has worked out really well.

Use a server-side language like PHP w/MySQL to write a text file or XML file that Flash can understand. in turn, when sending variables use ActionScript to send the variables to a PHP form parser that loads it to the server.

I don't have any examples to show you right now, but that would certainly be a workaround to getting FlashCon or some other product, and you can get started right away. Check out some XML and PHP code sites -- you'll probably run into someone who has already solved your problem.

vanhornRF

The general practice that I've experienced is that if it's something like a config file or just a really small amount of data then you could probably get away with just having an XML file on the server with your SWF files.

If you want the data to be more dynamic or you anticipate changing it quite often I would definitely do as Nouveau has already said and use PHP or a similiar technology to output database queries into an XML structure for your flash to load.

If there is a lot of data however and you are really noticing your program choking or lagging on loading up the XML in that format I would definitely recommend remoting like Kristian has suggested, AMFPHP seems to be one of the more popular choices.

Check out grapefrukt's answer to another question about flash and database interaction
Does Adobe Flash support databases?

just in case someone doesn't know the guys at midnightcoders have also a robust way for remoting in flash

you can also use swx format wich is an interesting project to send/receive data using swf's wrapers, i personally prefer amfphp but i just commented here for reference purposes

Don't use client side Actionscript to connect directly to the database, unless you're comfortable with the idea of exposing your connection string to anyone.

Use some server side logic to connect to the database instead.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!