Search Unity

[FLASH] How to call html javascript ?

Discussion in 'Flash' started by ovakin, Mar 18, 2012.

  1. ovakin

    ovakin

    Joined:
    Dec 18, 2011
    Posts:
    37
    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 :D
     
  2. alex97

    alex97

    Joined:
    Nov 27, 2011
    Posts:
    45
    that is not the place for assking its for develop preview! you can try in other.
     
  3. RalphH

    RalphH

    Administrator

    Joined:
    Dec 22, 2011
    Posts:
    592
    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):
    1.  
    2. void Start () {
    3.         ActionScript.Import("flash.external.ExternalInterface");
    4.         bool available = ActionScript.Expression<bool>("ExternalInterface.available");
    5.         if(available){
    6.             var functionName = "alert";
    7.             var arg0 = "Hello From Unity!";
    8.             ActionScript.Statement("ExternalInterface.call({0},{1});", functionName,arg0);
    9.         }else{
    10.             Debug.Log("ExternalInterface not available");  
    11.         }
    12.     }
    13.  
    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.
     
  4. ovakin

    ovakin

    Joined:
    Dec 18, 2011
    Posts:
    37
    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
     
  5. RalphH

    RalphH

    Administrator

    Joined:
    Dec 22, 2011
    Posts:
    592
    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?)
     
  6. ovakin

    ovakin

    Joined:
    Dec 18, 2011
    Posts:
    37
    YAY! I got it finally!
    Thank you UnityRalph for your support, though I found a way that easier for me to understand:

    Code (csharp):
    1. function Goto(site:String)
    2. {
    3.     ActionScript.Import("navigation");
    4.     ActionScript.Expression.<String>("navigation.goCommand({0})", site );
    5. }
    navigation.as
    Code (csharp):
    1. package
    2. {
    3.     import flash.external.ExternalInterface;
    4.     public class navigation
    5.     {
    6.         public static function goCommand(site:String)
    7.         {
    8.             ExternalInterface.call("redirectContent",site);
    9.         }
    10.     }
    11. }
     
  7. mmiller

    mmiller

    Joined:
    May 19, 2012
    Posts:
    1
    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).