¿Pasar variables de un script PHP a Flash ActionScript 3.0?

I have an image uploader that runs on a separate PHP script, and then updates the Preview Url after the file has been uploaded. But what I'd like to do is have a Flash SWF embedded in the same HTML that's running the PHP Uploader to get that Preview URL and display it in the Flash Application.

What would you suggest be the best way to go about sending this PHP variable to Flash?

Gracias de antemano!

Aaron

preguntado el 27 de agosto de 11 a las 21:08

I think u can do this using flashVar. -

2 Respuestas

You cannot asynchronously enviar a value from PHP (server-side) to Flash (client-side). You have to either pass it in on embed-time through a flashvar (although I doubt this will work in your case since you want this transfer of information to occur after a load operation) or your Flash application will need to query the server, and have the server return the correct value.

Una tercera opción sería utilizar el ExternalInterface API in Flash to let your HTML notify the Flash application via javascript when the URL is available.

Since I don't know your general set-up, it's hard to recommend one way over another, but the general reasons for going with one over the other are:

  • Elija el flashvar approach if the value is known when the embedding HTML is loaded, so that you can pass it in to the SWF as it's being initialized, e.g. using the query-string: myflash.swf?previewUrl=<?php echo $previewUrl;?>
  • Elija el ExternalInterface approach if you are using an asynchronous approach (so the above is not possible) and the HTML/JS part of your application already is being notified. This way you can just invoke a javascript method on the SWF embed DOM object, and have it be received inside your ActionScript.
  • Elija el server query approach if none of the above works, but you have some way of knowing when the upload is complete. Just use a regular URLLoader to query the server for the preview URL, specifying the file id or similar as a GET or POST variable.

Hope this helps. Please elaborate on the details of your architecture for a more thorough answer.

Respondido 28 ago 11, 15:08

Respondido 28 ago 11, 01:08

I've seen the tutorial before actually, but I can't seem how to separate the receive and send actions so the AS3 only receives the variable. Thanks for the fast response. - Aaron

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.