Posted By

Winkyboy on 10/27/08


Tagged

link getURL Website as3 navigateToURL


Versions (?)

Who likes this?

8 people have marked this snippet as a favorite

SmpleJohn
THEPWN3R
peterbelsky
tspitzr
vitor_np
elkraneo
deers
Josueriv


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


 / Published in: ActionScript 3
 

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

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.

  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. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: ddegner on February 28, 2009

my_btn.pack.addEventListener(MouseEvent.CLICK, myBtnClicked);

function myBtnClicked(e:MouseEvent):void { try { navigateToURL(new URLRequest("/index.php"), "_self"); } catch (e:Error) { trace("Error occurred!"); } }

Posted By: Winkyboy on November 18, 2009

damarev has a nice packaged AS3 getURL : http://snipplr.com/view.php?codeview&id=14015

Posted By: nuthman on March 3, 2010

I created a very simple getURL class as well if anyone is interested: http://www.as3blog.org/?p=18

Posted By: nuthman on March 3, 2010

Oops, sorry about that last link.. here is the correct one: http://www.as3blog.org/?p=40

Posted By: sksadi on March 23, 2011

I am having the following problem. Can any one help me please.

1120: Access of undefined property btn_Enter.

btn_Enter.addEventListener(MouseEvent.CLICK, myBtnClicked);

Posted By: ericbanaa19 on March 4, 2019

You need to declare your URL request. This is quite plenty a fancy way of retaining the URL. You could surprise, why you need a URL request to keep the URL whilst you could just use the string itself? Well, the solution is because you can use the identical URL request with many unique capabilities. Source by Cheap Australian Assignment Service - AllAssignmentHelp.Org

You need to login to post a comment.