AS3: Google it!

Probably you have heard of  navigateToURL(). navigateToURL() is simply Flash’s method of making a conventional hypertext link. In this tutorial we are going to use this method to Google what we want directly in our flash movie clip.

 google

navigateToURL() has two parameters:

- URLRequest: This is the network address of the page, file, script, or resource to which you are linking.

- window: This is the name of the frame or window in which you want to load the resource specified in the url setting.

Another usage of the navigateToURL() action sends variables from the Flash movie to a Web server’s script, which is set up to receive the variables. As an example we will use this usage to Google what we want directly in our flash movie clip.

 

Step 1: Create a new Flash movie with the ActionScript version set to 3.0. The background color, frame rate and the stage size do not matter for this tutorial.

Step 2: Create one new layers, so you will have two layers in total. Then name the one at the bottom TextBox and the one on top Actions.

step2

Step 3: We will use Input Text box to be able to get the search terms directly from users in our flash movie clip. Use the Text Tool (T) and create a Input Text box on the stage. You should access Properties Inspector and select Input Text from Text Type drop-down list.

step3

Step 4: Now, we need to set an Instance Name for our input text box. Use the Select Tool (V) and select the input text box, access the Properties Inspector and set MyText as the instance name of the text box.

step4

Step 5: Add a Button component onto the stage. You can add a component to your Stage in the following ways:
1. Open the Components panel by going to Window> Components or by pressing Ctrl+F7.
2. Add a component to the Stage by:
Double-clicking: You can double-click a component and it will be added to the center of your Document window’s workspace.
Dragging: You can add an instance by clicking the component icon and dragging it onto the Stage.

step5

Step 6: The Component Inspector panel is the central control area for component parameters and bindings. You can find this panel by choosing Window> Component Inspector or by using the Shift+F7 shortcut. Access the Component Inspector and set the button label to Google it!.

step6

Step 7: We need to set an Instance Name for our button so we can easily refer to it using ActionScript. Use the Select Tool (V) and select the button, access the Properties Inspector and set MyButton as the instance name of the button component.

step7

Step 8: Click once on the name of the Actions layer and then right-click the only frame on it and select Actions to open Actions panel.

 Step 9: Copy and paste this code to your Actions panel. 

function GoogleIt(event:MouseEvent):void {
 var gURL=new URLRequest(”http://www.google.com/search“);
 var SearchData = new URLVariables();
 SearchData.hl=”en”;
 SearchData.q=MyText.text;
 gURL.data=SearchData;
 navigateToURL(gURL);
}

MyButton.addEventListener(MouseEvent.CLICK, GoogleIt);

That’s it, We are done. You can now test your movie (Ctrl+Enter).

Downloads:

Flash CS3: Google it! :: AS3

Flash CS4: Google it! :: AS3

Share and Enjoy:
  • Print this article!
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Twitter
  • Twitthis
            Delicious     Bookmark this on Delicious

Copyright & Usage

The effects and techniques demonstrated in tutorials on AllTutz can be used in whatever manner you wish without attribution. You cannot copy whole tutorials (unless permission is given), either in English or translated to another language.

Leave a Reply