I'm currently writing a webcam program (like in Facebook's profile picture) in AS3 and I would like to be able to save the drawn picture to the server when c开发者_如何学Pythonlicking a button on my site. Is there any way of doing this? Do I need to create a socket or is there an easier way of doing it?
Pierre
The Flash plugin runs on the client, the PHP script runs on the server. You always have to establish some kind of remote connection between the two. Using a client side button to start a server side script that triggers a client side function to send data to the server seems quite unpractical, but it is certainly possible.
The way I see it, there are basically four ways to implement the functionality you want:
When the button is pressed, use ExternalInterface to call a Flash method and retrieve the image data as ByteArray via JavaScript, then connect to your PHP script via AJAX.
Use ExternalInterface to trigger a Flash method that connects directly to the PHP script and sends the image data as ByteArray via URLLoader (without AJAX).
Establish a socket connection from the Flash content, then use ExternalInterface and JavaScript to trigger a Flash method, which then sends the image through the socket.
Establish a socket connection from the Flash content, then add an event listener to listen to an event that is sent from the server when the button is pressed, and trigger a Flash method that then sends the image to the server.
In addition to the client-server-client problem I mentioned above, I would strongly advise against socket connections, unless you have highly interactive or time critical content, such as chats or multiplayer games (you bind your server's resources during the entire time a user is on the page). If all you need is to create a single connection to send the data, use either 1. or 2.
You can do this by creating a URLLoader and passing an URLRequest to its load method. Just set set the request method to POST
and put what you want to upload inside data
.
If you want examples just search using the two class names above as keywords.
On the server side (the PHP script, that is) you need to expect that sent data and save it on the server. Also returning a succeeded/failed message would make sense.
Good luck,
Alin
精彩评论