Quick and easy GetURL class / actionscript 3 urlrequest

Here is a quick basic flash url loader for quickly adding links to buttons and movie clips in Actionscript 3:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// GetURL Class by Rick Nuthman
// 10.4.09
// Usage:
// new GetURL("url", "target");

package com.frigidfish{
   
    import flash.net.*;
   
    public class GetURL{
       
        private var request:URLRequest;
       
        public function GetURL(url:String, target:String = '_self'){
           
            request = new URLRequest(url);         
            navigateToURL(request, target);
           
        }
    }
}

It’s just a bare bones script that works like the old getURL() method from actionscript 2.
It defaults to opening the url in a blank page, but you can change this by modifying the 2nd parameter.

1
2
3
4
5
6
7
8
import com.frigidfish.GetURL;

// you can add it right to an event listener for a button or movieclip

yourButton.addEventListener(MouseEvent.CLICK, function(){ new GetURL("your_url.html", "_self")});

// or by itself
new GetURL("your_url.html");

I like using this because it makes the code a lot cleaner and easier to read when you have a bunch of links to deal with in Flash. Enjoy!

Share on FacebookShare on Google+Share on StumbleUponTweet about this on TwitterEmail this to someone

Facebook comments:

8 thoughts on “Quick and easy GetURL class / actionscript 3 urlrequest”

  1. man, I’m getting crazy with this f*cking as3, my boss did a animated logo on as3 and I have to put index.php as a button in this logo, so I made the invisible button and tried to use this code, but, or I am REALLY STUPID or I just cant understand how to do, can you draw how to use this code or some like that? cause Im getting mad x.x
    its just copying and pasting the code doesnt it? what do I have to do to work?

    I got this error:

    1037: Packages cannot be nested.

    1. hello, I see the problem already. You pasted the class into your existing class.

      This class is intended to be an individual file.

      1. create a text file and call it GetUrl.as
      2. paste the contents of the class into the text file. (the code that starts with package)
      3. go to the location where your FLA file is saved and create a folder called com
      4. go to the com folder, and create another called frigidfish
      5. in the frigidfish folder, save the GetURL.as file.

      now, open your fla file where you want to create the link.
      at the top of your code, add these lines:

      import com.frigidfish.GetURL;
      import flash.Events.MouseEvent;

      now you can add a link to your button something like this:

      myButton.addEventListener(MouseEvent.CLICK, loadIndexPHP);

      function loadIndexPHP(event:MouseEvent){

      new GetURL(“http://yourSite/index.php”);
      }

      let me know if that doesn’t make sense and I’ll try to clear it up for ya

      Rick

  2. 1172: Definition com.frigidfish:GetURL could not be found.
    1120: Access of undefined property email. (email is a name of button)
    1180: Call to a possibly undefined method GetURL.
    1172: Definition flash.Events:MouseEvent could not be found.

    made everything from 1 to 5, rechecked

    HOW to make this thing work ? :)))

  3. I am thinking that I need to write a tutorial on how to make a class file 🙂

    Ok Barrabashko I’ll help ya out one error at a time:

    1172:

    As stated in the comment before yours, you must create a file called GetURL.as and place it in your_FLA_file’s_folder\com\frigidfish\

    then in your timeline where you write your code, add this line to the top:
    import com.frigidfish.GetURL;

    1120:
    Not sure why you are getting this error.. If this is a button that you put on the stage and you are trying to access it, make sure that you have given it an instance name.

    1180: This is related to the 1172 error. It doesn’t know where to find the class.

    1172: I think you spelled events Events with a capital E.. it should be:
    import flash.events.MouseEvent;

    can you post your code here so that I can see?

  4. On compile I recieve : “Warning: parameter ‘target’ has no type declaration.”

    So add to the class

    public function GetURL(url:String, target:String = ‘_self’){

Leave a Reply