简体   繁体   中英

Passing variables from a PHP script to 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?

Thanks in advance!

Aaron

You cannot asynchronously send 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.

A third option would be to use the 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:

  • Choose the 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, eg using the query-string: myflash.swf?previewUrl=<?php echo $previewUrl;?>
  • Choose the 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.
  • Choose the 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM