Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

How to open a link in a new window from Flash

Discussion in 'Flash' started by crawler, Aug 9, 2012.

  1. crawler

    crawler

    Joined:
    Aug 9, 2012
    Posts:
    27
    Hello! How to open a webpage link in a new window from Flash build?

    Here is a flash game Tail Drift by Cameron Owen
    http://unity3d.com/contest/flash-in-a-flash/

    Take a look at the bottom right corner after game loaded. There is Facebook and Twitter icons. If click the link opens in a new window.

    How he did this?

    Thanks!
     
  2. ParaLogic

    ParaLogic

    Joined:
    Aug 19, 2010
    Posts:
    177
    You can do it like this:

    1. Create a c# script in the "Plugins" folder named "CustomFlashStuff.cs" and paste this code:

    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. [NotConverted]
    5. [NotRenamed]
    6.  
    7. public class CustomFlashStuff {
    8.  
    9.     public static void openURLflash(string link){
    10.         Debug.Log ("This won't work until exported to a SWF");
    11.     }
    12.    
    13. }
    2. Create an AS3 file named "CustomFlashStuff.as" in a folder named "ActionScript" and paste this code:

    Code (csharp):
    1. package  {
    2.    
    3.     import flash.net.navigateToURL;
    4.     import flash.net.URLRequest;
    5.    
    6.     public class CustomFlashStuff {
    7.  
    8.         public static function openURLflash(link : String):void{
    9.             var request:URLRequest = new URLRequest(link);
    10.             navigateToURL(request, '_blank');
    11.         }
    12.        
    13.        
    14.  
    15.     }
    16.    
    17. }
    18.  
    3. To open a url simply call the code below anywhere in your script:

    Code (csharp):
    1. CustomFlashStuff.openURLflash("http://www.yoururl.com/");
    Hope that helps :)
     
  3. crawler

    crawler

    Joined:
    Aug 9, 2012
    Posts:
    27
    ParaLogic, thank you very much! It works awesome! :)
    With Respect!
     
  4. ParaLogic

    ParaLogic

    Joined:
    Aug 19, 2010
    Posts:
    177
    No problem! Glad it helped :)
     
  5. MichaelTkachuk

    MichaelTkachuk

    Joined:
    Jan 13, 2012
    Posts:
    8
    Wow. I thought only UnityShared.swc can be used to connect between falsh and Unity3D. Looks like i was wrong. Thanks for the point ParaLogic!
     
  6. mtoivo

    mtoivo

    Joined:
    Jul 30, 2012
    Posts:
    274
    My thanks to ParaLogic, too. I have struggled with (the lack of) XML-support on flash builds, and now managed to write a simple AS-wrapper that parses the given XML and provides identical methods to fetch data from it. Things I've learned today: UnityScript's Array doesn't convert to ActionScript counterpart (one of my method used to return an array of strings). Couldn't figure out how to return more than one variable from AS-method to unity, so variables are fetched one-by-one after the method call. After hacking that together, also learned that actionscript class-properties can't be accessed and getter/setter don't work either.
     
  7. ParaLogic

    ParaLogic

    Joined:
    Aug 19, 2010
    Posts:
    177
    That's why the flash exporter is still in beta ;) I suspect a lot more stuff will be supported when Unity 4 flash ships.
     
  8. GregorioDAngelo

    GregorioDAngelo

    Joined:
    Aug 26, 2013
    Posts:
    1
    Thank you !!!

    Saved my day...
     
  9. Soniface

    Soniface

    Joined:
    Apr 13, 2013
    Posts:
    1
    You helped me with this, Thank you ;)