Home / Articles / Adobe Flash / An Introduction to Using Code Snippets in Flash CS5

An Introduction to Using Code Snippets in Flash CS5

Article Description

Chris Florio, contributor to ActionScript 3.0 for Flash Professional CS5 Classroom in a Book, introduces the new Code Snippets feature in Flash CS5. This article shows how to add rich interactivity to Flash projects without writing any code, as well as how to modify the code snippets that Flash creates to customize your interactivity without a mastery of programming syntax.
Loading and Displaying an External Text File

Loading and Displaying an External Text File

Next, you will add a code snippet that will load an external text file. You will then modify the ActionScript that the snippet creates so that the loaded text displays in the TextArea component that is in the page1_mc movie clip.

  1. In the Actions panel, select a line below all of the existing code.
  2. In the Code Snippets panel, open the folder named “Load and Unload.”
  3. Double Click the code snippet named “Load External Text”.
  4. If you tested the movie now, the text file indicated in the code snippet would load and be displayed in the Flash Output panel. You will modify the code so that it instead displays in the TextArea component named field1_txt that is contained in the page1_mc movie clip.

  5. Near the bottom of the Actions panel, locate the line that reads:
  6. trace(textData);
  7. Change this line so that it reads:
  8.     page1_mc.field1_txt.text = textData;
  9. Test the movie. The loaded text should appear in the TextArea component (see Figure 4). Notice that this component automatically includes a working scrollbar for the text.
  10. Close the codesnippets_start.swf file to leave the Flash testing environment and return to the authoring environment.
  11. The code snippet that you just added contains comments with instructions that explain how to modify the code to load your own text files instead of the Lorum ipsum file.

The next step will be to load an external JPEG file when the third tab is clicked and then modify the resulting ActionScript to control the placement of the JPEG on the Flash stage.

6. Loading and Displaying an External Image | Next Section Previous Section