Hey guys, I used Unity3D to make flash menu for a webpage (to have kind of fancy 3D transition), the old one made by another guy, it calls this funtion: from this js file: How can I do the same thing using Unity and export to Flash? I tried Application.ExternalCall, but nothing happen when clicking. After some digging it turns out that is not possible. Since I have no knowledge of Flash and ActionScript, I would be very appreciated if you guys can give me as much detail as possible. Thank you
As Flash is still in preview, this is actually the correct forum for this. @ovakin; It's likely we'll change somethings in the future and have Application.ExternalCall work like it does on other platforms. In the mean time, this should help. Code (csharp): void Start () { ActionScript.Import("flash.external.ExternalInterface"); bool available = ActionScript.Expression<bool>("ExternalInterface.available"); if(available){ var functionName = "alert"; var arg0 = "Hello From Unity!"; ActionScript.Statement("ExternalInterface.call({0},{1});", functionName,arg0); }else{ Debug.Log("ExternalInterface not available"); } } Be aware that normal flash security restrictions apply and for local testing you'll either need to serve this up from localhost, or add the directory of the swf file as a trusted location in the flash player debugger.
Thank you UnityRalph, I put it in my script: Still nothing happened when click. Do I need to have something in the Assets\ActionScript folder? Please bear with my noobness
You probably still have to correctly setup the security settings as I've mentioned above, or debug on localhost. Try and setting up a Flash debugging player with this guide and check out the errors; http://unity3d.com/unity/publishing/flash# ( (How do I debug generated flash content?)
YAY! I got it finally! Thank you UnityRalph for your support, though I found a way that easier for me to understand: Code (csharp): function Goto(site:String) { ActionScript.Import("navigation"); ActionScript.Expression.<String>("navigation.goCommand({0})", site ); } navigation.as Code (csharp): package { import flash.external.ExternalInterface; public class navigation { public static function goCommand(site:String) { ExternalInterface.call("redirectContent",site); } } }
Hello Ovakin, and to all Unity users who reference this thread: Ovakin's solution works and the one suggested by UnityRalph does not; there currently seems to be a problem with invoking ExternalInterface.call directly with either ActionScript.Statement or ActionScript.Expression (the latter won't even compile for me without throwing all sorts of errors)... I struggled with this until trying the method Ovakin provided - i.e., using ExternalInterface.call within a separate ActionScript file rather than in a Unity script. Thank you Ovakin (I'll report this apparent bug).