The getURL() Method

The getURL() Method

Sending data out of Flash is one of the most exciting ways to show interaction. When any user can fill in a form, click a Submit button, and see a web page open with the results, the possibilities are endless. The getURL() method was the earliest means of accomplishing this goal.

Its general usage looks something like this:


Let's go over what each part is for:

  • URL This is the path to the web page you would like to go to.

  • window This is an optional parameter specifying the window or frame to load the content; it has four specific keywords:

    • _self The current frame in the current window the Flash file is residing in.

    • _blank Creates a new window.

    • _parent The parent frame of the current frame that the Flash file is residing in.

    • _top The top-level frame in the window that the Flash file is residing in.

  • variables Optional parameter for sending variables to the URL with either the GET or POST method.

The getURL() method is most often used for links to other pages, but you can use it to send data to other web pages as well. Here is an example of using the getURL() method to accomplish this goal. Place this code in the actions of the first frame on the main timeline:


This example, when run, opens up a browser window, and the results from searching display. You can replace the last part, "apple", with something else, and when you rerun the file, it will open up a browser window with the new results.

In the preceding example, we can change what we are looking for in the code itself and then see the results each time the code is run. This is not interactive at all; in fact, the user cannot control what is being searched for. Therefore, the next example will take the preceding one a step further.

In this example, you are going to create an input text field for the user to type in search terms. You will also put a Submit button in the file so that the user can perform different searches.


Start a new Flash document.


Create a second layer, and name the top layer actions and the bottom layer content.


In the content layer, create an input text field with the border turned on, and give it an instance name of search_txt.


In the same layer, create a button (or use one from the common libraries by choosing Window, Common Libraries, Buttons). Give it an instance name of search_btn and align it to the right of the text field (as in Figure 20.1).

Figure 20.1. Place the Search button beside the search field.


Now, in the first frame of the actions layer, open up the Actions panel and place these actions within it:

 //the event for the button search_btn.onRelease=function(){      //call the search URL with the search term      getURL(""+search_txt.text,"_blank"); } 

The actions are calling the getURL() method, and in the URL part we put the path to the search section of and then combined it with the search term that the user will place in the text field.

Test the example, and you will see that when you put a search term in the text field and click the Search button, a browser window opens with the results of the search, as shown in Figure 20.2.

Figure 20.2. The results from the search on

That was a good example of how to move data out of Flash with user interaction. The downside is that when you use the getURL() method, you are actually going outside of Flash with the results. In the following sections, you will learn how to get data into Flash using several built-in methods as well as the LoadVars object class.

Before you start loading data in, however, we need to go over what form the data needs to be in.

Macromedia Flash Professional 8 Unleashed
Macromedia Flash Professional 8 Unleashed
ISBN: 0672327619
EAN: 2147483647
Year: 2005
Pages: 319 © 2008-2017.
If you may any questions please contact us: