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:
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 slashdot.org 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.
The actions are calling the getURL() method, and in the URL part we put the path to the search section of slashdot.org 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 slashdot.org.
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.