Display html data from database as flash?
I want to display html(text) data into fla开发者_开发百科sh .Is there any way to do this dynamically? I am able to do this by creating an external xml file but how is it possible to do the same job without creating the external xml file using php and database? thnks..
Flash is a client side script and to access Database you need to use server side scripting which is PHP. Follow these steps:
- Use PHP to connect to DB
- Obtain Data or Store Data using MVC or simple PHP file whichever you are comfotable with.
- Obtain Data in XML format or Store it by parsing from a POST variable as you do in HTML forms.
- Use flash to talk to PHP rather than direct Database.
If you are worried about direct access to PHP then find a way to encrypt your call to PHP so it only responds from flash and not from any other headers. Maybe someone else can put some more details in for you.
Also see http://www.kirupa.com/developer/actionscript/flash_php_mysql.htm
An alternative to having Flash contact the a php page to get the text is to have the server generate the flash dynamically (providing it is not too complex) using, for example, the Ming or SWF Libraries.
You also have the option to use some of Flash's more advanced built-in remoting tools. If you are running PHP on your back-end, for instance, you could set up AMFPHP or ZendAMF. What this does is open a binary socket connection between the server and your client, and if you set it up right then you can alias remote classes to local classes and vice versa. So for instance you could define a "UserModel" class in Flash and a UserModel class in PHP, and then tell Flash to treat them as aliases of each other.
What this basically lets you do is make remote server calls as though they were local method calls.
Every major Flash project I've been on has used this approach. It's much faster than XML, you don't need to worry about parsing XML or JSON, and you can make remote method calls nicely. This works best if coupled with some sort of MVCS framework like RobotLegs, because then you can abstract away the server calls entirely - but that may be more complex than what you need, depending on what you're doing.
But, the long and short of it is that Flash can't talk to a database directly.
ACTUALLY, one more thing comes to mind - Omar Gonzalez has been working on something called MongoAS3, which allows flash to connect directly to a MongoDB database instance. It would require that your database be a NOSQL MongoDB rather than a standard MySQL but it might be good for your needs: http://www.mongoas3.com/
精彩评论