Using the Output Panel


The Output panel is used to send messages and notifications while troubleshooting your movies. When you test a Flash movie file (.swf), Flash 8 checks your ActionScript for syntax errors and sends any error messages to the Output panel.

Note 

Many multimedia authoring applications, such as Macromedia Director, won't let you leave the script window until the syntax is correct. With Flash, it's entirely possible to write incorrect syntax within a block of code and close the Actions panel with the error intact. Flash notifies you, though, when you publish or test the movie if it finds an error.

The Output panel itself is packed with functionality, enabling you to do the following:

  • Print the contents of the panel.

  • Copy the contents of the panel to the Clipboard.

  • Save the contents of the panel to a text file.

  • Search for a specific string within the contents of the panel.

  • Clear the current contents of the panel.

These commands can be accessed via the options menu in the upper-right corner of the Output panel.

trace() Action

The Output panel is not only used by Flash 8 to send syntax error messages to you, but you can also use it to view any data while testing a movie.

Using the trace() action can be a valuable tool when you debug your code. It is very simple to use and is sometimes better to use than the Debugger panel, which we discuss later in this chapter. Each time you call the trace() action, a new line is created and nothing is replaced. This makes it a great asset when you are debugging code such as for() loops. You can also save all data sent to the Output panel to a text file and review it later. A debugging session with the Debugger panel can't be saved.

Note 

You can use the Output panel and the Debugger panel together to more effectively analyze every aspect of your Flash movie during testing.

In this exercise, you create a simple frame loop and repeatedly send some information to the output window.

  1. Open Flash and create a new file by choosing File New.

  2. Rename Layer 1 to actions.

  3. Select the first frame of the actions layer and open the Actions panel (F9). Add the following code to the Script pane:

     var nCount:Number = 0; 

    This code declares a variable named nCount, with a Number data type. Its value is set to 0.

  4. Select frame 2 of the actions layer and press the F7 key to insert an empty keyframe. Select frame 2, and open the Actions panel. Insert the following code:

     trace(nCount++); 

    This code will send the value of nCount to the Output panel and then increment the value of nCount by one.

  5. Select frame 3 of the actions layer and insert an empty keyframe (F7). With frame 3 selected, open the Actions panel (F9). Add the following code:

     this.gotoAndPlay(2); 

    This action tells the Flash movie to constantly loop the second frame. As such, the trace() action repeatedly sends messages to the Output panel.

  6. Test the movie to see the result of using the trace() action by choosing Control Test Movie (Ctrl+Enter or z +Enter). You should see the value of count repeatedly sent to the Output panel, as shown in Figure 32-6. You can close both the Test Movie and Output windows.

image from book
Figure 32-6: Your Output panel should look similar to this figure once you have completed Step 6.

Caution 

If you close the Output panel before closing the Test Movie window, it will continue to reopen because the trace() action will be executed the next time frame 2 is played.

Tip 

You can slow down the rate of trace() messages for this example by changing the movie's frame rate in the Modify Document dialog box to a lower value such as 1 fps.

On the CD-ROM 

You can find this example, trace_loop.fla, in the ch32 folder of this book's CD-ROM.

The trace() action can also send expressions to the Output panel. In this example, you write an expression inside the trace() action and the result is sent to the Output panel.

  1. Create a new file by choosing File New.

  2. Rename Layer 1 to actions, and select the first frame. Open the Actions panel (F9). Type the following code into the Script pane of the Actions panel:

     var foo:Number = 5; var bar:Number = foo; trace(bar == foo); 

    The first line of this code declares a variable foo, which is equal to 5. The second line declares a variable named bar, which is equal to foo. The expression inside the trace() action uses the equality operator to evaluate if bar is equal to foo and sends the result to the Output panel. The equality operator is used to compare two expressions. If the two expressions are equal, the result is true. If they aren't equal, the result is false.

  3. Test the movie by choosing Control Test Movie. When you test the movie, the Output panel should open and display the Boolean value true. This is because the value of bar is equal to the value of foo.

  4. Close the Test Movie window and the Output panel and add the following line of code to the end of the actions list:

     trace(bar != foo); 

    This code uses the inequality operator instead of the equality operator in the expression. Again, the result is sent to the Output panel. The inequality operator is used to compare two expressions. If the two expressions aren't equal, the result is true. If the two expressions are equal, the result is false.

    image from book
    Simulating the trace() Action Online

    You can only use the trace() action in Test Mode within Flash 8, or when you use the Debugger panel with a remote Flash movie. You might like to use something similar to the trace() action when testing in a browser. Follow these steps to make a Flash/JavaScript version of the trace() action using a JavaScript alert dialog box:

    1. Open Flash and create a new file by choosing File New.

    2. Select the first frame of Layer 1 and enter the following code using the Actions panel. This code simulates a trace() action. It uses a JavaScript alert dialog box to display any information you send to the alert function. When testing this in Flash MX, a browser window is opened to display messages.

       function alert (alertString) {   getURL("javascript:alert(‘"+ alertString + "‘);"); } alert("this is a test"); 

    3. Anytime you want to send an alert to the browser, use alert("any text or expression in here").

    Also, make sure the allowScriptAccess parameter of the OBJECT tag and attribute of the EMBED tag in HTML is set to "always" when you test the Flash movie and HTML locally. Otherwise, the Flash movie is prohibited from communicating with JavaScript. For more information on this Flash Player attribute, refer to Chapter 21, "Publishing Flash Movies."

    image from book

  5. Test the movie again by choosing Control Test Movie. The Output panel will display true for the first trace() action, and false for the second trace() action.

On the CD-ROM 

You can find the completed file, trace_expression.fla, in the ch32 folder of this book's CD-ROM.

Although these are simple examples, the trace() action can be used to send the result of almost any equation that can be written on one line to the Output panel, assuming all variables referenced in the expression have been predefined.

List Objects and List Variables

The Output panel is used for troubleshooting, displaying syntax errors, and viewing trace() action values. It can also be used to view all objects or variables currently in your movie.

The List Object and List Variables commands, available in the Debug menu of the Test Movie environment, are very useful when debugging large applications in Flash 8.

  • List Objects: This command sends the current level, frame number, symbol names, Button, Movie Clip, or text field instance names, target paths, text blocks, and vector shapes to the Output window. The List Objects command displays the information in a hierarchal format. If you have five objects within a Movie Clip instance named foo, each of these objects will be indented beneath the foo declaration.

  • List Variables: This command sends all properties of any ActionScript objects, variables, and data currently in your Flash movie to the Output window. Functions are also listed when this command is executed.

Caution 

List Objects is frame dependent. If frame 1 of a movie has different objects than frame 5, executing List Objects on each of those frames sends different results to the Output panel.

Tip 

The data sent to the Output panel from the List Objects command is a little confusing. It reports a vector graphic as being a "shape:." However, a Graphic symbol is also reported as being a "Shape:." Hence, there is no way to distinguish whether it is a vector shape or a graphic.

Follow these steps to test the List Objects and List Variables commands:

  1. Open Flash 8 and create a new file by choosing File New.

  2. Populate frame 1 with multiple objects, inserting a Movie Clip instance, a text field, a Button instance, a block of text (Static text), and a simple vector shape. You might try nesting some objects three or four Movie Clips deep to see the hierarchy of information within the Output window.

  3. Test your movie by choosing Control Test Movie.

  4. Choose Debug List Objects. The Output panel will appear, containing the list of all objects on the current frame. Take a look to see how it reports the objects.




Macromedia Flash 8 Bible
Macromedia Flash8 Bible
ISBN: 0471746762
EAN: 2147483647
Year: 2006
Pages: 395

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net