<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" 
      xmlns:thr="http://purl.org/syndication/thread/1.0">
  <link rel="alternate" type="text/html" href="http://www.insideria.com/2008/08/learning-flex-3-adding-interac-2.html" />
  <link rel="self" type="application/atom+xml" href="http://www.insideria.com/atom.xml" />
  <id>tag:www.insideria.com,2009://34/tag:www.insideria.com,2008://34.26342-</id>
  <updated>2009-11-07T00:26:33Z</updated>
  <title>Comments for Learning Flex 3 - Adding Interactivity with ActionScript, Part 3 (http://www.insideria.com/2008/08/learning-flex-3-adding-interac-2.html)</title>
  <generator uri="http://www.sixapart.com/movabletype/">Movable Type 4.21-en</generator>
  <entry>
    <id>tag:www.insideria.com,2008://34.26342</id>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2008/08/learning-flex-3-adding-interac-2.html" />
    <link rel="service.edit" type="application/atom+xml" href="http://blogs.oreilly.com/cgi-bin/mt/mt-atom.cgi/weblog/blog_id=34/entry_id=26342" title="Learning Flex 3 - Adding Interactivity with ActionScript, Part 3" />
    <published>2008-08-11T13:00:00Z</published>
    <updated>2008-10-06T04:24:36Z</updated>
    <title>Learning Flex 3 - Adding Interactivity with ActionScript, Part 3</title>
    <summary>Part 3: Debugging for Kicks and Summary

This excerpt from Learning Flex 3 is for InsideRIA readers who may be considering giving Flex a try and who need a get-up-to-speed tutorial on handling use input in Flex. It&apos;s written by Alaric Cole, who&apos;s contributed open source components to the Flex community and who is a development and consulting specialist at Yahoo!.</summary>
    <author>
      <name>Alaric Cole</name>
      
    </author>
    
    <content type="html" xml:lang="en" xml:base="http://www.insideria.com/">
      <![CDATA[<div style="height: 20px;"><div style="float:left;">Pages: <a href="http://insideria.com/2008/08/learning-flex-3-adding-interac.html">1</a>, <a href="http://insideria.com/2008/08/learning-flex-3-adding-interac-1.html">2</a>, <strong>3</strong></div></div>

                   <h4>Debugging for Kicks</h4>
                    <p class="body">While showing how to display an alert helps in learning how events can work, displaying such a pop-up alert with every little change can be annoying. Because this isn&#8217;t really a feature you&#8217;d want to implement in your application, but more of a way for you to learn from and test your application, there&#8217;s a better way to display information in regard to an event. It&#8217;s called <span style="font-style:italic">debugging</span>. While the name implies that there&#8217;s a <span style="font-style:italic">bug</span>, or glitch, in your software that you&#8217;re trying to locate, you&#8217;ll see there&#8217;s really more to debugging than that. Debugging in Flex is a great way to show the innards of your application or to display information while you&#8217;re developing. </p>
                    <p><strong>Outputting Information to the Console</strong></p>
                    <p class="body">To debug your application, you&#8217;ll use a method called <span style="font-family:'Courier New','Andale Mono',Courier,Monaco,monospace;">trace()</span> that will display some text in the Console panel. Simply replace the <span style="font-family:'Courier New','Andale Mono',Courier,Monaco,monospace;">Alert.show</span> method with <span style="font-family:'Courier New','Andale Mono',Courier,Monaco,monospace;">trace</span>, as in the following:</p>

<div class="acode" style="overflow: auto; padding: 8px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>                    
<span class="category1">public</span> <span class="category1">function</span> showInfo():<span class="category1">void</span>

{
 
 <span class="category2">trace</span>("<span class="quote">Your name is </span>" + fullNameTextInput.<span class="category2">text</span> + 
 
 "<span class="quote"> and your age is </span>" + ageNS.value);
 
}</pre>
</code>

</div></div>

                    <p class="body">Now, just running the application won&#8217;t actually display this information. To use <span style="font-family:'Courier New','Andale Mono',Courier,Monaco,monospace;">trace</span>, you&#8217;ll have to be debugging your application. How do you do that? Pretty easily&#8212;I&#8217;m glad you asked. Instead of running the application by using the green arrow button, you&#8217;ll click the green bug icon to its right. Clicking this icon launches the application in debug mode. In most cases, it will look the same to you, but now when you change the NumericStepper, the string of text will be output to the Console panel. </p>
                    
                    
                      <p style="font-style:italic;">Note: The Console panel is, by default, located at the bottom of your Flex Builder window, next to the Problems panel. If your Console panel isn&#8217;t visible, make it visible by selecting Window<span class="symbol-9pt-">→</span>Console.</p>
                  
                    
                    <p class="body">Debug your application, click the NumericStepper a few times, and then switch back to Flex Builder to see the information in the Console panel. The same information that was previously in a pop-up alert is now output to a new line of text in the Console panel, as shown in Figure 6-5.</p>
                    
                    <div class="ap_c"><a href="http://oreillynet.com/images/oreilly/digitalmedia/insideria/0605.jpg" class="highslide" onclick="return hs.expand(this)"><img src="http://oreillynet.com/images/oreilly/digitalmedia/insideria/0605.jpg" alt="0605 Figure" title="Click to enlarge" width="400"/></a><div class="apcaption">Figure 6-5. The output of a <span style="font-family:'Courier New','Andale Mono',Courier,Monaco,monospace;">trace</span> in the Console panel</div></div>
                    
                    <p class="body">The <span style="font-family:'Courier New','Andale Mono',Courier,Monaco,monospace;">trace</span> statement is deceptively simple. However, coupled with debug mode, it will be one of your most powerful tools as you grow as a developer. Next you&#8217;ll learn how to use debugging to find out more information about an event. </p>
                    
         <p><strong>Using Event Parameters in Debugging</strong></p>
                    <p class="body">Remember those parameters you learned about that you could pass to a function? You&#8217;ll now add a parameter to your <span style="font-family:'Courier New','Andale Mono',Courier,Monaco,monospace;">showInfo()</span> function called <span style="font-family:'Courier New','Andale Mono',Courier,Monaco,monospace;">event</span> and make it of type Event. (You could call it whatever you like, but I usually just call it <span style="font-style:italic">event</span> in lowercase.) Now in the <span style="font-family:'Courier New','Andale Mono',Courier,Monaco,monospace;">trace</span> statement, you&#8217;ll be able to get some details about the event, namely, two properties called <span style="font-family:'Courier New','Andale Mono',Courier,Monaco,monospace;">type</span> and <span style="font-family:'Courier New','Andale Mono',Courier,Monaco,monospace;">currentTarget</span>. Your function should look like this:</p>

<div class="acode" style="overflow: auto; padding: 8px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>                    
<span class="category1">public</span> <span class="category1">function</span> showInfo(event:Event):<span class="category1">void</span>

{
 
 <span class="category2">trace</span>("<span class="quote">The type is </span>" + event.<span class="category2">type</span> + 
 
 "<span class="quote"> and the current target is </span>" + event.currentTarget);
 
}</pre>
</code>

</div></div>

                    <p class="body">What&#8217;s going to happen is an event object will be passed to this function. It is of type Event, which is a general type that has properties attached to it which are helpful in learning about the event. The <span style="font-family:'Courier New','Andale Mono',Courier,Monaco,monospace;">type</span> property contains the name of the event type, which in this case is a <span style="font-family:'Courier New','Andale Mono',Courier,Monaco,monospace;">change</span> event (&#8220;change&#8221;). The <span style="font-family:'Courier New','Andale Mono',Courier,Monaco,monospace;">currentTarget</span> property contains a reference to the object that passed the event, which is whatever called the function.</p>
              <p class="body">You might have realized that making this work requires one more step: you have to actually pass the parameter to the function when you call it. There&#8217;s a special parameter in Flex called <span style="font-family:'Courier New','Andale Mono',Courier,Monaco,monospace;">event</span> that is used to pass event objects to functions, and you&#8217;re going to use it. It&#8217;s built in. You haven&#8217;t created any variable called <span style="font-family:'Courier New','Andale Mono',Courier,Monaco,monospace;">event</span>, but Flex will create one at compile time. Think of it as a feature. Pass in the event by using the following code for your <span style="font-family:'Courier New','Andale Mono',Courier,Monaco,monospace;">change</span> event on the NumericStepper:</p>

<div class="acode" style="overflow: auto; padding: 8px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>                    
change="<span class="quote">showInfo(event)</span>"</pre>
</code>

</div></div>

                    <p class="body">And pass in the event for the button by using this for your <span style="font-family:'Courier New','Andale Mono',Courier,Monaco,monospace;">click</span> event on the button:</p>

<div class="acode" style="overflow: auto; padding: 8px; height: 15px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>
click="<span class="quote">showInfo(event)</span>"</pre>
</code>

</div></div>

                    <p class="body">Because the function expects an <span style="font-family:'Courier New','Andale Mono',Courier,Monaco,monospace;">event</span> parameter to be passed in, failing to pass it when calling the function results in a compile-time error. </p>
              <p class="body">Now when you debug the application and change the NumericStepper, you&#8217;ll get a message in the Console panel like &#8220;The type is change, and the current target is HelloWorld0.panel.ageNS.&#8221; Make sense? You knew the type of the event would be <span style="font-family:'Courier New','Andale Mono',Courier,Monaco,monospace;">change</span>, but that current target value is a little cryptic. Notice the <span style="font-style:italic">ageNS</span>, which is the <span style="font-family:'Courier New','Andale Mono',Courier,Monaco,monospace;">id</span> of the NumericStepper. But what&#8217;s the <span style="font-style:italic">HelloWorld0.panel</span> part? Well, when Flex creates your application, it actually creates a class based on the name of the application. In this case, Flex added zero to the end of the name. As for the <span style="font-style:italic">.panel</span> part, that&#8217;s the <span style="font-family:'Courier New','Andale Mono',Courier,Monaco,monospace;">id</span> of the panel in which the NumericStepper is located. So, in terms of a hierarchy, <span style="font-family:'Courier New','Andale Mono',Courier,Monaco,monospace;">ageNS</span> is considered part of panel, which is in turn part of the HelloWorld application.</p>
                
                    <p class="body">When clicking the button, the <span style="font-family:'Courier New','Andale Mono',Courier,Monaco,monospace;">trace</span> statement will display slightly different information. Because the event registered on the button is a <span style="font-family:'Courier New','Andale Mono',Courier,Monaco,monospace;">click</span> event, the trace will display the event type as &#8220;click.&#8221; Also, you&#8217;ll see that the <span style="font-family:'Courier New','Andale Mono',Courier,Monaco,monospace;">currentTarget</span> is the button. (If you haven&#8217;t given the button an <span style="font-family:'Courier New','Andale Mono',Courier,Monaco,monospace;">id</span>, the Flex compiler creates one for you, and it may be displayed here as &#8220;Button0&#8221; or &#8220;Button23&#8221; or something like that.)</p>
              <p class="body">This event information is handy when creating functions, because you can make the functions highly reusable. You could create one function that changes what it does based on who called it (the <span style="font-family:'Courier New','Andale Mono',Courier,Monaco,monospace;">currentTarget</span>) or what type of event occurred (the Event type).</p>
                    
                    <p><strong>Using Breakpoints</strong></p>
                    <p class="body">Next you&#8217;ll learn a pretty advanced technique, but it&#8217;s one I find so essential that it merits explaining. I&#8217;m talking about using breakpoints in your code to really see what&#8217;s happening. </p>
                    <p class="body">A <span style="font-style:italic">breakpoint</span> is a place in the logic of your code at which you&#8217;d like to stop everything. Because some programming constructs can get complicated, it&#8217;s really useful to be able to say, &#8220;Hold up a minute!&#8221; and check how things are going. A breakpoint allows you to do that, letting you pause the application and view its current status before continuing. </p>
              <p class="body">To use a breakpoint, double-click in the <span style="font-style:italic">gutter</span>, the area where the line numbers appear to the left of your code. Do this next to the line of code in which you want to create a breakpoint. In this case, you&#8217;ll want to create a breakpoint in the only place it makes sense, the only place you really have application logic, within your one and only function. So, place a breakpoint to the left of your <span style="font-family:'Courier New','Andale Mono',Courier,Monaco,monospace;">trace</span> statement, as shown in Figure 6-6.</p>
                   
                   <div class="ap_c"><a href="http://oreillynet.com/images/oreilly/digitalmedia/insideria/0606.jpg" class="highslide" onclick="return hs.expand(this)"><img src="http://oreillynet.com/images/oreilly/digitalmedia/insideria/0606.jpg" alt="0606 Figure" title="Click to enlarge" width="400"/></a><div class="apcaption">Figure 6-6. A breakpoint placed on line 11</div></div>
                    
              <p class="body">Now when you debug the application, whenever the NumericStepper is changed or the button is clicked, the function will be called and the breakpoint will be set. You&#8217;ll probably be prompted the first time with a dialog box from Flex Builder similar to Figure 6-7, which asks you whether you&#8217;d like to switch to the Flex Debugging perspective. I recommend turning on the checkbox that says &#8220;Remember my decision&#8221; because this will launch the right perspective when breakpoints are set. Click the Yes button, and you&#8217;ll have a whole new perspective.</p>
                    
                    <div class="ap_c"><a href="http://oreillynet.com/images/oreilly/digitalmedia/insideria/0607.jpg" class="highslide" onclick="return hs.expand(this)"><img src="http://oreillynet.com/images/oreilly/digitalmedia/insideria/0607.jpg" alt="0607 Figure" title="Click to enlarge" width="400"/></a><div class="apcaption">Figure 6-7. Confirm Perspective Switch dialog box</div></div>
                    
                    <p><strong>Seeing a New Perspective</strong></p>
                    <p class="body">Perspectives in Flex Builder are just a way of specifying and remembering a panel layout. When you&#8217;re developing in Flex Builder for the first time, you&#8217;re using the Flex Development perspective, which contains panels like Flex Properties and Flex Navigator. When debugging, you&#8217;ll be using a few new panels specific to that task, and they&#8217;re contained in the Flex Debugging perspective. </p>
              <p class="body">One of these new panels you&#8217;ll see, now that you&#8217;re in the Debugging perspective, is the Variables panel. By default it&#8217;s located in the top right of Flex Builder. Flex Builder also allows you to move and resize panels easily just by clicking and dragging the title bar of the individual panel. Because this panel is a tree list that needs a lot of vertical space, I really recommend moving it so that it takes up the whole right side of Flex Builder. Just click and drag the panel, moving your mouse to the far right side of the Flex Builder window. You&#8217;ll see a thin #CCCCCC outline, which is your feedback as to where the panel will be placed. You can also drag the panel outside the Flex Builder window, and it will be placed in its own pop-up window. </p>
                    
                    <p class="body">Whether you clicked the button or changed the NumericStepper, the Variables panel will display information about your application in its current state, at the breakpoint you set. You should see two items in a tree list, one called <span style="font-family:'Courier New','Andale Mono',Courier,Monaco,monospace;">this</span> and another called <span style="font-family:'Courier New','Andale Mono',Courier,Monaco,monospace;">event</span>. The item <span style="font-family:'Courier New','Andale Mono',Courier,Monaco,monospace;">this</span> refers to the application as a whole, and the item <span style="font-family:'Courier New','Andale Mono',Courier,Monaco,monospace;">event</span> refers to the <span style="font-family:'Courier New','Andale Mono',Courier,Monaco,monospace;">event</span> parameter that you passed to the function. </p>
                    
                    <p class="body">Click the arrow to the left of the <span style="font-family:'Courier New','Andale Mono',Courier,Monaco,monospace;">event</span> item to display the child nodes. You&#8217;ll focus on the items in the <span style="font-family:'Courier New','Andale Mono',Courier,Monaco,monospace;">[inherited]</span> node, so click the arrow to display them. You&#8217;ll see all the properties of this <span style="font-family:'Courier New','Andale Mono',Courier,Monaco,monospace;">event</span> object, including the beloved <span style="font-family:'Courier New','Andale Mono',Courier,Monaco,monospace;">type</span> and <span style="font-family:'Courier New','Andale Mono',Courier,Monaco,monospace;">currentTarget</span> properties, displayed with their current values, as shown in Figure 6-8.</p>
                    
                    <div class="ap_c"><a href="http://oreillynet.com/images/oreilly/digitalmedia/insideria/0608.jpg" class="highslide" onclick="return hs.expand(this)"><img src="http://oreillynet.com/images/oreilly/digitalmedia/insideria/0608.jpg" alt="0608 Figure" title="Click to enlarge" width="400"/></a><div class="apcaption">Figure 6-8. Variables panel</div></div>
                    
                    <p><strong>Ending Your Debug Session</strong></p>
                    <p class="body">Feel free to poke around here as you wish. You might want to return to this later, because it will tell you a lot about how Flex works, so keep it in mind. For now, close this perspective, and end your debug session. Note that debugging may lock up your browser, because it pauses Flash Player. So, the way to end the session is by clicking the red, square button located both in the Console panel and in the Debug panel, as shown in Figure 6-9. You can also access this command by selecting Run→Terminate. That will terminate the debugging session. When you&#8217;re done, you&#8217;ll also want to return to the Flex Development perspective by using the toggle button bar at the top right of Flex Builder or by selecting Window→Perspective→Flex Development.</p>
                 
              <div class="ap_r"><a href="http://oreillynet.com/images/oreilly/digitalmedia/insideria/0609.jpg" class="highslide" onclick="return hs.expand(this)"><img src="http://oreillynet.com/images/oreilly/digitalmedia/insideria/0609.jpg" alt="0609 Figure" title="Click to enlarge" width="148" /></a> <div class="apcaption">Figure 6-9. Debug panel</div></div>

                 <h4>Summary</h4>
              <p class="body">Now you&#8217;ve learned a bit more about what events are and how to use them in your application. Don&#8217;t worry if some of this is overwhelming; interactivity can be a very challenging part of development. If you need to return to this chapter later for a refresher, feel free. While your application may not be looking that different yet, you&#8217;ve learned some very important concepts in creating interactivity that you&#8217;ll be able to use very soon.</p>
                 
<p class="body">In the next chapter, you&#8217;ll get into some of the powerful features of Flex. Then you&#8217;ll really start to make your application into something useful.</p>

<div style="padding:15px 0px; margin=15px 0px; border-top: 1px solid #CCCCCC; border-bottom: 1px solid #CCCCCC;"><p><em>This chapter was excerpted from <a href="http://oreilly.com/catalog/9780596517328/">Learning Flex 3</a>, by <a href="">Alaric Cole</a>.<br />Read the <a href="http://www.insideria.com/LF3_toc.pdf">Table of Contents</a>.</em></p>

<p><strong>Buy this book: <a href="http://oreilly.com/catalog/9780596517328/">O'Reilly</a> | <a href="http://safari.oreilly.com/9780596517328?cid=orm-cat-readnow-9780596517328">Safari Books Online</a> | <a href="http://www.amazon.com/gp/product/0596517327?tag=oreillycom-20">Amazon</a></strong></p>
</div>

<div style="padding-top: 15px; margin-bottom: 20px; height: 20px;">
<div style="float:left;">Pages: <a href="http://insideria.com/2008/08/learning-flex-3-adding-interac.html">1</a>, <a href="http://insideria.com/2008/08/learning-flex-3-adding-interac-1.html">2</a>, <strong>3</strong></div>
</div>]]>
      
    </content>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2008://34.26342-comment:2020605</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2008://34.26342" type="text/html" href="http://www.insideria.com/2008/08/learning-flex-3-adding-interac-2.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2008/08/learning-flex-3-adding-interac-2.html#comment-2020605" />
    <title>Comment from Sam C on 2008-08-11</title>
    <author>
        <name>Sam C</name>
        <uri></uri>
    </author>
    <content type="html" xml:lang="en" xml:base="">
        <![CDATA[<p>Is there a version that is more printable?</p>]]>
    </content>
    <published>2008-08-12T00:24:10Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2008://34.26342-comment:2020608</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2008://34.26342" type="text/html" href="http://www.insideria.com/2008/08/learning-flex-3-adding-interac-2.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2008/08/learning-flex-3-adding-interac-2.html#comment-2020608" />
    <title>Comment from Alaric Cole on 2008-08-11</title>
    <author>
        <name>Alaric Cole</name>
        <uri>http://learningflex3.com</uri>
    </author>
    <content type="html" xml:lang="en" xml:base="http://learningflex3.com">
        <![CDATA[<p>The book.</p>]]>
    </content>
    <published>2008-08-12T03:29:38Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2008://34.26342-comment:2175403</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2008://34.26342" type="text/html" href="http://www.insideria.com/2008/08/learning-flex-3-adding-interac-2.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2008/08/learning-flex-3-adding-interac-2.html#comment-2175403" />
    <title>Comment from AndyC on 2009-11-06</title>
    <author>
        <name>AndyC</name>
        <uri></uri>
    </author>
    <content type="html" xml:lang="en" xml:base="">
        <![CDATA[<p>I'm trying to use the event info to make reusable functions but am not quite sure how to do it. The event.currentTarget.id could be dg1, dg2 etc<br />
but I'm not sure how to replace the hardcopy dg1 below. I have tried (),[],{}<br />
and using a variable so far without luck</p>

<p>private function moreInfo(event:ListEvent):void<br />
			{<br />
				trace (event.currentTarget.id);<br />
				<br />
			svc.getPlayerByYear(dg1.selectedItem.nameID);</p>

<p>}</p>

<p>TIA for any help</p>]]>
    </content>
    <published>2009-11-07T00:26:28Z</published>
  </entry>

</feed
