Code Snippets

This movie has a button to navigate to a web page. Get Adobe Flash player

  1. Create a new movie.
  2. Add a button (From the menu select Window, Common Libraries, Buttons. Add any button you like.)
  3. Name the button btnHello in the properties window.
  4. Click the button to select it.
  5. Open the actions panel (From the menu select Window, Actions or F9.)
  6. Click Code Snippets in the top right corner and double click Click to go to Web Page.
    snippets
  7. A new layer called Actions will be inserted and the code shown below will be inserted:
    /* Click to Go to Web Page
    Clicking on the specified symbol instance loads the URL in a new browser window.
    
    Instructions:
    1. Replace http://www.adobe.com with the desired URL address.
       Keep the quotation marks ("").
    */
    
    btnHello.addEventListener(MouseEvent.CLICK, fl_ClickToGoToWebPage);
    
    function fl_ClickToGoToWebPage(event:MouseEvent):void
    {
    	navigateToURL(new URLRequest("http://www.adobe.com"), "_blank");
    }
  8. Modify the code as shown below using your favorite website instead of Adobe:
    btnHello.addEventListener(MouseEvent.CLICK,goHello);
    
    function goHello(e:MouseEvent):void
    {   
    	navigateToURL(new URLRequest("http://www.hello-world.com"), "_blank");
    }
    

NEXT: Properties of MovieClips