AS3 getURL / navigateToURL (How to make clickable links in AS3)


/ Published in: ActionScript 3
Save to your folder(s)

Shown in the source are the actual code, shorthand of the code, and Steven Sacks' simple-but-sweet rendition of getURL done in AS3, which requires the downloadable class from his site.


Copy this code and paste it in your HTML
  1. ///////////////////////////////////////////////////
  2. // Actual AS3 clickable-link code:
  3. my_btn.addEventListener(MouseEvent.CLICK, myBtnClicked);
  4.  
  5. function myBtnClicked(e:MouseEvent):void {
  6. var url:String = "http://www.example.com/";
  7. var request:URLRequest = new URLRequest(url);
  8. try {
  9. navigateToURL(request, '_blank');
  10. } catch (e:Error) {
  11. trace("Error occurred!");
  12. }
  13. }
  14.  
  15.  
  16. ///////////////////////////////////////////////////
  17. // Lazy shorthand. Reminder: navigateToURL SHOULD be in a try/catch
  18. my_btn.addEventListener(MouseEvent.CLICK, myBtnClicked);
  19.  
  20. function myBtnClicked(e:MouseEvent):void {
  21. navigateToURL(new URLRequest("http://www.example.com/"));
  22. }
  23.  
  24.  
  25. ///////////////////////////////////////////////////
  26. // Implementation of Steven Sacks' AS3 getURL class
  27. import net.stevensacks.utils.Web;
  28.  
  29. my_btn.addEventListener(MouseEvent.CLICK, myBtnClicked);
  30.  
  31. function myBtnClicked(e:MouseEvent):void {
  32. Web.getURL("http://www.example.com/");
  33. }

URL: http://www.stevensacks.net/2008/02/06/as3-geturl-solved/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.