<?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/2009/06/user-info-component.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,2009://34.37168-</id>
  <updated>2009-11-16T14:53:16Z</updated>
  <title>Comments for User Info Component (http://www.insideria.com/2009/06/user-info-component.html)</title>
  <generator uri="http://www.sixapart.com/movabletype/">Movable Type 4.21-en</generator>
  <entry>
    <id>tag:www.insideria.com,2009://34.37168</id>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2009/06/user-info-component.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=37168" title="User Info Component" />
    <published>2009-06-30T13:00:00Z</published>
    <updated>2009-06-30T20:04:02Z</updated>
    <title>User Info Component</title>
    <summary>Welcome back to the series. This time we are goings to build a really exciting component that will be used to simply display information about the user. Well, you might say why to we need such a component, is there are real purpose behind that? Well, in my opinion, yes. There are a lot of facebook applications out there done in Flash where we see information about the friends etc. During the process of facebook application development, there will always be a need to quickly display information about the specific friend. The information that is contained inside the component could be every bit of information that was entered by the user.</summary>
    <author>
      <name>Mirza Hatipovic</name>
      
    </author>
    
    <category term="Adobe Feed" />
    
    <category term="Features" />
    
    <content type="html" xml:lang="en" xml:base="http://www.insideria.com/">
      <![CDATA[<div style="text-align: left;">&nbsp;&nbsp;&nbsp;&nbsp;Welcome back to the series. This time we are goings to build a really exciting component that will be used to simply display information about the user. Well, you might say why to we need such a component, is there are real purpose behind that? Well, in my opinion, yes. There are a lot of facebook applications out there done in Flash where we see information about the friends etc. During the process of facebook application development, there will always be a need to quickly display information about the specific friend. The information that is contained inside the component could be every bit of information that was entered by the user. </div>

<div style="text-align: left;">In our case, the component will do the following: It will display all the information that was entered by the facebook user, it will contain all the necessary information that is contained in http://wiki.developers.facebook.com/index.php/Users.getInfo. As we can see there are uid, about_me, activities, affiliations, type, college, high school, work, region, year, name, nid, status. So, in the process of development, there will be a need for us to quickly display this information. Some of them we will need to display, some of them will be needed to hide away. </div>

<div style="text-align: left;">The article will consist of 3 sections. The first section will talk about the back end and how to grad the information from facebook. The 2 section will deal with the functionality of the component and the display of data. The section will deal with all the stuff that is needed to display the actual that that was retrieved. The last section will deal with the look and feel of the displayed component. We will make sure that we can use different fonts, different colors. In short, the last section will handle the look of the front end. </div>

<strong>Getting the data we want</strong>

<div style="text-align: left;">Ok, in order to move on we need to set up the standard element we always work with. First we need an empty FLA, then we need the the api and the secret, then we need the facebook API. In the first few lines of code, we will load all the data that is needed and pass it to the component. So, open the FLA we worked on previously and clear all elements from the stage and code:</div>

<br/>
<span class="mt-enclosure mt-enclosure-image" style="display: inline;"><a href="http://www.insideria.com/assets_c/2009/06/article13_img12.html" onclick="window.open('http://www.insideria.com/assets_c/2009/06/article13_img12.html','popup','width=356,height=378,scrollbars=no,resizable=no,toolbar=no,directories=no,location=no,menubar=no,status=no,left=0,top=0'); return false"><img src="http://www.insideria.com/assets_c/2009/06/article13_img1-thumb-356x378.png" width="356" height="378" alt="article13_img1.png" class="mt-image-none" style="" /></a></span>
<br/>

<div style="text-align: left;">Ok, that's a familiar scenario for us. We don&#8217;t need anything from the previous article on the stage and we don&#8217;t need the code, we start from scratch. </div>

<div style="text-align: left;">Let&#8217;s get our api key and the secret from the FB Developer page. We need to create the session, here is the familiar code: </div>

<div class="acode" style="overflow:auto;padding:10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>

<span class="category1">import</span> com.facebook.<span class="category2">data</span>.users.GetInfoData;
<span class="category1">import</span> com.facebook.utils.FacebookSessionUtil;
<span class="category1">import</span> com.facebook.<span class="category2">data</span>.users.FacebookUser;
<span class="category1">import</span> com.facebook.<span class="category2">data</span>.users.GetInfoFieldValues;
<span class="category1">import</span> com.facebook.commands.users.GetInfo;
<span class="category1">import</span> com.facebook.net.FacebookCall;
<span class="category1">import</span> com.facebook.events.FacebookEvent;
<span class="category1">import</span> com.facebook.Facebook;

<span class="category1">var</span> fbook:Facebook;
<span class="category1">var</span> session:FacebookSessionUtil;

session = <span class="category1">new</span> FacebookSessionUtil("<span class="quote">your_api_key</span>","<span class="quote">your_secret</span>", loaderInfo);
fbook = session.facebook;</pre>
</code>

</div></div> 

<div style="text-align: left;">When we compile the swf, upload and run it, we should not see any errors. If there are few, please go back and fix them before we move on, we really don't want them to bother us later. </div>

<strong>Displaying the data properly</strong>

<div style="text-align: left;">The next thing we want to create is to create an component architecture and a MovieClip that will serve us as the basis for all upcoming features that will be added to the component. The idea is the same like for the previous samples. So in order to work with components, we need an empty MovieClip. So we go to Insert -> New Symbol&#133;</div>

<br/>
<span class="mt-enclosure mt-enclosure-image" style="display: inline;"><a href="http://www.insideria.com/assets_c/2009/06/article13_img22.html" onclick="window.open('http://www.insideria.com/assets_c/2009/06/article13_img22.html','popup','width=228,height=126,scrollbars=no,resizable=no,toolbar=no,directories=no,location=no,menubar=no,status=no,left=0,top=0'); return false"><img src="http://www.insideria.com/assets_c/2009/06/article13_img2-thumb-228x126.png" width="228" height="126" alt="article13_img2.png" class="mt-image-none" style="" /></a></span>
<br/>

<div style="text-align: left;">Then in the dialog we type in the following:</div>

<br/>
<span class="mt-enclosure mt-enclosure-image" style="display: inline;"><a href="http://www.insideria.com/assets_c/2009/06/article13_img32.html" onclick="window.open('http://www.insideria.com/assets_c/2009/06/article13_img32.html','popup','width=502,height=459,scrollbars=no,resizable=no,toolbar=no,directories=no,location=no,menubar=no,status=no,left=0,top=0'); return false"><img src="http://www.insideria.com/assets_c/2009/06/article13_img3-thumb-400x365.png" width="400" height="365" alt="article13_img3.png" class="mt-image-none" style="" /></a></span>
<br/>

<div style="text-align: left;">As we can see from the screen above, the MovieClip needs to be named &#8220;UserInfo&#8221; and the class that the MovieClip is being linked to is facebookUI.UserInfo. From the previous samples we know that we link the classes from the facebookUI package to Symbols in the FLA. So now that we know where the class needs to be located, we need to create the class. Open your favorite text editor and paste the following code to it:</div>

<div class="acode" style="overflow:auto;padding:10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>

package facebookUI{
  
  	<span class="category1">import</span> fl.core.UIComponent;
  	<span class="category1">import</span> flash.<span class="category2">text</span>.*;
  	<span class="category1">import</span> com.facebook.<span class="category2">data</span>.users.GetInfoData;
  	<span class="category1">import</span> com.facebook.utils.FacebookSessionUtil;
  	<span class="category1">import</span> com.facebook.<span class="category2">data</span>.users.FacebookUser;
  	<span class="category1">import</span> com.facebook.<span class="category2">data</span>.users.GetInfoFieldValues;
  	<span class="category1">import</span> com.facebook.<span class="category2">data</span>.friends.*;
  	<span class="category1">import</span> com.facebook.commands.users.*;
  	<span class="category1">import</span> com.facebook.commands.friends.*;
  	<span class="category1">import</span> com.facebook.net.FacebookCall;
  	<span class="category1">import</span> com.facebook.events.FacebookEvent;
  	<span class="category1">import</span> com.facebook.Facebook;
  
  	<span class="category1">public</span> <span class="category1">class</span> UserInfo <span class="category1">extends</span> UIComponent{
    
  		<span class="category1">private</span> <span class="category1">var</span> _fBook:Facebook;
    
    		<span class="category1">function</span> UserInfo() {
      			
      		}
    
    		override protected <span class="category1">function</span> configUI():<span class="category1">void</span> {
      
        			<span class="category1">super</span>.configUI();
      
      		}
    
    		<span class="category1">public</span> <span class="category1">function</span> <span class="category1">set</span> session(f:Facebook):<span class="category1">void</span>{
   
      			_fBook = f;
   
      		}
  
  		<span class="category1">public</span> <span class="category1">function</span> <span class="category2">get</span> session():Facebook{
      			
      		
      		}
  
  		     <span class="category1">public</span> <span class="category1">function</span> <span class="category1">set</span> uid(u:<span class="category2">Number</span>):<span class="category1">void</span>{
      		   		_uid = u;
      		   }
  
  		   <span class="category1">public</span> <span class="category1">function</span> <span class="category2">get</span> uid():<span class="category2">Number</span>{
      	                  <span class="category1">return</span> _uid;
      		   }
  
   	 
    	}
  
}</pre>
</code>

</div></div> 

<div style="text-align: left;">Save this as „UserInfo.as&#8220; in the facebookUI folder. So, now we are ready to do some neat stuff! Let's got back to the main timeline where we created our session:</div>

<div class="acode" style="overflow:auto;padding:10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>

<span class="category1">import</span> com.facebook.<span class="category2">data</span>.users.GetInfoData;
<span class="category1">import</span> com.facebook.utils.FacebookSessionUtil;
<span class="category1">import</span> com.facebook.<span class="category2">data</span>.users.FacebookUser;
<span class="category1">import</span> com.facebook.<span class="category2">data</span>.users.GetInfoFieldValues;
<span class="category1">import</span> com.facebook.commands.users.GetInfo;
<span class="category1">import</span> com.facebook.net.FacebookCall;
<span class="category1">import</span> com.facebook.events.FacebookEvent;
<span class="category1">import</span> com.facebook.Facebook;

<span class="category1">var</span> fbook:Facebook;
<span class="category1">var</span> session:FacebookSessionUtil;

session = <span class="category1">new</span> FacebookSessionUtil("<span class="quote">your_api_key</span>","<span class="quote">your_secret</span>", loaderInfo);
fbook = session.facebook;</pre>
</code>

</div></div> 

<div style="text-align: left;">We need to add the following code to make this work:</div>

<div class="acode" style="overflow:auto;padding:10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>

<span class="category1">var</span> userInfo = <span class="category1">new</span> UserInfo();
userInfo.uid = someFacebookUID;
userInfo.session = fbook;</pre>
</code>

</div></div> 

<div style="text-align: left;">That&#8217;s it! We gave the component a valid session and we can almost forget about the code on the main timeline. The rest will be coded inside the component! </div>

<div style="text-align: left;">Do you know about orthogonality in software development? We all know what orthogonality is 
but how does this apply to software development? Well, we just applied ortogonality to our application and it is a sign of good software engineering principles. The idea behind that lies that we need to have modules that can be extended but this modification does not have to affect the entire system. Controlling a helicopter is a sample of a non-ortogonal system. Why? Because every control unit is connected to each other and altering one of them control affects the whole helicopter. That is not what we want in software engineering, even not in facebook development. The line of code:</div>

<div class="acode" style="overflow:auto;padding:10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>

<span class="category1">var</span> userInfo = <span class="category1">new</span> UserInfo();
userInfo.uid = someFacebookUID;
userInfo.session = fbook;</pre>
</code>

</div></div> 

<div style="text-align: left;">where we pass the session to the UserInfo component, is a classical sample of an ortogonal system in programming. When we pass the session to the component, the component is a class of it's own and we can place so much code in there as we want. Inside the UserInfo component, we can write 2 lines of code, but we can also write 10 000 lines of code, without affecting the stability of the overall code! </div>

<div style="text-align: left;">Enough theory, let's get back to the component. Here is the code of the whole class:</div>

<div class="acode" style="overflow:auto;padding:10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>

package facebookUI{
  
  	<span class="category1">import</span> fl.core.UIComponent;
  	<span class="category1">import</span> flash.<span class="category2">text</span>.*;
  	<span class="category1">import</span> com.facebook.<span class="category2">data</span>.users.GetInfoData;
  	<span class="category1">import</span> com.facebook.utils.FacebookSessionUtil;
  	<span class="category1">import</span> com.facebook.<span class="category2">data</span>.users.FacebookUser;
  	<span class="category1">import</span> com.facebook.<span class="category2">data</span>.users.GetInfoFieldValues;
  	<span class="category1">import</span> com.facebook.<span class="category2">data</span>.friends.*;
  	<span class="category1">import</span> com.facebook.commands.users.*;
  	<span class="category1">import</span> com.facebook.commands.friends.*;
  	<span class="category1">import</span> com.facebook.net.FacebookCall;
  	<span class="category1">import</span> com.facebook.events.FacebookEvent;
  	<span class="category1">import</span> com.facebook.Facebook;
 
  	<span class="category1">public</span> <span class="category1">class</span> UserInfo <span class="category1">extends</span> UIComponent{
    
  		<span class="category1">private</span> <span class="category1">var</span> _fBook:Facebook;
  		<span class="category1">private</span> <span class="category1">var</span> _uid:<span class="category2">Number</span>;
    
    		<span class="category1">function</span> UserInfo() {
      			
      		}
    
    		override protected <span class="category1">function</span> configUI():<span class="category1">void</span> {
      
        			<span class="category1">super</span>.configUI();
      
      		}
  
    		<span class="category1">public</span> <span class="category1">function</span> <span class="category1">set</span> session(f:Facebook):<span class="category1">void</span>{
      			_fBook = f;
      		}
  
  		<span class="category1">public</span> <span class="category1">function</span> <span class="category2">get</span> session():Facebook{
      			
      		
      		}
  
  		   <span class="category1">public</span> <span class="category1">function</span> <span class="category1">set</span> uid(u:<span class="category2">Number</span>):<span class="category1">void</span>{
      		   		_uid = u;
      		   }
  
  		   <span class="category1">public</span> <span class="category1">function</span> <span class="category2">get</span> uid():<span class="category2">Number</span>{
      	                  <span class="category1">return</span> _uid;
      		   }
  
    	}
 
}   </pre>
</code>

</div></div> 

<div style="text-align: left;">As we can see, the session will be received inside the session setter: </div>

<div class="acode" style="overflow:auto;padding:10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>

<span class="category1">public</span> <span class="category1">function</span> <span class="category1">set</span> session(f:Facebook):<span class="category1">void</span>{
 	_fBook = f;
}</pre>
</code>

</div></div> 

We need to modify the setter to start working on facebook. Inside the setter, place the following call:

<div class="acode" style="overflow:auto;padding:10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>

<span class="category1">public</span> <span class="category1">function</span> <span class="category1">set</span> session(f:Facebook):<span class="category1">void</span>{
 	_fBook = f;
         loadData();
}</pre>
</code>

</div></div> 

<div style="text-align: left;">As we can see from the sample, there will be one method that will load the desired data, very simple. Here is how it looks like:</div>

<div class="acode" style="overflow:auto;padding:10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>

<span class="category1">private</span> <span class="category1">function</span> loadData():<span class="category1">void</span>{
 
 			<span class="category1">var</span> <span class="category2">call</span>:FacebookCall = <span class="category1">new</span> GetInfo([_uid], [GetInfoFieldValues.ALL_VALUES]);
 		 	<span class="category2">call</span>.addEventListener(FacebookEvent.COMPLETE, onDataLoaded);
 			_fBook.post(<span class="category2">call</span>);
 
}</pre>
</code>

</div></div> 

<div style="text-align: left;">The whole data will be received inside this method, because we defined it that way:</div>

<div class="acode" style="overflow:auto;padding:10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>

<span class="category1">private</span> <span class="category1">function</span> onDataLoaded(e:FacebookEvent):<span class="category1">void</span>{
 	
 	<span class="linecomment">//facebook data loaded, now do some action</span>
 
}</pre>
</code>

</div></div> 

<div style="text-align: left;">Cool, now we really don&#8217;t want to get confused and therefore we really know how the whole class looks like, here is the folder:</div>

<div class="acode" style="overflow:auto;padding:10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>

package facebookUI{
  
  	<span class="category1">import</span> fl.core.UIComponent;
  	<span class="category1">import</span> flash.<span class="category2">text</span>.*;
  	<span class="category1">import</span> com.facebook.<span class="category2">data</span>.users.GetInfoData;
  	<span class="category1">import</span> com.facebook.utils.FacebookSessionUtil;
  	<span class="category1">import</span> com.facebook.<span class="category2">data</span>.users.FacebookUser;
  	<span class="category1">import</span> com.facebook.<span class="category2">data</span>.users.GetInfoFieldValues;
  	<span class="category1">import</span> com.facebook.<span class="category2">data</span>.friends.*;
  	<span class="category1">import</span> com.facebook.commands.users.*;
  	<span class="category1">import</span> com.facebook.commands.friends.*;
  	<span class="category1">import</span> com.facebook.net.FacebookCall;
  	<span class="category1">import</span> com.facebook.events.FacebookEvent;
  	<span class="category1">import</span> com.facebook.Facebook;
  
  	<span class="category1">public</span> <span class="category1">class</span> UserInfo <span class="category1">extends</span> UIComponent{
    
  		<span class="category1">private</span> <span class="category1">var</span> _fBook:Facebook;
  		<span class="category1">private</span> <span class="category1">var</span> _uid:<span class="category2">Number</span>;
    
    		<span class="category1">function</span> UserInfo() {
      		}
    
    		override protected <span class="category1">function</span> configUI():<span class="category1">void</span> {
        			<span class="category1">super</span>.configUI();
      		}
  
  		<span class="category1">private</span> <span class="category1">function</span> loadData():<span class="category1">void</span>{
   
   			<span class="category1">var</span> <span class="category2">call</span>:FacebookCall = <span class="category1">new</span> GetInfo([_uid], [GetInfoFieldValues.ALL_VALUES]);
   		 	<span class="category2">call</span>.addEventListener(FacebookEvent.COMPLETE, onDataLoaded);
   			_fBook.post(<span class="category2">call</span>);
   
   		}
  
  
  		<span class="category1">private</span> <span class="category1">function</span> onDataLoaded(e:FacebookEvent):<span class="category1">void</span>{
   	
   			<span class="category2">trace</span>("<span class="quote">data is loaded, we can play around...</span>");
   
   		}
  
    
    		<span class="category1">public</span> <span class="category1">function</span> <span class="category1">set</span> session(f:Facebook):<span class="category1">void</span>{
      			_fBook = f;
   			loadData();
      		}
  
  		<span class="category1">public</span> <span class="category1">function</span> <span class="category2">get</span> session():Facebook{
      			<span class="category1">return</span> _fBook;
      		}
  
  		<span class="category1">public</span> <span class="category1">function</span> <span class="category1">set</span> uid(u:<span class="category2">Number</span>):<span class="category1">void</span>{
      			_uid = u;
      		}
  
  		<span class="category1">public</span> <span class="category1">function</span> <span class="category2">get</span> uid():<span class="category2">Number</span>{
      			<span class="category1">return</span> _uid;
      		}
   	 
    	}
 
}</pre>
</code>

</div></div> 

<div style="text-align: left;">So we got the data, we don't have to crawl the facebook databases for information. The next step is to display the data properly. Depends on what we want to display. So, what will be displayed? </div>

<div style="text-align: left;">We don&#8217;t want the component to be extra large, we want to display data only that we want. So it would be kind of nice to have a system where we simply pass an array of values and they get displayed. Please note that we will not attempt to display any images right now, because this component will be purely text based. Here is the code how it can be done:</div>

<div class="acode" style="overflow:auto;padding:10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>

<span class="category1">public</span> <span class="category1">function</span> <span class="category1">set</span> displayFields(f:<span class="category2">Array</span>):<span class="category1">void</span> {
 			_fields = f;
 		}

<span class="category1">public</span> <span class="category1">function</span> <span class="category2">get</span> displayFields():<span class="category2">Array</span> {
 	<span class="category1">return</span> _fields;
}</pre>
</code>

</div></div> 

<div style="text-align: left;">This way we store the array of fields we want to have displayed. Because we can&#8217;t display the data immediately (before the data is loaded from FB) we have to make sure the fields are store somewhere. Finally, the display method will do the job:</div>

<div class="acode" style="overflow:auto;padding:10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>

<span class="category1">private</span> <span class="category1">function</span> onDataLoaded(e:FacebookEvent):<span class="category1">void</span>{
 	
 	<span class="category1">var</span> userData = ((e.<span class="category2">data</span> as GetInfoData).userCollection).<span class="category2">getItemAt</span>(0);
 	<span class="category1">var</span> i = 0;
 	<span class="category1">var</span> len = _fields.<span class="category2">length</span>;
 
 	<span class="category1">for</span>(i = 0; i &lt; len; i++){
  		<span class="category1">var</span> tField:<span class="category2">TextField</span> = <span class="category1">new</span> <span class="category2">TextField</span>();
  		<span class="category1">this</span>.addChild(tField);
  		<span class="category1">var</span> field = _fields[i];
  		tField.<span class="category2">text</span> = userData[field];
  		tField.<span class="category2">y</span> = tField.<span class="category2">textHeight</span> * i;
  	}
 
}</pre>
</code>

</div></div> 

<div style="text-align: left;">Back on the main TimeLine, we set the fields we want to be displayed:</div>

<div class="acode" style="overflow:auto;padding:10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>

userInfo.uid = someID;
userInfo.displayFields = ["<span class="quote">first_name</span>", "<span class="quote">last_name</span>", "<span class="quote">about_me</span>"];
userInfo.session = fbook;</pre>
</code>

</div></div> 

<div style="text-align: left;">And the result is:</div>

<br/>
<span class="mt-enclosure mt-enclosure-image" style="display: inline;"><a href="http://www.insideria.com/assets_c/2009/06/article13_img42.html" onclick="window.open('http://www.insideria.com/assets_c/2009/06/article13_img42.html','popup','width=287,height=231,scrollbars=no,resizable=no,toolbar=no,directories=no,location=no,menubar=no,status=no,left=0,top=0'); return false"><img src="http://www.insideria.com/assets_c/2009/06/article13_img4-thumb-287x231.png" width="287" height="231" alt="article13_img4.png" class="mt-image-none" style="" /></a></span>
<br/>

<div style="text-align: left;">Now we know this works. We have an array of fields:</div>

userInfo.displayFields = ["first_name", "last_name", "about_me"];

<div style="text-align: left;">that we want to display. You can experiment with other fields from the list found in http://wiki.developers.facebook.com/index.php/Users.getInfo. We can add as much fields as we want, all of the will be displayed properly below each other. </div>

<strong><div style="text-align: left;">Working on the look and feel of the component</div></strong>

<div style="text-align: left;">We completed the 2 stages and worked hard to load the data and display it, so now we need to work even harder to change the look and feel of the component. We don't want boring text fields that look like they where from the beginning of the internet, but we also don't want to add proprietary graphics that are hard to incorporate into the existing design. The idea behind all this is to make the component flexible so it fits right into all kinds of design. Let's say we have an application that deals with love relationships, we really want the data to appear in the right font and in the right font color. If we have to create a game that deals with robots, certainly we will use a technical font, choose a dark font color so all this fits right in place. </div>

<div style="text-align: left;">Take a look at those samples:</div>

<br/>
<span class="mt-enclosure mt-enclosure-image" style="display: inline;"><a href="http://www.insideria.com/assets_c/2009/06/article13_img52.html" onclick="window.open('http://www.insideria.com/assets_c/2009/06/article13_img52.html','popup','width=445,height=314,scrollbars=no,resizable=no,toolbar=no,directories=no,location=no,menubar=no,status=no,left=0,top=0'); return false"><img src="http://www.insideria.com/assets_c/2009/06/article13_img5-thumb-400x282.png" width="400" height="282" alt="article13_img5.png" class="mt-image-none" style="" /></a></span>
<br/>

<br/>
<span class="mt-enclosure mt-enclosure-image" style="display: inline;"><a href="http://www.insideria.com/assets_c/2009/06/article13_img62.html" onclick="window.open('http://www.insideria.com/assets_c/2009/06/article13_img62.html','popup','width=578,height=331,scrollbars=no,resizable=no,toolbar=no,directories=no,location=no,menubar=no,status=no,left=0,top=0'); return false"><img src="http://www.insideria.com/assets_c/2009/06/article13_img6-thumb-400x229.png" width="400" height="229" alt="article13_img6.png" class="mt-image-none" style="" /></a></span>
<br/>

<div style="text-align: left;">For this to happen, we need two component parameters that will be passed: the text size, text color and the text font. Those parameters can be added either at author time, or at run time, we will make both options available. So, let's add the two parameters in the existing class:</div>

<div class="acode" style="overflow:auto;padding:10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>


	<span class="linecomment">//font size</span>
	<span class="category1">public</span> <span class="category1">function</span> <span class="category1">set</span> fontSize(u:<span class="category2">Number</span>):<span class="category1">void</span>{
    		_fontFace = u;
    	}

	<span class="category1">public</span> <span class="category1">function</span> <span class="category2">get</span> fontSize():<span class="category2">Number</span>{
    		<span class="category1">return</span> _fontFace;
    	}

	<span class="linecomment">//font color</span>
	<span class="category1">public</span> <span class="category1">function</span> <span class="category1">set</span> fontColor(u:<span class="category2">Number</span>):<span class="category1">void</span>{
    		_fontColor = u;
    	}

	<span class="category1">public</span> <span class="category1">function</span> <span class="category2">get</span> fontColor():<span class="category2">Number</span>{
    		<span class="category1">return</span> _fontColor;
    	}

	<span class="linecomment">//font face</span>
	<span class="category1">public</span> <span class="category1">function</span> <span class="category1">set</span> fontFace(u:<span class="category2">Number</span>):<span class="category1">void</span>{
    		_fontFace = u;
    	}

	<span class="category1">public</span> <span class="category1">function</span> <span class="category2">get</span> fontFace():<span class="category2">Number</span>{
    		<span class="category1">return</span> _fontFace;
    	}</pre>
</code>

</div></div> 

<div style="text-align: left;">Let&#8217;s begin with the font face:</div>

<div class="acode" style="overflow:auto;padding:10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>


<span class="linecomment">//font face</span>
<span class="category1">public</span> <span class="category1">function</span> <span class="category1">set</span> fontFace(u:<span class="category2">Number</span>):<span class="category1">void</span>{
 	_fontFace = u;
}

<span class="category1">public</span> <span class="category1">function</span> <span class="category2">get</span> fontFace():<span class="category2">Number</span>{
   	<span class="category1">return</span> _fontFace;
}</pre>
</code>

</div></div> 

<div style="text-align: left;">Now, we need to modify the font as soon as the font is set, therefore we need the built-in invalidate() function that redraws the component. Remember the information from the article 6, where we discussed the component architecture, we need to utilize the existing structure of the component to fully take advantage of it. In our case, we need to override the draw function provided by UIComponent:</div>


<div class="acode" style="overflow:auto;padding:10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>


override protected <span class="category1">function</span> draw():<span class="category1">void</span> {
    
 	<span class="linecomment">// always call super.draw() at the end</span>
 	<span class="category1">super</span>.draw();
 
}</pre>
</code>

</div></div> 

<div style="text-align: left;"> It&#8217;s best that we place the method right below the contructor, so the complete class now look like this:</div>

<div class="acode" style="overflow:auto;padding:10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>


package facebookUI{
  
  	<span class="category1">import</span> fl.core.UIComponent;
  	<span class="category1">import</span> flash.<span class="category2">text</span>.*;
  	<span class="category1">import</span> com.facebook.<span class="category2">data</span>.users.GetInfoData;
  	<span class="category1">import</span> com.facebook.utils.FacebookSessionUtil;
  	<span class="category1">import</span> com.facebook.<span class="category2">data</span>.users.FacebookUser;
  	<span class="category1">import</span> com.facebook.<span class="category2">data</span>.users.GetInfoFieldValues;
  	<span class="category1">import</span> com.facebook.<span class="category2">data</span>.friends.*;
  	<span class="category1">import</span> com.facebook.commands.users.*;
  	<span class="category1">import</span> com.facebook.commands.friends.*;
  	<span class="category1">import</span> com.facebook.net.FacebookCall;
  	<span class="category1">import</span> com.facebook.events.FacebookEvent;
  	<span class="category1">import</span> com.facebook.Facebook;
  
  	<span class="category1">public</span> <span class="category1">class</span> UserInfo <span class="category1">extends</span> UIComponent{
    
  		<span class="category1">private</span> <span class="category1">var</span> _fBook:Facebook;
  		<span class="category1">private</span> <span class="category1">var</span> _uid:<span class="category2">Number</span>;
  		<span class="category1">private</span> <span class="category1">var</span> _fields:<span class="category2">Array</span>;
  
  		<span class="category1">private</span> <span class="category1">var</span> _fontFace:<span class="category2">String</span>;
  		<span class="category1">private</span> <span class="category1">var</span> _fontColor:<span class="category2">String</span>;
  		<span class="category1">private</span> <span class="category1">var</span> _fontSize:<span class="category2">String</span>;
    
    		<span class="category1">function</span> UserInfo() {
      		}
    
    		override protected <span class="category1">function</span> configUI():<span class="category1">void</span> {
        			<span class="category1">super</span>.configUI();
      		}
  
  		<span class="category1">private</span> <span class="category1">function</span> loadData():<span class="category1">void</span>{
   
   			<span class="category1">var</span> <span class="category2">call</span>:FacebookCall = <span class="category1">new</span> GetInfo([_uid], [GetInfoFieldValues.ALL_VALUES]);
   		 	<span class="category2">call</span>.addEventListener(FacebookEvent.COMPLETE, onDataLoaded);
   			_fBook.post(<span class="category2">call</span>);
   
   		}
  
  		<span class="category1">private</span> <span class="category1">function</span> onDataLoaded(e:FacebookEvent):<span class="category1">void</span>{
   	
   			<span class="category1">var</span> userData = ((e.<span class="category2">data</span> as GetInfoData).userCollection).<span class="category2">getItemAt</span>(0);
   			<span class="category1">var</span> i = 0;
   			<span class="category1">var</span> len = _fields.<span class="category2">length</span>;
   
   			<span class="category1">for</span>(i = 0; i &lt; len; i++){
    				<span class="category1">var</span> tField:<span class="category2">TextField</span> = <span class="category1">new</span> <span class="category2">TextField</span>();
    				<span class="category1">this</span>.addChild(tField);
    				<span class="category1">var</span> field = _fields[i];
    				tField.<span class="category2">text</span> = userData[field];
    				tField.<span class="category2">y</span> = tField.<span class="category2">textHeight</span> * i;
    			}
   
   		}
  
  		override protected <span class="category1">function</span> draw():<span class="category1">void</span> {
      
      		    <span class="linecomment">// always call super.draw() at the end</span>
      		    <span class="category1">super</span>.draw();
      
      		}	
  
  		<span class="linecomment">//fields to display</span>
  		<span class="category1">public</span> <span class="category1">function</span> <span class="category1">set</span> displayFields(f:<span class="category2">Array</span>):<span class="category1">void</span> {
   			_fields = f;
   		}
  
  		<span class="category1">public</span> <span class="category1">function</span> <span class="category2">get</span> displayFields():<span class="category2">Array</span> {
   			<span class="category1">return</span> _fields;
   		}
    
  		<span class="linecomment">//session</span>
    		<span class="category1">public</span> <span class="category1">function</span> <span class="category1">set</span> session(f:Facebook):<span class="category1">void</span>{
      			_fBook = f;
   			loadData();
      		}
  
  		<span class="category1">public</span> <span class="category1">function</span> <span class="category2">get</span> session():Facebook{
      			<span class="category1">return</span> _fBook;
      		}
  
  		<span class="linecomment">//uid</span>
  		<span class="category1">public</span> <span class="category1">function</span> <span class="category1">set</span> uid(u:<span class="category2">Number</span>):<span class="category1">void</span>{
      			_uid = u;
      		}
  
  		<span class="category1">public</span> <span class="category1">function</span> <span class="category2">get</span> uid():<span class="category2">Number</span>{
      			<span class="category1">return</span> _uid;
      		}
  
  		<span class="linecomment">//font size</span>
  		<span class="category1">public</span> <span class="category1">function</span> <span class="category1">set</span> fontSize(u:<span class="category2">Number</span>):<span class="category1">void</span>{
      			_fontFace = u;
      		}
  
  		<span class="category1">public</span> <span class="category1">function</span> <span class="category2">get</span> fontSize():<span class="category2">Number</span>{
      			<span class="category1">return</span> _fontFace;
      		}
  
  		<span class="linecomment">//font color</span>
  		<span class="category1">public</span> <span class="category1">function</span> <span class="category1">set</span> fontColor(u:<span class="category2">Number</span>):<span class="category1">void</span>{
      			_fontColor = u;
      		}
  
  		<span class="category1">public</span> <span class="category1">function</span> <span class="category2">get</span> fontColor():<span class="category2">Number</span>{
      			<span class="category1">return</span> _fontColor;
      		}
  
  		<span class="linecomment">//font face</span>
  		<span class="category1">public</span> <span class="category1">function</span> <span class="category1">set</span> fontFace(u:<span class="category2">Number</span>):<span class="category1">void</span>{
      			_fontFace = u;
      		}
  
  		<span class="category1">public</span> <span class="category1">function</span> <span class="category2">get</span> fontFace():<span class="category2">Number</span>{
      			<span class="category1">return</span> _fontFace;
      		}
  
    	}
 
} </pre>
</code>

</div></div> 

<div style="text-align: left;">Let&#8217;s concentrate on the draw() method. </div>

<div class="acode" style="overflow:auto;padding:10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>

override protected <span class="category1">function</span> draw():<span class="category1">void</span> {
    
 	<span class="linecomment">// always call super.draw() at the end</span>
    	<span class="category1">super</span>.draw();
    
}	</pre>
</code>

</div></div> 

<div style="text-align: left;">Let's say, we set the font to something else: </div>

<div class="acode" style="overflow:auto;padding:10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>


<span class="linecomment">//main timeline</span>
<span class="category1">var</span> userInfo = <span class="category1">new</span> UserInfo();
<span class="category1">this</span>.addChild(userInfo);

userInfo.fontFace = "<span class="quote">Century Gothic</span>";
userInfo.fontColor = 0xff0000;
userInfo.fontSize = 33;
userInfo.uid = someFacebookUserID;
userInfo.displayFields = ["<span class="quote">first_name</span>", "<span class="quote">last_name</span>"];
userInfo.session = fbook;</pre>
</code>

</div></div> 

<div style="text-align: left;">Here is what needs to be added to the draw function:</div>

<div class="acode" style="overflow:auto;padding:10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>


override protected <span class="category1">function</span> draw():<span class="category1">void</span> {
    
 	<span class="category1">var</span> tf:<span class="category2">TextFormat</span> = <span class="category1">new</span> <span class="category2">TextFormat</span>();
 	tf.<span class="category2">font</span> = _fontFace;
 
 	<span class="category1">var</span> i = 0; 
 	<span class="category1">var</span> len = <span class="category1">this</span>.numChildren;
 
 	<span class="category1">for</span>(i = 0; i &lt; len; i++){
  		<span class="category1">var</span> tField:<span class="category2">TextField</span> = <span class="category1">this</span>.getChildAt(i);
  		tField.<span class="category2">setTextFormat</span>(tf);
  	}
 
    	<span class="linecomment">// always call super.draw() at the end</span>
    	<span class="category1">super</span>.draw();
    
}	</pre>
</code>

</div></div> 

<div style="text-align: left;">And the uploaded result is:</div>

<br/>
<span class="mt-enclosure mt-enclosure-image" style="display: inline;"><a href="http://www.insideria.com/assets_c/2009/06/article13_img72.html" onclick="window.open('http://www.insideria.com/assets_c/2009/06/article13_img72.html','popup','width=335,height=227,scrollbars=no,resizable=no,toolbar=no,directories=no,location=no,menubar=no,status=no,left=0,top=0'); return false"><img src="http://www.insideria.com/assets_c/2009/06/article13_img7-thumb-335x227.png" width="335" height="227" alt="article13_img7.png" class="mt-image-none" style="" /></a></span>
<br/>

<div style="text-align: left;">Cool, now we have a nice way to access basic information of our friends in our applications and the component is flexible too. Before we finish, we will review the UserInfo class:</div>

<div class="acode" style="overflow:auto;padding:10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>


package facebookUI{
  
  	<span class="category1">import</span> fl.core.UIComponent;
  	<span class="category1">import</span> flash.<span class="category2">text</span>.*;
  	<span class="category1">import</span> com.facebook.<span class="category2">data</span>.users.GetInfoData;
  	<span class="category1">import</span> com.facebook.utils.FacebookSessionUtil;
  	<span class="category1">import</span> com.facebook.<span class="category2">data</span>.users.FacebookUser;
  	<span class="category1">import</span> com.facebook.<span class="category2">data</span>.users.GetInfoFieldValues;
  	<span class="category1">import</span> com.facebook.<span class="category2">data</span>.friends.*;
  	<span class="category1">import</span> com.facebook.commands.users.*;
  	<span class="category1">import</span> com.facebook.commands.friends.*;
  	<span class="category1">import</span> com.facebook.net.FacebookCall;
  	<span class="category1">import</span> com.facebook.events.FacebookEvent;
  	<span class="category1">import</span> com.facebook.Facebook;
  
  	<span class="category1">public</span> <span class="category1">class</span> UserInfo <span class="category1">extends</span> UIComponent{
  
  		<span class="category1">private</span> <span class="category1">var</span> _fBook:Facebook;
  		<span class="category1">private</span> <span class="category1">var</span> _uid:<span class="category2">Number</span>;
  		<span class="category1">private</span> <span class="category1">var</span> _fields:<span class="category2">Array</span>;
  
  		<span class="category1">private</span> <span class="category1">var</span> _fontFace:<span class="category2">String</span>;
  		<span class="category1">private</span> <span class="category1">var</span> _fontColor:<span class="category2">Number</span>;
  		<span class="category1">private</span> <span class="category1">var</span> _fontSize:<span class="category2">Number</span>;
    
    		<span class="category1">function</span> UserInfo() {
   			   		}
    
    		override protected <span class="category1">function</span> configUI():<span class="category1">void</span> {
        			<span class="category1">super</span>.configUI();
      		}
   
  		<span class="category1">private</span> <span class="category1">function</span> loadData():<span class="category1">void</span>{
   
   			<span class="category1">var</span> <span class="category2">call</span>:FacebookCall = <span class="category1">new</span> GetInfo([_uid], [GetInfoFieldValues.ALL_VALUES]);
   		 	<span class="category2">call</span>.addEventListener(FacebookEvent.COMPLETE, onDataLoaded);
   			_fBook.post(<span class="category2">call</span>);
   
   		}
   
  		<span class="category1">private</span> <span class="category1">function</span> onDataLoaded(e:FacebookEvent):<span class="category1">void</span>{
   	
   			<span class="category1">var</span> userData = ((e.<span class="category2">data</span> as GetInfoData).userCollection).<span class="category2">getItemAt</span>(0);
   			<span class="category1">var</span> i = 0;
   			<span class="category1">var</span> len = _fields.<span class="category2">length</span>;
   
   			<span class="category1">for</span>(i = 0; i &lt; len; i++){
    				<span class="category1">var</span> tField:<span class="category2">TextField</span> = <span class="category1">new</span> <span class="category2">TextField</span>();
    				<span class="category1">this</span>.addChild(tField);
    				<span class="category1">var</span> field = _fields[i];
    				tField.<span class="category2">text</span> = userData[field];
    				tField.<span class="category2">y</span> = tField.<span class="category2">textHeight</span> * i;
    			}
   
   			invalidate();
   
   		}
  
  		override protected <span class="category1">function</span> draw():<span class="category1">void</span> {
      
   			<span class="category1">var</span> tf:<span class="category2">TextFormat</span> = <span class="category1">new</span> <span class="category2">TextFormat</span>();
   			tf.<span class="category2">font</span> = _fontFace;
   			tf.<span class="category2">size</span> = _fontSize;
   			tf.<span class="category2">color</span> = _fontColor;
   
   			<span class="category1">var</span> i = 0; 
   			<span class="category1">var</span> len = <span class="category1">this</span>.numChildren;
   
   			<span class="category1">for</span>(i = 0; i &lt; len; i++){
    				<span class="category1">var</span> tField:<span class="category2">TextField</span> = <span class="category1">this</span>.getChildAt(i);
    				tField.<span class="category2">setTextFormat</span>(tf);	
    			}
   
   			<span class="category1">for</span>(i = 0; i &lt; len; i++){
    				tField.<span class="category2">width</span> = tField.<span class="category2">textWidth</span>;
    				tField.<span class="category2">height</span> = tField.<span class="category2">textHeight</span>;
    				tField.<span class="category2">y</span> = tField.<span class="category2">textHeight</span> * i;	
    			}
   
      		    <span class="linecomment">// always call super.draw() at the end</span>
      		    <span class="category1">super</span>.draw();
      
      		}	
  
  		<span class="linecomment">//fields to display</span>
  		<span class="category1">public</span> <span class="category1">function</span> <span class="category1">set</span> displayFields(f:<span class="category2">Array</span>):<span class="category1">void</span> {
   			_fields = f;
   		}
  
  		<span class="category1">public</span> <span class="category1">function</span> <span class="category2">get</span> displayFields():<span class="category2">Array</span> {
   			<span class="category1">return</span> _fields;
   		}
    
  		<span class="linecomment">//session</span>
    		<span class="category1">public</span> <span class="category1">function</span> <span class="category1">set</span> session(f:Facebook):<span class="category1">void</span>{
      			_fBook = f;
   			loadData();
      		}
  
  		<span class="category1">public</span> <span class="category1">function</span> <span class="category2">get</span> session():Facebook{
      			<span class="category1">return</span> _fBook;
      		}
  
  		<span class="linecomment">//uid</span>
  		<span class="category1">public</span> <span class="category1">function</span> <span class="category1">set</span> uid(u:<span class="category2">Number</span>):<span class="category1">void</span>{
      			_uid = u;
      		}
  
  		<span class="category1">public</span> <span class="category1">function</span> <span class="category2">get</span> uid():<span class="category2">Number</span>{
      			<span class="category1">return</span> _uid;
      		}
  
  		<span class="linecomment">//font size</span>
  		<span class="category1">public</span> <span class="category1">function</span> <span class="category1">set</span> fontSize(u:<span class="category2">Number</span>):<span class="category1">void</span>{
      			_fontSize = u;
   			invalidate();
      		}
  
  		<span class="category1">public</span> <span class="category1">function</span> <span class="category2">get</span> fontSize():<span class="category2">Number</span>{
      			<span class="category1">return</span> _fontSize;
      		}
  
  		<span class="linecomment">//font color</span>
  		<span class="category1">public</span> <span class="category1">function</span> <span class="category1">set</span> fontColor(u:<span class="category2">Number</span>):<span class="category1">void</span>{
      			_fontColor = u;
   			invalidate();
      		}
  
  		<span class="category1">public</span> <span class="category1">function</span> <span class="category2">get</span> fontColor():<span class="category2">Number</span>{
      			<span class="category1">return</span> _fontColor;
      		}
  
  		<span class="linecomment">//font face</span>
  		<span class="category1">public</span> <span class="category1">function</span> <span class="category1">set</span> fontFace(u:<span class="category2">String</span>):<span class="category1">void</span>{
      			_fontFace = u;
   			invalidate();
      		}
  
  		<span class="category1">public</span> <span class="category1">function</span> <span class="category2">get</span> fontFace():<span class="category2">String</span>{
      			<span class="category1">return</span> _fontFace;
      		}
  
    	}
 
}</pre>
</code>

</div></div> ]]>
      
    </content>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2009://34.37168-comment:2070513</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2009://34.37168" type="text/html" href="http://www.insideria.com/2009/06/user-info-component.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2009/06/user-info-component.html#comment-2070513" />
    <title>Comment from Dennis on 2009-08-17</title>
    <author>
        <name>Dennis</name>
        <uri></uri>
    </author>
    <content type="html" xml:lang="en" xml:base="">
        <![CDATA[<p>Hi Mirza<br />
Great tutorials - thank you very much. I have a small question regarding how to retrieve the location user-info.</p>

<p>In the context of your userinfo component how would i access the hometown_location / city?</p>

<p>I can access the location object but i cant seem to figure out how to obtain the children of that object.</p>

<p>Best regards</p>]]>
    </content>
    <published>2009-08-17T11:43:59Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2009://34.37168-comment:2184404</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2009://34.37168" type="text/html" href="http://www.insideria.com/2009/06/user-info-component.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2009/06/user-info-component.html#comment-2184404" />
    <title>Comment from Marcos on 2009-11-13</title>
    <author>
        <name>Marcos</name>
        <uri></uri>
    </author>
    <content type="html" xml:lang="en" xml:base="">
        <![CDATA[<p>Amazing tutorial!</p>

<p>I had some setbacks in implementing the draw functions, but identified the problem and was corrected, the fault loop!</p>

<p>Thanks,<br />
Marcos from<br />
<a href="http://www.mtksistemas.com.br">controle de acesso</a> </p>]]>
    </content>
    <published>2009-11-13T13:00:59Z</published>
  </entry>

</feed
