<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Flex Blog &#187; Examples</title>
	<atom:link href="http://www.flex-blog.com/category/examples/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.flex-blog.com</link>
	<description>Examples, News and Other Stuff</description>
	<lastBuildDate>Fri, 06 Aug 2010 15:36:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>SWIZ Framework in Flex 4 Example: Part I</title>
		<link>http://www.flex-blog.com/swiz-framework-in-flex-4-example-part-i/</link>
		<comments>http://www.flex-blog.com/swiz-framework-in-flex-4-example-part-i/#comments</comments>
		<pubDate>Fri, 06 Aug 2010 15:36:57 +0000</pubDate>
		<dc:creator>Arjan</dc:creator>
				<category><![CDATA[Examples]]></category>
		<category><![CDATA[Flash Builder]]></category>
		<category><![CDATA[Flex 4]]></category>
		<category><![CDATA[Framework]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[MVCS]]></category>
		<category><![CDATA[SWIZ]]></category>

		<guid isPermaLink="false">http://www.flex-blog.com/?p=1155</guid>
		<description><![CDATA[Line Break Author: Arjan (36 Articles) - Author Website Arjan is a SAP Consultant specialized in ABAP and Front End development techniques like Web Dynpro, Adobe Interactive Forms, Flex and AIR. In his free time he likes to create examples for Flex-Blog and other applications using Flex, AIR and PHP. Other hobbies are movies and [...]


Related posts:<ol><li><a href='http://www.flex-blog.com/the-swiz-framework-for-flex-3-flex-4-easy-light-and-very-powerfull/' rel='bookmark' title='Permanent Link: The SWIZ framework for Flex 3 / Flex 4: Easy, Light and Very Powerfull'>The SWIZ framework for Flex 3 / Flex 4: Easy, Light and Very Powerfull</a></li>
<li><a href='http://www.flex-blog.com/how-to-make-magnetic-button/' rel='bookmark' title='Permanent Link: How to make a magnetic button in Flex 4'>How to make a magnetic button in Flex 4</a></li>
<li><a href='http://www.flex-blog.com/flex-custom-event-example/' rel='bookmark' title='Permanent Link: Flex Custom Event Example'>Flex Custom Event Example</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div class="TweetButton_button" style="float: right; margin-left: 10px;;height:20px;margin-bottom:5px;">
<p>			<a href="http://twitter.com/share?url=http%3A%2F%2Fwww.flex-blog.com%2Fswiz-framework-in-flex-4-example-part-i%2F&amp;text=SWIZ Framework in Flex 4 Example: Part I&amp;count=vertical&amp;via=FlexBlog&amp;lang=en&amp;related=Flash+Builder,Flex+4,Framework,MVC,MVCS,SWIZ"></p>
<p>				<img src="http://www.flex-blog.com/wp-content/plugins/tweetbutton-for-wordpress/images/tweet.png" style="border:none" /></p>
<p>			</a></p></div>
<p><small style="visibility:hidden; font-size:1px;">Line Break</small>
<div class="atab_box">
<p><b>Author: <a href="http://www.flex-blog.com/author/admin/">Arjan</a></b> <small>(36 Articles)</small> - <a href="http://www.flex-blog.com">Author Website</a></p>
<img alt='' src='http://0.gravatar.com/avatar/29187d7302c1efbed2d457ec26cfbe4d?s=50&amp;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D50&amp;r=G' class='avatar avatar-50 photo' height='50' width='50' />
<p style="min-height:65px;">Arjan is a SAP Consultant specialized in ABAP and Front End development techniques like Web Dynpro, Adobe Interactive Forms, Flex and AIR. In his free time he likes to create examples for Flex-Blog and other applications using Flex, AIR and PHP. Other hobbies are movies and music. He is also the co-owner of Flex-Blog.com.</p>
</div><p><br />
A few weeks ago I posted about the SWIZ Framework. The post was useless, but I was so enthusiastic about SWIZ, that I had to post something at that time. This post will be more usefull, I promise. Lets see how we can get the SWIZ Framework working in combination with the Flex 4 SDK.<br />
<span id="more-1155"></span><br />
First, you may want to find out about flex frameworks, MVC(S) in general if you don&#8217;t know anything about them. Its really helpful to have some sort of understandig why we want to do things using the MVC paradigm and how we can use frameworks to help us to achieve that.<br />
</br><br />
Try to understand the basics of flex frameworks (Cairngorm, PureMVC, SWIZ etc. etc.) and MVC(S) by reading about them before you start developing applications. As I found out, understanding the concepts is really important. Just visit some framework / MVC sites and wiki&#8217;s to get a basic understanding.<br />
</br><br />
Im not gonna talk about the pro and cons of certain frameworks here. All I know is that I know a few of them and SWIZ is the only one that I really like for a few simple reasons:</p>
<ul>
<li>It doesn&#8217;t slow down you development time at all</li>
<li>Easy to understand</li>
<li>Easy to apply</li>
<li>Its MVC(S), but that applies to all the major frameworks</li>
</ul>
<p>Now enough about all that, lets create a simple application with MySQL, PHP and Flex 4 using SWIZ. First, you will need the SWIZ swc file, at this time, the latest release is 1.0 RC1, you can download it <a href="http://swizframework.jira.com/wiki/download/attachments/1998854/swiz-framework-1.0.0-RC1.zip">here</a>.</p>
<p>Lets discuss the functional specs of our mini flex application briefly before we start building it. What I want is the following:</p>
<p><strong>Storage:</strong></p>
<ul>
<li>Store company data (name and location)
<li>Store contact persons for companies (firstname, lastname)
</ul>
<p><strong>Application:</strong></p>
<ul>
<li>List of companies showing name and location
<li>List of contact persons of the selected company (loaded when user selects a company).
</ul>
<p>This post, Part I will only cover the first item in our list. In part II, we are going to handle item two in our list. </p>
<p>Let&#8217;s get started. First, we&#8217;ll need some database and two tables to facilitate this. In this example we are using PHP and MySQL so I used PHPMyAdmin to create the following:</p>
<ul>
<li>A table company which has 3 fields: id (int, auto increment primary key), name (text 100) and location (text 100)
<li>A table contactperson which has 4 fields: id (int auto increment primary key), companyid (int), firstname (text 100) and lastname (text 100).
</ul>
<p>Add some dummy data to both tables using phpMyAdmin.</p>
<p>When you&#8217;re finished you&#8217;re ready to start coding in Flex. Start your Flash Builder 4 and create a new project (in my case I called it SimpleSWIZExamplePart1).</br></p>
<p>After that, add the SWIZ swc file to you libs folder inside your project folder. You can just drag and drop it from your filesystem to do this. Now you&#8217;re all set to start using SWIZ. First, lets add the basic configuration to our main application file:</p>
<div class="codecolorer-container actionscript mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #66cc66;">&lt;</span>fx:Declarations<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>swiz:Swiz beanProviders=<span style="color: #ff0000;">&quot;{[]}&quot;</span><span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>swiz:config<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>swiz:SwizConfig setUpEventType=<span style="color: #ff0000;">&quot;creationComplete&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;setUpEventPhase=<span style="color: #ff0000;">&quot;{ EventPhase.CAPTURING_PHASE } &quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;setUpEventPriority=<span style="color: #ff0000;">&quot;50&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;tearDownEventType=<span style="color: #ff0000;">&quot;{ Event.REMOVED_FROM_STAGE }&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;tearDownEventPhase=<span style="color: #ff0000;">&quot;{ EventPhase.CAPTURING_PHASE }&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;tearDownEventPriority=<span style="color: #ff0000;">&quot;50&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;strict=<span style="color: #ff0000;">&quot;true&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;viewPackages=<span style="color: #ff0000;">&quot;com.flexblog.swizexample.view.*&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;defaultFaultHandler=<span style="color: #ff0000;">&quot;onFault&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;defaultDispatcher=<span style="color: #ff0000;">&quot;dispatcher&quot;</span> <span style="color: #66cc66;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;/</span>swiz:config<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;/</span>swiz:Swiz<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <br />
<span style="color: #66cc66;">&lt;/</span>fx:Declarations<span style="color: #66cc66;">&gt;</span></div></td></tr></tbody></table></div>
<p>Notice that you can set some properties, the most important one is viewPackages. Later on, you&#8217;ll have to specify your own package here. Notice that there&#8217;s a defaultFaultHandler in the configuration which calls a function onFault, this requires a tiny bit of script in your main application file:</p>
<div class="codecolorer-container actionscript mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #66cc66;">&lt;</span>fx:Script<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;!</span><span style="color: #66cc66;">&#91;</span>CDATA<span style="color: #66cc66;">&#91;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">controls</span>.<span style="color: #006600;">Alert</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">rpc</span>.<span style="color: #006600;">events</span>.<span style="color: #006600;">FaultEvent</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> onFault<span style="color: #66cc66;">&#40;</span>event:FaultEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Alert.<span style="color: #0066CC;">show</span><span style="color: #66cc66;">&#40;</span> event.<span style="color: #006600;">fault</span>.<span style="color: #0066CC;">message</span>, <span style="color: #ff0000;">&quot;Error&quot;</span> <span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&gt;</span><br />
<span style="color: #66cc66;">&lt;/</span>fx:Script<span style="color: #66cc66;">&gt;</span></div></td></tr></tbody></table></div>
<p>First we&#8217;re going to create our application model. Create a package structure first, for example com.flexblog.swizexample. In that package, create another package called model. Inside that model package, create an ActionScript class called Model.as. This class is going to be our central data store in the application. Here&#8217;s the code for the initial model class:</p>
<div class="codecolorer-container actionscript mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">package com.<span style="color: #006600;">flexblog</span>.<span style="color: #006600;">swizexample</span>.<span style="color: #006600;">model</span><br />
<span style="color: #66cc66;">&#123;</span> &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">collections</span>.<span style="color: #006600;">ArrayCollection</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Model<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/**<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* List of companies<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#91;</span>Bindable<span style="color: #66cc66;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> companies:ArrayCollection;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> Model<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #66cc66;">&#125;</span></div></td></tr></tbody></table></div>
<p>As you can see, the model has on variable called companies, this is going to hold the list of companies that we retrieve from the backend using a service (which is called by a controller). You still with me? Let create the ActionScript service that communicates with the backend.</p>
<p>To create the service, we can use one of the great new features of Flash Builder 4 to connect with out database. Click on the data button in Flash Builder 4, select Connect to PHP and click the generate sample link. Connect to your local mysql server. In my case: user / pass, hostname: localhost, port: 3306. After that, select the company table. Flash Builder automatically generates a PHP file for you that communicates with the back-end! Make sure you give the service an appropriate name (e.g. CompanyService) and put your newly created actionscript class in a services package, for example com.flexblog.swizdemo.services, for the datatype package, use com.flexblog.swizexample.domain.</p>
<p>Now to execute this service, we are going to create a Controller. Create a new package called controller inside your &#8220;main&#8221; package. In my example the package is com.flexblog.swizexample.controller. Inside the package, create a new ActionScript class called CompanyController.as. Put the following code in the class:</p>
<div class="codecolorer-container actionscript mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">package com.<span style="color: #006600;">flexblog</span>.<span style="color: #006600;">swizexample</span>.<span style="color: #006600;">controller</span><br />
<span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">import</span> com.<span style="color: #006600;">flexblog</span>.<span style="color: #006600;">swizexample</span>.<span style="color: #006600;">model</span>.<span style="color: #006600;">Model</span>;<br />
&nbsp; &nbsp; <span style="color: #0066CC;">import</span> com.<span style="color: #006600;">flexblog</span>.<span style="color: #006600;">swizexample</span>.<span style="color: #006600;">services</span>.<span style="color: #006600;">CompanyService</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">collections</span>.<span style="color: #006600;">ArrayCollection</span>;<br />
&nbsp; &nbsp; <span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">controls</span>.<span style="color: #006600;">Alert</span>;<br />
&nbsp; &nbsp; <span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">rpc</span>.<span style="color: #006600;">events</span>.<span style="color: #006600;">FaultEvent</span>;<br />
&nbsp; &nbsp; <span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">rpc</span>.<span style="color: #006600;">events</span>.<span style="color: #006600;">ResultEvent</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0066CC;">import</span> org.<span style="color: #006600;">swizframework</span>.<span style="color: #006600;">utils</span>.<span style="color: #006600;">services</span>.<span style="color: #006600;">ServiceHelper</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> CompanyController <span style="color: #0066CC;">extends</span> AbstractController<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/**<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* companyService, Injected by SWIZ Framework<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#91;</span>Inject<span style="color: #66cc66;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> companyService:CompanyService;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> CompanyController<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/**<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* Automatically called by SWIZ Framework after<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* application startup by using the [PostConstruct] tag<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#91;</span>PostConstruct<span style="color: #66cc66;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getAllCompanies<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sh.<span style="color: #006600;">executeServiceCall</span><span style="color: #66cc66;">&#40;</span> companyService.<span style="color: #006600;">getAllCompany</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>, handleGetAllResult, handleFault <span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> handleGetAllResult<span style="color: #66cc66;">&#40;</span>event:ResultEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; model.<span style="color: #006600;">companies</span> = event.<span style="color: #006600;">result</span> as ArrayCollection;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> handleFault<span style="color: #66cc66;">&#40;</span>event:FaultEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Alert.<span style="color: #0066CC;">show</span><span style="color: #66cc66;">&#40;</span> event.<span style="color: #006600;">fault</span>.<span style="color: #0066CC;">message</span>, <span style="color: #ff0000;">&quot;Error&quot;</span> <span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #66cc66;">&#125;</span></div></td></tr></tbody></table></div>
<p>Notice the [PostConstruct] tag above the getAllCompanies() method. This nice SWIZ metadata tag lets SWIZ know that it should automatically execute the method decorated with that tag on application startup. Very nice!</p>
<p>As you can see, the CompanyController extends a Class called AbstractController which holds some things that all my Controllers are going to need, create that class as well:</p>
<div class="codecolorer-container actionscript mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">package com.<span style="color: #006600;">flexblog</span>.<span style="color: #006600;">swizexample</span>.<span style="color: #006600;">controller</span><br />
<span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">import</span> com.<span style="color: #006600;">flexblog</span>.<span style="color: #006600;">swizexample</span>.<span style="color: #006600;">model</span>.<span style="color: #006600;">Model</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0066CC;">import</span> org.<span style="color: #006600;">swizframework</span>.<span style="color: #006600;">utils</span>.<span style="color: #006600;">services</span>.<span style="color: #006600;">ServiceHelper</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> AbstractController<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/**<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* ServiceHelper to facilitate service calls, Injected by SWIZ Framework<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#91;</span>Inject<span style="color: #66cc66;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> sh:ServiceHelper;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/**<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* Application model, Injected by SWIZ Framework<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#91;</span>Inject<span style="color: #66cc66;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> model:Model;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> AbstractController<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #66cc66;">&#125;</span></div></td></tr></tbody></table></div>
<p>Now we need to do some additional things to make these classes work. As you can see i&#8217;m using variables called companyService, model and serviceHelper which are never instantiated&#8230;here&#8217;s where SWIZ helps you with a great little thing called <a href="http://en.wikipedia.org/wiki/Dependency_injection">Dependency Injection</a>: it automatically creates an object of type CompanyService for you when it&#8217;s needed. Strange when you see it for the first time but it helps you A LOT.</p>
<p>To let SWIZ tie everything together, we need something called a BeanProvider. Create a new MXML component called Beans.mxml in you main package (com.flexblog.siwzexample) based on anything and replace all the code with the following:</p>
<div class="codecolorer-container actionscript mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #66cc66;">&lt;</span>?<span style="color: #0066CC;">xml</span> <span style="color: #0066CC;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #66cc66;">&gt;</span><br />
<span style="color: #66cc66;">&lt;</span>swiz:BeanProvider xmlns:fx=<span style="color: #ff0000;">&quot;http://ns.adobe.com/mxml/2009&quot;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; xmlns:s=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/spark&quot;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; xmlns:mx=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/mx&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; xmlns:swiz=<span style="color: #ff0000;">&quot;http://swiz.swizframework.org&quot;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; xmlns:controller=<span style="color: #ff0000;">&quot;com.flexblog.swizexample.controller.*&quot;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; xmlns:services=<span style="color: #ff0000;">&quot;com.flexblog.swizexample.services.*&quot;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; xmlns:model=<span style="color: #ff0000;">&quot;com.flexblog.swizexample.model.*&quot;</span> <span style="color: #66cc66;">&gt;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>controller:CompanyController id=<span style="color: #ff0000;">&quot;companyController&quot;</span><span style="color: #66cc66;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>services:CompanyService id=<span style="color: #ff0000;">&quot;companyService&quot;</span><span style="color: #66cc66;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>swiz:ServiceHelper id=<span style="color: #ff0000;">&quot;serviceHelper&quot;</span><span style="color: #66cc66;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>model:Model id=<span style="color: #ff0000;">&quot;model&quot;</span><span style="color: #66cc66;">/&gt;</span><br />
&nbsp; &nbsp; <br />
<span style="color: #66cc66;">&lt;/</span>swiz:BeanProvider<span style="color: #66cc66;">&gt;</span></div></td></tr></tbody></table></div>
<p>With this, SWIZ knows that it should do Dependency injection on all Objects of type Model, CompanyController, CompanyService and ServiceHelper when the variables have the [Inject] metadata tag.</p>
<p>Now with that out of the way lets set up a view that can display our company details. First, create a view package that can hold all your MXML view components. In my example the package is com.swizexample.view. After that, create a new MXML component inside that package called MainView.mxml. Make sure it&#8217;s based on a VGroup and remove the height and width details. After that, create a new MXML component called CompanyView.mxml, also based on a VGroup, remove the width and height here too.</p>
<p>Now you should have 2 new MXML components. Add the MainView.mxml to your application file like this:</p>
<div class="codecolorer-container actionscript mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #66cc66;">&lt;</span>view:MainView id=<span style="color: #ff0000;">&quot;mainView&quot;</span> <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;100%&quot;</span> <span style="color: #0066CC;">height</span>=<span style="color: #ff0000;">&quot;100%&quot;</span><span style="color: #66cc66;">/&gt;</span></div></td></tr></tbody></table></div>
<p>And add the CompanyView to your mainview:</p>
<div class="codecolorer-container actionscript mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #66cc66;">&lt;</span>view:CompanyView id=<span style="color: #ff0000;">&quot;companyView&quot;</span> <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;100%&quot;</span> <span style="color: #0066CC;">height</span>=<span style="color: #ff0000;">&quot;100%&quot;</span><span style="color: #66cc66;">/&gt;</span></div></td></tr></tbody></table></div>
<p>Ok, now lets finish our CompanyView, we will just add a basic DataGrid to list all companies with a simple title to it:</p>
<div class="codecolorer-container actionscript mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #66cc66;">&lt;</span>s:Label <span style="color: #0066CC;">text</span>=<span style="color: #ff0000;">&quot;Companies&quot;</span> fontWeight=<span style="color: #ff0000;">&quot;bold&quot;</span><span style="color: #66cc66;">/&gt;</span><br />
<span style="color: #66cc66;">&lt;</span>mx:DataGrid dataProvider=<span style="color: #ff0000;">&quot;{model.companies}&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;100%&quot;</span> <span style="color: #0066CC;">height</span>=<span style="color: #ff0000;">&quot;100%&quot;</span><span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>mx:columns<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>mx:DataGridColumn headerText=<span style="color: #ff0000;">&quot;Name&quot;</span> dataField=<span style="color: #ff0000;">&quot;name&quot;</span><span style="color: #66cc66;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>mx:DataGridColumn headerText=<span style="color: #ff0000;">&quot;Location&quot;</span> dataField=<span style="color: #ff0000;">&quot;location&quot;</span><span style="color: #66cc66;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;/</span>mx:columns<span style="color: #66cc66;">&gt;</span><br />
<span style="color: #66cc66;">&lt;/</span>mx:DataGrid<span style="color: #66cc66;">&gt;</span></div></td></tr></tbody></table></div>
<p>As you can see, the CompanyView uses model.companies as the dataprovider for the datagrid. To make it a bit more complicated, this is <strong>not</strong> the model we discussed earlier. This model is acutally a new ActionScript class called CompanyViewPresentationModel.as which is going to be the <a href="http://swizframework.jira.com/wiki/display/SWIZ/Presentation+Model">Presentation Model</a> of our CompanyView. Still with me? Create a new subpackage in the model package called presentation. Inside that package, create the CompanyViewPresentationModel.as class:</p>
<div class="codecolorer-container actionscript mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">package com.<span style="color: #006600;">flexblog</span>.<span style="color: #006600;">swizexample</span>.<span style="color: #006600;">model</span>.<span style="color: #006600;">presentation</span><br />
<span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">collections</span>.<span style="color: #006600;">ArrayCollection</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> CompanyViewPresentationModel<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/**<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* List of companies, injected and binded to the application model using SWIZ<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#91;</span>Bindable<span style="color: #66cc66;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#91;</span>Inject<span style="color: #66cc66;">&#40;</span>source=<span style="color: #ff0000;">&quot;model.companies&quot;</span>, bind=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> companies:ArrayCollection;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> CompanyViewPresentationModel<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #66cc66;">&#125;</span></div></td></tr></tbody></table></div>
<p>As you can see it also has a companies variable. This companies variable is binded to the global model (Model.as) using the SWIZ [Inject(source="model.companies", bind=true)] tag.</p>
<p>Also add this new Class to your Beans.mxml file so that SWIZ can Inject this in your view.</p>
<div class="codecolorer-container actionscript mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #66cc66;">&lt;</span>presentation:CompanyViewPresentationModel id=<span style="color: #ff0000;">&quot;companyViewPresentationModel&quot;</span><span style="color: #66cc66;">/&gt;</span></div></td></tr></tbody></table></div>
<p>Now add the following to your CompanyView:</p>
<div class="codecolorer-container actionscript mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #66cc66;">&lt;</span>fx:Script<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;!</span><span style="color: #66cc66;">&#91;</span>CDATA<span style="color: #66cc66;">&#91;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">import</span> com.<span style="color: #006600;">flexblog</span>.<span style="color: #006600;">swizexample</span>.<span style="color: #006600;">model</span>.<span style="color: #006600;">presentation</span>.<span style="color: #006600;">CompanyViewPresentationModel</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/**<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* The presentation model for the CompanyView,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* Injected by SWIZ<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#91;</span>Inject<span style="color: #66cc66;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#91;</span>Bindable<span style="color: #66cc66;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> model:CompanyViewPresentationModel;<br />
<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&gt;</span><br />
<span style="color: #66cc66;">&lt;/</span>fx:Script<span style="color: #66cc66;">&gt;</span></div></td></tr></tbody></table></div>
<p>Ok, now you&#8217;re ready to finish configuring SWIZ in your application file. Add the Beans.mxml to the swiz config (and import the Beans.mxml in the script section) and make sure the viewPackages property is ok:</p>
<div class="codecolorer-container actionscript mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #66cc66;">&lt;</span>fx:Declarations<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>swiz:Swiz beanProviders=<span style="color: #ff0000;">&quot;{[Beans]}&quot;</span><span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>swiz:config<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>swiz:SwizConfig setUpEventType=<span style="color: #ff0000;">&quot;creationComplete&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;setUpEventPhase=<span style="color: #ff0000;">&quot;{ EventPhase.CAPTURING_PHASE } &quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;setUpEventPriority=<span style="color: #ff0000;">&quot;50&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;tearDownEventType=<span style="color: #ff0000;">&quot;{ Event.REMOVED_FROM_STAGE }&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;tearDownEventPhase=<span style="color: #ff0000;">&quot;{ EventPhase.CAPTURING_PHASE }&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;tearDownEventPriority=<span style="color: #ff0000;">&quot;50&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;strict=<span style="color: #ff0000;">&quot;true&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;viewPackages=<span style="color: #ff0000;">&quot;com.flexblog.swizexample.view.*&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;defaultFaultHandler=<span style="color: #ff0000;">&quot;onFault&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;defaultDispatcher=<span style="color: #ff0000;">&quot;dispatcher&quot;</span> <span style="color: #66cc66;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;/</span>swiz:config<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;/</span>swiz:Swiz<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <br />
<span style="color: #66cc66;">&lt;/</span>fx:Declarations<span style="color: #66cc66;">&gt;</span></div></td></tr></tbody></table></div>
<p>That should be it. Try running your application. If everything is ok, you should see a list of companies from your local database (if you added the dummy data, ofcourse).</p>
<p>Something like this, view source is enabled. Check out the ASDoc <a href="http://www.flex-blog.com/samples/sample45/asdoc-output/index.html" target="_blank">here</a>:</p>
<p><iframe src="http://www.flex-blog.com/samples/sample45/SimpleSWIZExamplePart1.html" width="100%" frameborder="0" height="250"></iframe></p>


<p>Related posts:<ol><li><a href='http://www.flex-blog.com/the-swiz-framework-for-flex-3-flex-4-easy-light-and-very-powerfull/' rel='bookmark' title='Permanent Link: The SWIZ framework for Flex 3 / Flex 4: Easy, Light and Very Powerfull'>The SWIZ framework for Flex 3 / Flex 4: Easy, Light and Very Powerfull</a></li>
<li><a href='http://www.flex-blog.com/how-to-make-magnetic-button/' rel='bookmark' title='Permanent Link: How to make a magnetic button in Flex 4'>How to make a magnetic button in Flex 4</a></li>
<li><a href='http://www.flex-blog.com/flex-custom-event-example/' rel='bookmark' title='Permanent Link: Flex Custom Event Example'>Flex Custom Event Example</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.flex-blog.com/swiz-framework-in-flex-4-example-part-i/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Dynamic AdvancedDataGridColumn in Flex 4</title>
		<link>http://www.flex-blog.com/dynamic-advanceddatagridcolumn-in-flex-4/</link>
		<comments>http://www.flex-blog.com/dynamic-advanceddatagridcolumn-in-flex-4/#comments</comments>
		<pubDate>Wed, 04 Aug 2010 18:08:54 +0000</pubDate>
		<dc:creator>Arjan</dc:creator>
				<category><![CDATA[Examples]]></category>
		<category><![CDATA[AdvancedDataGrid]]></category>
		<category><![CDATA[AdvancedDataGridColumn]]></category>
		<category><![CDATA[Dynamic]]></category>
		<category><![CDATA[Flex 4]]></category>

		<guid isPermaLink="false">http://www.flex-blog.com/?p=1227</guid>
		<description><![CDATA[Line Break Author: Arjan (36 Articles) - Author Website Arjan is a SAP Consultant specialized in ABAP and Front End development techniques like Web Dynpro, Adobe Interactive Forms, Flex and AIR. In his free time he likes to create examples for Flex-Blog and other applications using Flex, AIR and PHP. Other hobbies are movies and [...]


Related posts:<ol><li><a href='http://www.flex-blog.com/flex-dynamic-chart/' rel='bookmark' title='Permanent Link: Flex Dynamic Chart Example'>Flex Dynamic Chart Example</a></li>
<li><a href='http://www.flex-blog.com/style-advanceddatagrid-depending-on-data-example/' rel='bookmark' title='Permanent Link: Style AdvancedDataGrid depending on data example'>Style AdvancedDataGrid depending on data example</a></li>
<li><a href='http://www.flex-blog.com/tree-in-advanced-datagrid-example/' rel='bookmark' title='Permanent Link: Tree in Advanced DataGrid Example'>Tree in Advanced DataGrid Example</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div class="TweetButton_button" style="float: right; margin-left: 10px;;height:20px;margin-bottom:5px;">
<p>			<a href="http://twitter.com/share?url=http%3A%2F%2Fwww.flex-blog.com%2Fdynamic-advanceddatagridcolumn-in-flex-4%2F&amp;text=Dynamic AdvancedDataGridColumn in Flex 4&amp;count=vertical&amp;via=FlexBlog&amp;lang=en&amp;related=AdvancedDataGrid,AdvancedDataGridColumn,Dynamic,Flex+4"></p>
<p>				<img src="http://www.flex-blog.com/wp-content/plugins/tweetbutton-for-wordpress/images/tweet.png" style="border:none" /></p>
<p>			</a></p></div>
<p><small style="visibility:hidden; font-size:1px;">Line Break</small>
<div class="atab_box">
<p><b>Author: <a href="http://www.flex-blog.com/author/admin/">Arjan</a></b> <small>(36 Articles)</small> - <a href="http://www.flex-blog.com">Author Website</a></p>
<img alt='' src='http://0.gravatar.com/avatar/29187d7302c1efbed2d457ec26cfbe4d?s=50&amp;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D50&amp;r=G' class='avatar avatar-50 photo' height='50' width='50' />
<p style="min-height:65px;">Arjan is a SAP Consultant specialized in ABAP and Front End development techniques like Web Dynpro, Adobe Interactive Forms, Flex and AIR. In his free time he likes to create examples for Flex-Blog and other applications using Flex, AIR and PHP. Other hobbies are movies and music. He is also the co-owner of Flex-Blog.com.</p>
</div><p><br />
This little example shows you how you can add an AdvancedDataGrid column to your AdvancedDataGrid dynamically.<br />
<span id="more-1227"></span><br />
First lets create a simple layout to hold our AdvancedDataGrid in your application file:</p>
<div class="codecolorer-container actionscript mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #66cc66;">&lt;</span>s:layout<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>s:VerticalLayout paddingLeft=<span style="color: #ff0000;">&quot;5&quot;</span> paddingTop=<span style="color: #ff0000;">&quot;5&quot;</span><span style="color: #66cc66;">/&gt;</span><br />
<span style="color: #66cc66;">&lt;/</span>s:layout<span style="color: #66cc66;">&gt;</span><br />
<span style="color: #66cc66;">&lt;</span>mx:AdvancedDataGrid id=<span style="color: #ff0000;">&quot;adg&quot;</span> dataProvider=<span style="color: #ff0000;">&quot;{ac}&quot;</span> <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;450&quot;</span> <span style="color: #0066CC;">height</span>=<span style="color: #ff0000;">&quot;250&quot;</span><span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>mx:columns<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>mx:AdvancedDataGridColumn dataField=<span style="color: #ff0000;">&quot;firstname&quot;</span> headerText=<span style="color: #ff0000;">&quot;Firstname&quot;</span><span style="color: #66cc66;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;/</span>mx:columns<span style="color: #66cc66;">&gt;</span><br />
<span style="color: #66cc66;">&lt;/</span>mx:AdvancedDataGrid<span style="color: #66cc66;">&gt;</span><br />
<span style="color: #66cc66;">&lt;/</span>s:Application<span style="color: #66cc66;">&gt;</span></div></td></tr></tbody></table></div>
<p>Notice that the AdvancedDataGrid uses a dataProvider, declare that in your script section:</p>
<div class="codecolorer-container actionscript mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">collections</span>.<span style="color: #006600;">ArrayCollection</span>;<br />
<br />
<span style="color: #66cc66;">&#91;</span>Bindable<span style="color: #66cc66;">&#93;</span><br />
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> ac:ArrayCollection;</div></td></tr></tbody></table></div>
<p>Now create a method init() that&#8217;s called on the initialize event of the application that fills the ArrayCollection with some dummy data:</p>
<div class="codecolorer-container actionscript mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> init<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><br />
<span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Create some dummy data</span><br />
&nbsp; &nbsp; ac = <span style="color: #000000; font-weight: bold;">new</span> ArrayCollection<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> obj:<span style="color: #0066CC;">Object</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Object</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; obj.<span style="color: #006600;">firstname</span> = <span style="color: #ff0000;">&quot;John&quot;</span>;<br />
&nbsp; &nbsp; obj.<span style="color: #006600;">lastname</span> = <span style="color: #ff0000;">&quot;Doe&quot;</span>;<br />
&nbsp; &nbsp; ac.<span style="color: #006600;">addItem</span><span style="color: #66cc66;">&#40;</span>obj<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; obj = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Object</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; obj.<span style="color: #006600;">firstname</span> = <span style="color: #ff0000;">&quot;Jane&quot;</span>;<br />
&nbsp; &nbsp; obj.<span style="color: #006600;">lastname</span> = <span style="color: #ff0000;">&quot;Doughnut&quot;</span>;<br />
&nbsp; &nbsp; ac.<span style="color: #006600;">addItem</span><span style="color: #66cc66;">&#40;</span>obj<span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #66cc66;">&#125;</span></div></td></tr></tbody></table></div>
<p>Now lets create the stuff that&#8217;s going to help us add a column to our existing AdvancedDataGrid. First create a button<br />
above the AdvancedDataGrid in the layout:</p>
<div class="codecolorer-container actionscript mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #66cc66;">&lt;</span>s:<span style="color: #0066CC;">Button</span> id=<span style="color: #ff0000;">&quot;addColumnBtn&quot;</span> click=<span style="color: #ff0000;">&quot;addColumn()&quot;</span> label=<span style="color: #ff0000;">&quot;Add Last Name Column&quot;</span><span style="color: #66cc66;">/&gt;</span></div></td></tr></tbody></table></div>
<p>Notice that it calls a method addColumn(), lets add that to our script section:</p>
<div class="codecolorer-container actionscript mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> addColumn<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><br />
<span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Get the AdvancedDataGrid colums (array)</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> columns:<span style="color: #0066CC;">Array</span> = adg.<span style="color: #006600;">columns</span>;<br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Create new AdvancedDataGridColumn</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> adgColumn:AdvancedDataGridColumn = <span style="color: #000000; font-weight: bold;">new</span> AdvancedDataGridColumn<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Set the headerText and dataField properties</span><br />
&nbsp; &nbsp; adgColumn.<span style="color: #006600;">headerText</span> = <span style="color: #ff0000;">&quot;Lastname&quot;</span>;<br />
&nbsp; &nbsp; adgColumn.<span style="color: #006600;">dataField</span> = <span style="color: #ff0000;">&quot;lastname&quot;</span>;<br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Set the column width</span><br />
&nbsp; &nbsp; adgColumn.<span style="color: #0066CC;">width</span> = <span style="color: #cc66cc;">225</span>;<br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// add the new column to the existing column array with the push() method</span><br />
&nbsp; &nbsp; columns.<span style="color: #0066CC;">push</span><span style="color: #66cc66;">&#40;</span>adgColumn<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// set the AdvancedDataGrid columns to the array of columns</span><br />
&nbsp; &nbsp; adg.<span style="color: #006600;">columns</span> = columns;<br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Hide the Button</span><br />
&nbsp; &nbsp; addColumnBtn.<span style="color: #0066CC;">visible</span> = <span style="color: #000000; font-weight: bold;">false</span>;<br />
<span style="color: #66cc66;">&#125;</span></div></td></tr></tbody></table></div>
<p>Run the application, at first you should see one column with the button to add the second column. After you&#8217;ve clicked it, the second column appears and the button disappears.</p>
<p>Check out the sample application:</p>
<p><iframe src="http://www.flex-blog.com/samples/sample44/DynamicAdvancedDataGridColumn.html" width="100%" frameborder="0" height="300"></iframe></p>
<p>Here&#8217;s the complete source code:</p>
<div class="codecolorer-container actionscript mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #66cc66;">&lt;</span>?<span style="color: #0066CC;">xml</span> <span style="color: #0066CC;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #66cc66;">&gt;</span><br />
<span style="color: #66cc66;">&lt;</span>s:Application xmlns:fx=<span style="color: #ff0000;">&quot;http://ns.adobe.com/mxml/2009&quot;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;xmlns:s=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/spark&quot;</span> initialize=<span style="color: #ff0000;">&quot;init()&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;xmlns:mx=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/mx&quot;</span> minWidth=<span style="color: #ff0000;">&quot;955&quot;</span> minHeight=<span style="color: #ff0000;">&quot;600&quot;</span><span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>fx:Declarations<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;!</span>-- Place non-visual elements <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>.<span style="color: #006600;">g</span>., services, value objects<span style="color: #66cc66;">&#41;</span> here --<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;/</span>fx:Declarations<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>fx:Script<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;!</span><span style="color: #66cc66;">&#91;</span>CDATA<span style="color: #66cc66;">&#91;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">collections</span>.<span style="color: #006600;">ArrayCollection</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#91;</span>Bindable<span style="color: #66cc66;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> ac:ArrayCollection;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> init<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Create some dummy data</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ac = <span style="color: #000000; font-weight: bold;">new</span> ArrayCollection<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> obj:<span style="color: #0066CC;">Object</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Object</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; obj.<span style="color: #006600;">firstname</span> = <span style="color: #ff0000;">&quot;John&quot;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; obj.<span style="color: #006600;">lastname</span> = <span style="color: #ff0000;">&quot;Doe&quot;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ac.<span style="color: #006600;">addItem</span><span style="color: #66cc66;">&#40;</span>obj<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; obj = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Object</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; obj.<span style="color: #006600;">firstname</span> = <span style="color: #ff0000;">&quot;Jane&quot;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; obj.<span style="color: #006600;">lastname</span> = <span style="color: #ff0000;">&quot;Doughnut&quot;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ac.<span style="color: #006600;">addItem</span><span style="color: #66cc66;">&#40;</span>obj<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> addColumn<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Get the AdvancedDataGrid colums (array)</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> columns:<span style="color: #0066CC;">Array</span> = adg.<span style="color: #006600;">columns</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Create new AdvancedDataGridColumn</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> adgColumn:AdvancedDataGridColumn = <span style="color: #000000; font-weight: bold;">new</span> AdvancedDataGridColumn<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Set the headerText and dataField properties</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; adgColumn.<span style="color: #006600;">headerText</span> = <span style="color: #ff0000;">&quot;Lastname&quot;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; adgColumn.<span style="color: #006600;">dataField</span> = <span style="color: #ff0000;">&quot;lastname&quot;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Set the column width</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; adgColumn.<span style="color: #0066CC;">width</span> = <span style="color: #cc66cc;">225</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// add the new column to the existing column array with the push() method</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; columns.<span style="color: #0066CC;">push</span><span style="color: #66cc66;">&#40;</span>adgColumn<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// set the AdvancedDataGrid columns to the array of columns</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; adg.<span style="color: #006600;">columns</span> = columns;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Hide the Button</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; addColumnBtn.<span style="color: #0066CC;">visible</span> = <span style="color: #000000; font-weight: bold;">false</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;/</span>fx:Script<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>s:layout<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>s:VerticalLayout paddingLeft=<span style="color: #ff0000;">&quot;5&quot;</span> paddingTop=<span style="color: #ff0000;">&quot;5&quot;</span><span style="color: #66cc66;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;/</span>s:layout<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>s:<span style="color: #0066CC;">Button</span> id=<span style="color: #ff0000;">&quot;addColumnBtn&quot;</span> click=<span style="color: #ff0000;">&quot;addColumn()&quot;</span> label=<span style="color: #ff0000;">&quot;Add Last Name Column&quot;</span><span style="color: #66cc66;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>mx:AdvancedDataGrid id=<span style="color: #ff0000;">&quot;adg&quot;</span> dataProvider=<span style="color: #ff0000;">&quot;{ac}&quot;</span> <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;450&quot;</span> <span style="color: #0066CC;">height</span>=<span style="color: #ff0000;">&quot;250&quot;</span><span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>mx:columns<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>mx:AdvancedDataGridColumn dataField=<span style="color: #ff0000;">&quot;firstname&quot;</span> headerText=<span style="color: #ff0000;">&quot;Firstname&quot;</span><span style="color: #66cc66;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;/</span>mx:columns<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;/</span>mx:AdvancedDataGrid<span style="color: #66cc66;">&gt;</span><br />
<span style="color: #66cc66;">&lt;/</span>s:Application<span style="color: #66cc66;">&gt;</span></div></td></tr></tbody></table></div>


<p>Related posts:<ol><li><a href='http://www.flex-blog.com/flex-dynamic-chart/' rel='bookmark' title='Permanent Link: Flex Dynamic Chart Example'>Flex Dynamic Chart Example</a></li>
<li><a href='http://www.flex-blog.com/style-advanceddatagrid-depending-on-data-example/' rel='bookmark' title='Permanent Link: Style AdvancedDataGrid depending on data example'>Style AdvancedDataGrid depending on data example</a></li>
<li><a href='http://www.flex-blog.com/tree-in-advanced-datagrid-example/' rel='bookmark' title='Permanent Link: Tree in Advanced DataGrid Example'>Tree in Advanced DataGrid Example</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.flex-blog.com/dynamic-advanceddatagridcolumn-in-flex-4/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to make a magnetic button in Flex 4</title>
		<link>http://www.flex-blog.com/how-to-make-magnetic-button/</link>
		<comments>http://www.flex-blog.com/how-to-make-magnetic-button/#comments</comments>
		<pubDate>Wed, 30 Jun 2010 21:26:54 +0000</pubDate>
		<dc:creator>Janez Feldin</dc:creator>
				<category><![CDATA[Examples]]></category>
		<category><![CDATA[Button]]></category>
		<category><![CDATA[Flash Builder]]></category>
		<category><![CDATA[Flex 4]]></category>
		<category><![CDATA[Magnetic]]></category>

		<guid isPermaLink="false">http://www.flex-blog.com/?p=1170</guid>
		<description><![CDATA[Line Break Author: Janez Feldin (3 Articles) - Author Website Janez likes to experiment with flash in his own free time. His other hobbies are playing volleyball, listening to the music, watching movies and above all else, paragliding. I have made a simple example on what most people refer to as magnetic (button) on the [...]


Related posts:<ol><li><a href='http://www.flex-blog.com/image-as-button-in-a-datagrid/' rel='bookmark' title='Permanent Link: Image as Button in a DataGrid'>Image as Button in a DataGrid</a></li>
<li><a href='http://www.flex-blog.com/using-basecolor-to-style-components-in-flex-4/' rel='bookmark' title='Permanent Link: Using baseColor to Style Components in Flex 4'>Using baseColor to Style Components in Flex 4</a></li>
<li><a href='http://www.flex-blog.com/swiz-framework-in-flex-4-example-part-i/' rel='bookmark' title='Permanent Link: SWIZ Framework in Flex 4 Example: Part I'>SWIZ Framework in Flex 4 Example: Part I</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div class="TweetButton_button" style="float: right; margin-left: 10px;;height:20px;margin-bottom:5px;">
<p>			<a href="http://twitter.com/share?url=http%3A%2F%2Fwww.flex-blog.com%2Fhow-to-make-magnetic-button%2F&amp;text=How to make a magnetic button in Flex 4&amp;count=vertical&amp;via=FlexBlog&amp;lang=en&amp;related=Button,Flash+Builder,Flex+4,Magnetic"></p>
<p>				<img src="http://www.flex-blog.com/wp-content/plugins/tweetbutton-for-wordpress/images/tweet.png" style="border:none" /></p>
<p>			</a></p></div>
<p><small style="visibility:hidden; font-size:1px;">Line Break</small>
<div class="atab_box">
<p><b>Author: <a href="http://www.flex-blog.com/author/janez/">Janez Feldin</a></b> <small>(3 Articles)</small> - <a href="http://www.dpl-lescebled.si/knjizica_letenja/index_en.php">Author Website</a></p>
<img alt='' src='http://0.gravatar.com/avatar/a1e4d66aa5328baab2a61ca488b6db7d?s=50&amp;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D50&amp;r=G' class='avatar avatar-50 photo' height='50' width='50' />
<p style="min-height:65px;">Janez likes to experiment with flash in his own free time. 
His other hobbies are playing volleyball, listening to the music, watching movies and above all else, paragliding.</p>
</div><p><br />
I have made a simple example on what most people refer to as magnetic (button) on the web. By extending the standard button you are able to do such a thing with Flex 4.<br />
<span id="more-1170"></span><br />
Finished result:</p>
<p><iframe src="http://www.flex-blog.com/samples/sample43/Main.html" width="100%" frameborder="0" height="300"></iframe></p>
<p>For this I have made a new class which extands spark button (you should extand the component you want to applay &#8220;magnetic&#8221; effect to it) and it looks like this:</p>
<div class="codecolorer-container actionscript mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br />86<br />87<br />88<br />89<br />90<br />91<br />92<br />93<br />94<br />95<br />96<br />97<br />98<br />99<br />100<br />101<br />102<br />103<br />104<br />105<br />106<br />107<br /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">package com.<span style="color: #006600;">flexblog</span>.<span style="color: #006600;">components</span><br />
<span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">MouseEvent</span>;<br />
&nbsp; &nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">ui</span>.<span style="color: #0066CC;">Mouse</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">core</span>.<span style="color: #006600;">FlexGlobals</span>;<br />
&nbsp; &nbsp; <span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">events</span>.<span style="color: #006600;">FlexEvent</span>;<br />
&nbsp; &nbsp; <span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">events</span>.<span style="color: #006600;">MoveEvent</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0066CC;">import</span> spark.<span style="color: #006600;">components</span>.<span style="color: #0066CC;">Button</span>;<br />
&nbsp; &nbsp; <span style="color: #0066CC;">import</span> spark.<span style="color: #006600;">effects</span>.<span style="color: #006600;">Move</span>;<br />
&nbsp; &nbsp; <span style="color: #0066CC;">import</span> spark.<span style="color: #006600;">effects</span>.<span style="color: #006600;">easing</span>.<span style="color: #006600;">Elastic</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MagneticButton <span style="color: #0066CC;">extends</span> <span style="color: #0066CC;">Button</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// xAncor and yAncor determine the point to which </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// the button returns when mouse cursor is too far away</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#91;</span>Bindable<span style="color: #66cc66;">&#93;</span> <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> xAncor:<span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">0</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#91;</span>Bindable<span style="color: #66cc66;">&#93;</span> <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> yAncor:<span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">0</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Distance on x axis which determine maximum </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// distance from xAncor in one direction</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#91;</span>Bindable<span style="color: #66cc66;">&#93;</span> <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> xDist:<span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">100</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Distance on y axis which determine maximum </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// distance from yAncor in one direction</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#91;</span>Bindable<span style="color: #66cc66;">&#93;</span> <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> yDist:<span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">50</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Property that makes transitions between different positions</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _move:Move = <span style="color: #000000; font-weight: bold;">new</span> Move<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> MagneticButton<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">super</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/**<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* Tries to add event listener for mouse move event to stage. <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* If stage is null than adds event listener for application <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* complete and than adds event listener for mouse move<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">try</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _move.<span style="color: #006600;">easer</span> = <span style="color: #000000; font-weight: bold;">new</span> Elastic<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _move.<span style="color: #0066CC;">duration</span> = <span style="color: #cc66cc;">1500</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; xAncor = <span style="color: #0066CC;">this</span>.<span style="color: #006600;">x</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; yAncor = <span style="color: #0066CC;">this</span>.<span style="color: #006600;">y</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FlexGlobals.<span style="color: #006600;">topLevelApplication</span>.<span style="color: #0066CC;">stage</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">MOUSE_MOVE</span>, mouse_move<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">catch</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:<span style="color: #0066CC;">Error</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FlexGlobals.<span style="color: #006600;">topLevelApplication</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>FlexEvent.<span style="color: #006600;">APPLICATION_COMPLETE</span>, app_complete<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/**<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* Function that is called when Main application is complete. <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* It sets easer property and duration property for _move, set ancor <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* of the button to the buttens current x and y position and as <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* mentioned above adds an event listener for mouse move<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> app_complete<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:FlexEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _move.<span style="color: #006600;">easer</span> = <span style="color: #000000; font-weight: bold;">new</span> Elastic<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _move.<span style="color: #0066CC;">duration</span> = <span style="color: #cc66cc;">1500</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; xAncor = <span style="color: #0066CC;">this</span>.<span style="color: #006600;">x</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; yAncor = <span style="color: #0066CC;">this</span>.<span style="color: #006600;">y</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">MOUSE_MOVE</span>, mouse_move<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/**<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* Sets the ancor of the button and also move it to that position.<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> setAncor<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">_x</span>:<span style="color: #0066CC;">Number</span>,<span style="color: #0066CC;">_y</span>:<span style="color: #0066CC;">Number</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; xAncor = <span style="color: #0066CC;">_x</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; yAncor = <span style="color: #0066CC;">_y</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _move.<span style="color: #006600;">xTo</span> = <span style="color: #0066CC;">_x</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _move.<span style="color: #006600;">yTo</span> = <span style="color: #0066CC;">_y</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _move.<span style="color: #0066CC;">play</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/**<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* &nbsp;Function that actually calculates and moves the button to the right position.<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> mouse_move<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:MouseEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Some basic math logic to calculate if mouse cursor </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// is close enough to move the button to that location</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span> <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">abs</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>xAncor + <span style="color: #0066CC;">this</span>.<span style="color: #0066CC;">width</span><span style="color: #66cc66;">/</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span> - <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">mouseX</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&lt;</span> <span style="color: #cc66cc;">2</span><span style="color: #66cc66;">*</span>xDist <span style="color: #66cc66;">&amp;&amp;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">abs</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>yAncor + <span style="color: #0066CC;">this</span>.<span style="color: #0066CC;">height</span><span style="color: #66cc66;">/</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span> - <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">mouseY</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&lt;</span> <span style="color: #cc66cc;">2</span><span style="color: #66cc66;">*</span>yDist <span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _move.<span style="color: #006600;">xTo</span> = <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">mouseX</span> - <span style="color: #0066CC;">this</span>.<span style="color: #0066CC;">width</span><span style="color: #66cc66;">/</span><span style="color: #cc66cc;">2</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _move.<span style="color: #006600;">yTo</span> = <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">mouseY</span> - <span style="color: #0066CC;">this</span>.<span style="color: #0066CC;">height</span><span style="color: #66cc66;">/</span><span style="color: #cc66cc;">2</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _move.<span style="color: #006600;">xTo</span> = xAncor;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _move.<span style="color: #006600;">yTo</span> = yAncor;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _move.<span style="color: #0066CC;">play</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #66cc66;">&#125;</span></div></td></tr></tbody></table></div>
<p>With this we have acctualy created new component and to use it we need to add that component to stage in our mxml component just like we would any other component.</p>
<p>Our main.mxml:</p>
<div class="codecolorer-container actionscript mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #66cc66;">&lt;</span>?<span style="color: #0066CC;">xml</span> <span style="color: #0066CC;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #66cc66;">&gt;</span><br />
<span style="color: #66cc66;">&lt;</span>s:Application xmlns:fx=<span style="color: #ff0000;">&quot;http://ns.adobe.com/mxml/2009&quot;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;xmlns:s=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/spark&quot;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;xmlns:mx=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/mx&quot;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;xmlns:components=<span style="color: #ff0000;">&quot;com.flexblog.components.*&quot;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0066CC;">backgroundColor</span>=<span style="color: #ff0000;">&quot;#B9B9B9&quot;</span> <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;500&quot;</span> <span style="color: #0066CC;">height</span>=<span style="color: #ff0000;">&quot;300&quot;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;viewSourceURL=<span style="color: #ff0000;">&quot;srcview/index.html&quot;</span><span style="color: #66cc66;">&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>components:MagneticButton label=<span style="color: #ff0000;">&quot;I am magnetic button&quot;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;x=<span style="color: #ff0000;">&quot;100&quot;</span> y=<span style="color: #ff0000;">&quot;50&quot;</span> xDist=<span style="color: #ff0000;">&quot;50&quot;</span> yDist=<span style="color: #ff0000;">&quot;30&quot;</span><span style="color: #66cc66;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>components:MagneticButton label=<span style="color: #ff0000;">&quot;I am also magnetic button&quot;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;x=<span style="color: #ff0000;">&quot;300&quot;</span> y=<span style="color: #ff0000;">&quot;50&quot;</span> xDist=<span style="color: #ff0000;">&quot;50&quot;</span> yDist=<span style="color: #ff0000;">&quot;30&quot;</span> <span style="color: #66cc66;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>s:<span style="color: #0066CC;">Button</span> label=<span style="color: #ff0000;">&quot;I am normal button&quot;</span> x=<span style="color: #ff0000;">&quot;150&quot;</span> y=<span style="color: #ff0000;">&quot;150&quot;</span><span style="color: #66cc66;">/&gt;</span><br />
&nbsp; &nbsp; <br />
<span style="color: #66cc66;">&lt;/</span>s:Application<span style="color: #66cc66;">&gt;</span></div></td></tr></tbody></table></div>


<p>Related posts:<ol><li><a href='http://www.flex-blog.com/image-as-button-in-a-datagrid/' rel='bookmark' title='Permanent Link: Image as Button in a DataGrid'>Image as Button in a DataGrid</a></li>
<li><a href='http://www.flex-blog.com/using-basecolor-to-style-components-in-flex-4/' rel='bookmark' title='Permanent Link: Using baseColor to Style Components in Flex 4'>Using baseColor to Style Components in Flex 4</a></li>
<li><a href='http://www.flex-blog.com/swiz-framework-in-flex-4-example-part-i/' rel='bookmark' title='Permanent Link: SWIZ Framework in Flex 4 Example: Part I'>SWIZ Framework in Flex 4 Example: Part I</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.flex-blog.com/how-to-make-magnetic-button/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using ASDoc as an External Tool in Flash Builder 4</title>
		<link>http://www.flex-blog.com/using-asdoc-as-an-external-tool-in-flash-builder-4/</link>
		<comments>http://www.flex-blog.com/using-asdoc-as-an-external-tool-in-flash-builder-4/#comments</comments>
		<pubDate>Tue, 22 Jun 2010 09:34:57 +0000</pubDate>
		<dc:creator>Arjan</dc:creator>
				<category><![CDATA[Examples]]></category>
		<category><![CDATA[ASDoc]]></category>
		<category><![CDATA[Flash Builder]]></category>
		<category><![CDATA[Flex 4]]></category>

		<guid isPermaLink="false">http://www.flex-blog.com/?p=1122</guid>
		<description><![CDATA[Line Break Author: Arjan (36 Articles) - Author Website Arjan is a SAP Consultant specialized in ABAP and Front End development techniques like Web Dynpro, Adobe Interactive Forms, Flex and AIR. In his free time he likes to create examples for Flex-Blog and other applications using Flex, AIR and PHP. Other hobbies are movies and [...]


Related posts:<ol><li><a href='http://www.flex-blog.com/flex-4-flash-builder-4-basecolor-changed-to-chromecolor/' rel='bookmark' title='Permanent Link: Flex 4 / Flash Builder 4: baseColor changed to chromeColor'>Flex 4 / Flash Builder 4: baseColor changed to chromeColor</a></li>
<li><a href='http://www.flex-blog.com/connect-to-google-analytics-from-flash-builder/' rel='bookmark' title='Permanent Link: Connect to Google Analytics from Flash Builder'>Connect to Google Analytics from Flash Builder</a></li>
<li><a href='http://www.flex-blog.com/call-javascript-function-from-flex-flash-builder-as3/' rel='bookmark' title='Permanent Link: Call Javascript function from Flex / Flash Builder (AS3)'>Call Javascript function from Flex / Flash Builder (AS3)</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div class="TweetButton_button" style="float: right; margin-left: 10px;;height:20px;margin-bottom:5px;">
<p>			<a href="http://twitter.com/share?url=http%3A%2F%2Fwww.flex-blog.com%2Fusing-asdoc-as-an-external-tool-in-flash-builder-4%2F&amp;text=Using ASDoc as an External Tool in Flash Builder 4&amp;count=vertical&amp;via=FlexBlog&amp;lang=en&amp;related=ASDoc,Flash+Builder,Flex+4"></p>
<p>				<img src="http://www.flex-blog.com/wp-content/plugins/tweetbutton-for-wordpress/images/tweet.png" style="border:none" /></p>
<p>			</a></p></div>
<p><small style="visibility:hidden; font-size:1px;">Line Break</small>
<div class="atab_box">
<p><b>Author: <a href="http://www.flex-blog.com/author/admin/">Arjan</a></b> <small>(36 Articles)</small> - <a href="http://www.flex-blog.com">Author Website</a></p>
<img alt='' src='http://0.gravatar.com/avatar/29187d7302c1efbed2d457ec26cfbe4d?s=50&amp;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D50&amp;r=G' class='avatar avatar-50 photo' height='50' width='50' />
<p style="min-height:65px;">Arjan is a SAP Consultant specialized in ABAP and Front End development techniques like Web Dynpro, Adobe Interactive Forms, Flex and AIR. In his free time he likes to create examples for Flex-Blog and other applications using Flex, AIR and PHP. Other hobbies are movies and music. He is also the co-owner of Flex-Blog.com.</p>
</div><p><br />
When developing Flex and AIR applications for clients / customers it&#8217;s always nice to deliver a structured structured Flash Builder project with well documented sources. </p>
<p>Similar to JavaDoc for Java, Actionscript has the opportunity to use a tool that generates HTML files in which you can navigate through all your project packages, ActionScript Classes and MXML files. ASDoc is essentially a command line tool, but you can configure Eclipse / Flash Builder in such a way that you can run ASDoc with a click of a button. This example show you how to do this.<br />
<span id="more-1122"></span><br />
Here is an example of what ASDoc can output for you:<br />
<img src="http://www.flex-blog.com/samples/images/asdoc/asdoc_output_example.png" alt="ASDoc output example" width="600" border="2" /><br />
</br><br />
Let&#8217;s configure Flash Builder so that we can do this with one click of a button!<br />
</br><br />
First, open the external tools configuration in your Flash Builder and create a new configuration by clicking on the new launch configuration icon:<br />
<img src="http://www.flex-blog.com/samples/images/asdoc/flash_builder_external_tools.png" alt="Flash Builder External Tools" /><br />
Set the following for the configuration values:</p>
<li>Location: Navigate to the asdoc.exe file on your filesystem. Its located in your SDK X.X.X\bin folder.</li>
<li>Working directory: Browse to the location of your project.</li>
<li>Arguments: -source-path src and -doc-sources src.</li>
<p></br><br />
If you are using any external libraries (SWC files) in your project, you need to specify them as well (in my example, they are located in the libs folder in my project):</p>
<li>-external-library-path: libs</li>
<p></br><br />
After that, you should see something like this:<br />
<img src="http://www.flex-blog.com/samples/images/asdoc/asdoc_configuration.png" alt="ASDoc Configuration" width="600"/><br />
</br><br />
Now you&#8217;re all set, you can generate ASDoc for your project by clicking the External Tools button in you Flash Builder.<br />
</br><br />
<img src="http://www.flex-blog.com/samples/images/asdoc/run_asdoc.png" alt="Run ASDoc" /><br />
</br><br />
This will automatically output all files to [your project location]\asdoc-output. When asdoc.exe finishes, open the index.html file to see the result.<br />
</br><br />
For information how to comment your Classes, Methods, MXML Files and such, take a look at the ASDoc documentation from Adobe <a href="http://help.adobe.com/en_US/flex/using/WSd0ded3821e0d52fe1e63e3d11c2f44bb7b-7fe7.html">here</a>.<br />
</br><br />
<strong>Note: This example assumes that you are using the Flex 4 SDK, for all other SDKs you should pick the correct location of asdoc.exe on your filesystem to get it working for your project.</strong></p>


<p>Related posts:<ol><li><a href='http://www.flex-blog.com/flex-4-flash-builder-4-basecolor-changed-to-chromecolor/' rel='bookmark' title='Permanent Link: Flex 4 / Flash Builder 4: baseColor changed to chromeColor'>Flex 4 / Flash Builder 4: baseColor changed to chromeColor</a></li>
<li><a href='http://www.flex-blog.com/connect-to-google-analytics-from-flash-builder/' rel='bookmark' title='Permanent Link: Connect to Google Analytics from Flash Builder'>Connect to Google Analytics from Flash Builder</a></li>
<li><a href='http://www.flex-blog.com/call-javascript-function-from-flex-flash-builder-as3/' rel='bookmark' title='Permanent Link: Call Javascript function from Flex / Flash Builder (AS3)'>Call Javascript function from Flex / Flash Builder (AS3)</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.flex-blog.com/using-asdoc-as-an-external-tool-in-flash-builder-4/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flex Encryption (MD5, SHA1, SHA224, SHA256, HMAC)</title>
		<link>http://www.flex-blog.com/flex-encryption-md5-sha1-sha224-sha256-hmac/</link>
		<comments>http://www.flex-blog.com/flex-encryption-md5-sha1-sha224-sha256-hmac/#comments</comments>
		<pubDate>Mon, 21 Jun 2010 10:58:13 +0000</pubDate>
		<dc:creator>Janez Feldin</dc:creator>
				<category><![CDATA[Examples]]></category>
		<category><![CDATA[Encryption]]></category>
		<category><![CDATA[Flex]]></category>

		<guid isPermaLink="false">http://www.flex-blog.com/?p=1117</guid>
		<description><![CDATA[Line Break Author: Janez Feldin (3 Articles) - Author Website Janez likes to experiment with flash in his own free time. His other hobbies are playing volleyball, listening to the music, watching movies and above all else, paragliding. After a question on our flex forum about MD5 encryption, I decided to write an example about [...]


No related posts.]]></description>
			<content:encoded><![CDATA[<div class="TweetButton_button" style="float: right; margin-left: 10px;;height:20px;margin-bottom:5px;">
<p>			<a href="http://twitter.com/share?url=http%3A%2F%2Fwww.flex-blog.com%2Fflex-encryption-md5-sha1-sha224-sha256-hmac%2F&amp;text=Flex Encryption (MD5, SHA1, SHA224, SHA256, HMAC)&amp;count=vertical&amp;via=FlexBlog&amp;lang=en&amp;related=Encryption,Flex"></p>
<p>				<img src="http://www.flex-blog.com/wp-content/plugins/tweetbutton-for-wordpress/images/tweet.png" style="border:none" /></p>
<p>			</a></p></div>
<p><small style="visibility:hidden; font-size:1px;">Line Break</small>
<div class="atab_box">
<p><b>Author: <a href="http://www.flex-blog.com/author/janez/">Janez Feldin</a></b> <small>(3 Articles)</small> - <a href="http://www.dpl-lescebled.si/knjizica_letenja/index_en.php">Author Website</a></p>
<img alt='' src='http://0.gravatar.com/avatar/a1e4d66aa5328baab2a61ca488b6db7d?s=50&amp;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D50&amp;r=G' class='avatar avatar-50 photo' height='50' width='50' />
<p style="min-height:65px;">Janez likes to experiment with flash in his own free time. 
His other hobbies are playing volleyball, listening to the music, watching movies and above all else, paragliding.</p>
</div><p></p>
<p>After a question on our <a href="http://www.flex-blog.com/forum/">flex forum</a> about MD5 encryption, I decided to write an example about all the encryption types available in Flex.</p>
<p><span id="more-1117"></span></p>
<p>Encryption is not available by default, you have to download the latest version of the (open source) project <a href="http://as3corelib.googlecode.com/">AS3corelib</a>.</p>
<p>If you would like to encrypt a String with an MD5, you have the MD5 class in <em>as3corelib-.92.1srccomadobecryptoMD5.as</em>.</p>
<p>Import this class and than just call</p>
<div class="codecolorer-container actionscript mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">MD5.<span style="color: #006600;">hash</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;some string&quot;</span><span style="color: #66cc66;">&#41;</span>;</div></td></tr></tbody></table></div>
<p>and there you go…</p>
<p>To show you every encryption method I&#8217;ve written this example.</p>
<p><iframe src="http://www.flex-blog.com/samples/sample42/Main.html" width="100%" frameborder="0" height="500"></iframe></p>
<p><strong>Janez</strong></p>


<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://www.flex-blog.com/flex-encryption-md5-sha1-sha224-sha256-hmac/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>The SWIZ framework for Flex 3 / Flex 4: Easy, Light and Very Powerfull</title>
		<link>http://www.flex-blog.com/the-swiz-framework-for-flex-3-flex-4-easy-light-and-very-powerfull/</link>
		<comments>http://www.flex-blog.com/the-swiz-framework-for-flex-3-flex-4-easy-light-and-very-powerfull/#comments</comments>
		<pubDate>Fri, 11 Jun 2010 14:41:28 +0000</pubDate>
		<dc:creator>Arjan</dc:creator>
				<category><![CDATA[Examples]]></category>
		<category><![CDATA[Framework]]></category>
		<category><![CDATA[SWIZ]]></category>

		<guid isPermaLink="false">http://www.flex-blog.com/?p=1113</guid>
		<description><![CDATA[Line Break Author: Arjan (36 Articles) - Author Website Arjan is a SAP Consultant specialized in ABAP and Front End development techniques like Web Dynpro, Adobe Interactive Forms, Flex and AIR. In his free time he likes to create examples for Flex-Blog and other applications using Flex, AIR and PHP. Other hobbies are movies and [...]


Related posts:<ol><li><a href='http://www.flex-blog.com/swiz-framework-in-flex-4-example-part-i/' rel='bookmark' title='Permanent Link: SWIZ Framework in Flex 4 Example: Part I'>SWIZ Framework in Flex 4 Example: Part I</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div class="TweetButton_button" style="float: right; margin-left: 10px;;height:20px;margin-bottom:5px;">
<p>			<a href="http://twitter.com/share?url=http%3A%2F%2Fwww.flex-blog.com%2Fthe-swiz-framework-for-flex-3-flex-4-easy-light-and-very-powerfull%2F&amp;text=The SWIZ framework for Flex 3 / Flex 4: Easy, Light and Very Powerfull&amp;count=vertical&amp;via=FlexBlog&amp;lang=en&amp;related=Framework,SWIZ"></p>
<p>				<img src="http://www.flex-blog.com/wp-content/plugins/tweetbutton-for-wordpress/images/tweet.png" style="border:none" /></p>
<p>			</a></p></div>
<p><small style="visibility:hidden; font-size:1px;">Line Break</small>
<div class="atab_box">
<p><b>Author: <a href="http://www.flex-blog.com/author/admin/">Arjan</a></b> <small>(36 Articles)</small> - <a href="http://www.flex-blog.com">Author Website</a></p>
<img alt='' src='http://0.gravatar.com/avatar/29187d7302c1efbed2d457ec26cfbe4d?s=50&amp;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D50&amp;r=G' class='avatar avatar-50 photo' height='50' width='50' />
<p style="min-height:65px;">Arjan is a SAP Consultant specialized in ABAP and Front End development techniques like Web Dynpro, Adobe Interactive Forms, Flex and AIR. In his free time he likes to create examples for Flex-Blog and other applications using Flex, AIR and PHP. Other hobbies are movies and music. He is also the co-owner of Flex-Blog.com.</p>
</div><p><br />
I recently followed a course about using the SWIZ framework with Flex (3 in the course). What i&#8217;ve found out is that SWIZ a very powerfull framework with a lot of really nice features to help you with your flex development.<br />
<span id="more-1113"></span><br />
Some of the best features of SWIZ:</p>
<p>- Light (unlike cairngorm and PureMVC)<br />
- Easy<br />
- Dependency Injection<br />
- Event Mediation</p>
<p>I will post some examples using the SWIZ framework in combination with Flex 4 soon. Until then, check out the <a href="http://swizframework.org/">framework site</a> and the <a href="http://swizframework.jira.com/wiki/display/SWIZ/Home">SWIZ Wiki</a></p>


<p>Related posts:<ol><li><a href='http://www.flex-blog.com/swiz-framework-in-flex-4-example-part-i/' rel='bookmark' title='Permanent Link: SWIZ Framework in Flex 4 Example: Part I'>SWIZ Framework in Flex 4 Example: Part I</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.flex-blog.com/the-swiz-framework-for-flex-3-flex-4-easy-light-and-very-powerfull/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Call Javascript function from Flex / Flash Builder (AS3)</title>
		<link>http://www.flex-blog.com/call-javascript-function-from-flex-flash-builder-as3/</link>
		<comments>http://www.flex-blog.com/call-javascript-function-from-flex-flash-builder-as3/#comments</comments>
		<pubDate>Fri, 07 May 2010 11:58:06 +0000</pubDate>
		<dc:creator>Roelof</dc:creator>
				<category><![CDATA[Examples]]></category>
		<category><![CDATA[Flash Builder]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Flex 4]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://www.flex-blog.com/?p=1081</guid>
		<description><![CDATA[Line Break Author: Roelof (11 Articles) - Author Website Roelof is a SAP Consultant specialized in Front-End development. In his spare free time he is either developing on the web, playing basketball, watching soccer, travelling or just being lazy. He is also the co-owner of Flex-Blog.com. This are actually two examples in one. First I [...]


Related posts:<ol><li><a href='http://www.flex-blog.com/easy-unix-time-function/' rel='bookmark' title='Permanent Link: Easy Unix Time Function'>Easy Unix Time Function</a></li>
<li><a href='http://www.flex-blog.com/connect-to-google-analytics-from-flash-builder/' rel='bookmark' title='Permanent Link: Connect to Google Analytics from Flash Builder'>Connect to Google Analytics from Flash Builder</a></li>
<li><a href='http://www.flex-blog.com/using-asdoc-as-an-external-tool-in-flash-builder-4/' rel='bookmark' title='Permanent Link: Using ASDoc as an External Tool in Flash Builder 4'>Using ASDoc as an External Tool in Flash Builder 4</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div class="TweetButton_button" style="float: right; margin-left: 10px;;height:20px;margin-bottom:5px;">
<p>			<a href="http://twitter.com/share?url=http%3A%2F%2Fwww.flex-blog.com%2Fcall-javascript-function-from-flex-flash-builder-as3%2F&amp;text=Call Javascript function from Flex / Flash Builder (AS3)&amp;count=vertical&amp;via=FlexBlog&amp;lang=en&amp;related=Flash+Builder,Flex,Flex+4,Javascript"></p>
<p>				<img src="http://www.flex-blog.com/wp-content/plugins/tweetbutton-for-wordpress/images/tweet.png" style="border:none" /></p>
<p>			</a></p></div>
<p><small style="visibility:hidden; font-size:1px;">Line Break</small>
<div class="atab_box">
<p><b>Author: <a href="http://www.flex-blog.com/author/roelof/">Roelof</a></b> <small>(11 Articles)</small> - <a href="http://www.flex-blog.com">Author Website</a></p>
<img alt='' src='http://0.gravatar.com/avatar/2caba20bc811d080f88174249b682d14?s=50&amp;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D50&amp;r=G' class='avatar avatar-50 photo' height='50' width='50' />
<p style="min-height:65px;">Roelof is a SAP Consultant specialized in Front-End development. In his spare free time he is either developing on the web, playing basketball, watching soccer, travelling or just being lazy. He is also the co-owner of Flex-Blog.com.</p>
</div><p></p>
<p>This are actually two examples in one. First I will show how to call a Javascript function from your Flex Application. The second example will be a direct execution of Javascript code from your AS3.</p>
<p>Calling Javascript can be done easily using the ExternalInterface class. I have used this in my Flex Comment Form to refresh the screen after the comment is placed.</p>
<p><span id="more-1081"></span></p>
<h2>What&#8217;s possible?</h2>
<p><em>ActionScript -> Javascript (HTML)</em></p>
<ul>
<li>Call any JavaScript function (with any number of arguments, any names and any data types).</li>
<li>Receive a return value from the Javascript function.</li>
</ul>
<p><em>Javascript (HTML) -> Actionscript</em></p>
<ul>
<li>Call any ActionScript function (using the standard function notation).</li>
<li>Receive a return value from the ActionScript function.</li>
</ul>
<p><em>Please note that you cannot use the ExternalInterface using AIR.</em></p>
<h2>Example</h2>
<p>I will start of with an example. I have added this Javascript function to the header of the HTML file generated with the release (<a href="http://www.flex-blog.com/samples/sample40/CallingJavascriptFromFlexExample.html">view source</a>).</p>
<div class="codecolorer-container javascript mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #339933;">&lt;</span>script language<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;javascript&quot;</span><span style="color: #339933;">&gt;</span><br />
<span style="color: #003366; font-weight: bold;">function</span> myfunction<span style="color: #009900;">&#40;</span>message<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>message<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></div></td></tr></tbody></table></div>
<p>This Javascript function will be called if you press on the button of the Flex component below.<br />
<iframe src="http://www.flex-blog.com/samples/sample40/CallingJavascriptFromFlexExample.html" width="100%" frameborder="0" height="150"></iframe></p>
<h2>Calling Javascript Function from Flex.</h2>
<p>You probably wonder what Actionscript code is behind this. It&#8217;s actually very simple. I have created this function, which eventually calls the Javascript function with 1 parameter.</p>
<div class="codecolorer-container actionscript mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> showJavascriptAlert<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> javascriptFunction:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">&quot;myfunction&quot;</span>;<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">message</span>:<span style="color: #0066CC;">String</span> = <span style="color: #0066CC;">message</span>.<span style="color: #0066CC;">text</span>;<br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>ExternalInterface.<span style="color: #006600;">available</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// call the javascript function!</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; ExternalInterface.<span style="color: #0066CC;">call</span><span style="color: #66cc66;">&#40;</span>javascriptFunction, <span style="color: #0066CC;">message</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
<span style="color: #66cc66;">&#125;</span></div></td></tr></tbody></table></div>
<h2>Calling Javascript from Flex (no function).</h2>
<p>It is possible to create a Javascript function to call from your Flex Application, but it&#8217;s not necessary. Within Actionscript 3.0 it is possible to execute Javascript code directly. Sometimes it&#8217;s just overkill to create a complete Javascript function for something easy. Like for example showing an alert. This example is <strong>not</strong> using a JavaScript function.</p>
<h2>Example 2</h2>
<p>Here is the example. (use right mouse click -> View Source)<br />
<iframe src="http://www.flex-blog.com/samples/sample41/CallingJavascriptFromFlexExampleNoFunction.html" width="100%" frameborder="0" height="1500"></iframe></p>
<h2>Source Code</h2>
<div class="codecolorer-container actionscript mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> showJavascriptAlert<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">message</span>:<span style="color: #0066CC;">String</span> = <span style="color: #0066CC;">message</span>.<span style="color: #0066CC;">text</span>;<br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>ExternalInterface.<span style="color: #006600;">available</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// call the javascript function!</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; ExternalInterface.<span style="color: #0066CC;">call</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;alert&quot;</span>, <span style="color: #0066CC;">message</span><span style="color: #66cc66;">&#41;</span>; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
<span style="color: #66cc66;">&#125;</span></div></td></tr></tbody></table></div>
<p>I did not write an example about calling ActionScript functions from JavaScript. If you would like to see that example leave a comment!</p>


<p>Related posts:<ol><li><a href='http://www.flex-blog.com/easy-unix-time-function/' rel='bookmark' title='Permanent Link: Easy Unix Time Function'>Easy Unix Time Function</a></li>
<li><a href='http://www.flex-blog.com/connect-to-google-analytics-from-flash-builder/' rel='bookmark' title='Permanent Link: Connect to Google Analytics from Flash Builder'>Connect to Google Analytics from Flash Builder</a></li>
<li><a href='http://www.flex-blog.com/using-asdoc-as-an-external-tool-in-flash-builder-4/' rel='bookmark' title='Permanent Link: Using ASDoc as an External Tool in Flash Builder 4'>Using ASDoc as an External Tool in Flash Builder 4</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.flex-blog.com/call-javascript-function-from-flex-flash-builder-as3/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Flex FlashVars in AS3 Example</title>
		<link>http://www.flex-blog.com/flex-flashvars-in-as3-example/</link>
		<comments>http://www.flex-blog.com/flex-flashvars-in-as3-example/#comments</comments>
		<pubDate>Tue, 04 May 2010 12:54:33 +0000</pubDate>
		<dc:creator>Roelof</dc:creator>
				<category><![CDATA[Examples]]></category>
		<category><![CDATA[Flash Builder]]></category>
		<category><![CDATA[Flash Builder 4]]></category>
		<category><![CDATA[Flashvars]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Flex 4]]></category>

		<guid isPermaLink="false">http://www.flex-blog.com/?p=1086</guid>
		<description><![CDATA[Line Break Author: Roelof (11 Articles) - Author Website Roelof is a SAP Consultant specialized in Front-End development. In his spare free time he is either developing on the web, playing basketball, watching soccer, travelling or just being lazy. He is also the co-owner of Flex-Blog.com. While building my WordPress Flash Comment Form in Flex [...]


Related posts:<ol><li><a href='http://www.flex-blog.com/wordpress-flash-flex-comments-form/' rel='bookmark' title='Permanent Link: WordPress Flash / Flex Comments Form'>WordPress Flash / Flex Comments Form</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div class="TweetButton_button" style="float: right; margin-left: 10px;;height:20px;margin-bottom:5px;">
<p>			<a href="http://twitter.com/share?url=http%3A%2F%2Fwww.flex-blog.com%2Fflex-flashvars-in-as3-example%2F&amp;text=Flex FlashVars in AS3 Example&amp;count=vertical&amp;via=FlexBlog&amp;lang=en&amp;related=Flash+Builder,Flash+Builder+4,Flashvars,Flex,Flex+4"></p>
<p>				<img src="http://www.flex-blog.com/wp-content/plugins/tweetbutton-for-wordpress/images/tweet.png" style="border:none" /></p>
<p>			</a></p></div>
<p><small style="visibility:hidden; font-size:1px;">Line Break</small>
<div class="atab_box">
<p><b>Author: <a href="http://www.flex-blog.com/author/roelof/">Roelof</a></b> <small>(11 Articles)</small> - <a href="http://www.flex-blog.com">Author Website</a></p>
<img alt='' src='http://0.gravatar.com/avatar/2caba20bc811d080f88174249b682d14?s=50&amp;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D50&amp;r=G' class='avatar avatar-50 photo' height='50' width='50' />
<p style="min-height:65px;">Roelof is a SAP Consultant specialized in Front-End development. In his spare free time he is either developing on the web, playing basketball, watching soccer, travelling or just being lazy. He is also the co-owner of Flex-Blog.com.</p>
</div><p></p>
<p>While building my WordPress Flash Comment Form in Flex / ActionScript 3.0 over the weekend I needed to find out how to use FlashVars to pass data to my SWF file.</p>
<p>In this small example I will show you how to pass them and how to handle them in your Flex application. And ofcourse a small example application (with view source enabled).</p>
<p><span id="more-1086"></span></p>
<h2>Example Application</h2>
<p>Below is an example using FlashVars with View Source enabled. Complete source of the HTML and Flex application can be found below.</p>
<p><iframe src="http://www.flex-blog.com/samples/sample39/FlashVarsExample.html" width="100%" frameborder="0" height="100"></iframe></p>
<p>Continue reading for more implementation tips.</p>
<h2>Passing FlashVars to your SWF</h2>
<p>Adding SWF files to your HTML is not an easy job, at our examples we usualy embed the HTML file, that was generated when you release your project, in an Iframe. If you are using that solution, you should add your FlashVars as follows:</p>
<p>The source below is taken from FlashVarsExample.html, created with the release build of this example:</p>
<div class="codecolorer-container javascript mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &lt;script type=&quot;text/javascript&quot; src=&quot;swfobject.js&quot;&gt;&lt;/script&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;!--</span> <span style="color: #000066; font-weight: bold;">For</span> version detection<span style="color: #339933;">,</span> set to min. <span style="color: #660066;">required</span> Flash Player version<span style="color: #339933;">,</span> or <span style="color: #CC0000;">0</span> <span style="color: #009900;">&#40;</span>or 0.0.0<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">for</span> no version detection. <span style="color: #339933;">--&gt;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> swfVersionStr <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;10.0.0&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;!--</span> To <span style="color: #003366; font-weight: bold;">use</span> express install<span style="color: #339933;">,</span> set to playerProductInstall.<span style="color: #660066;">swf</span><span style="color: #339933;">,</span> otherwise the empty string. <span style="color: #339933;">--&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> xiSwfUrlStr <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;playerProductInstall.swf&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> flashvars <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; flashvars.<span style="color: #000066;">name</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;Flex-Blog Visitor&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> params <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; params.<span style="color: #660066;">quality</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;high&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; params.<span style="color: #660066;">bgcolor</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;#ffffff&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; params.<span style="color: #660066;">allowscriptaccess</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;sameDomain&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; params.<span style="color: #660066;">allowfullscreen</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;true&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> attributes <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; attributes.<span style="color: #660066;">id</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;FlashVarsExample&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; attributes.<span style="color: #000066;">name</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;FlashVarsExample&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; attributes.<span style="color: #660066;">align</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;middle&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; swfobject.<span style="color: #660066;">embedSWF</span><span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;FlashVarsExample.swf&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;flashContent&quot;</span><span style="color: #339933;">,</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;500&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;100&quot;</span><span style="color: #339933;">,</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; swfVersionStr<span style="color: #339933;">,</span> xiSwfUrlStr<span style="color: #339933;">,</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; flashvars<span style="color: #339933;">,</span> params<span style="color: #339933;">,</span> attributes<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;!--</span> JavaScript enabled so display the flashContent div <span style="color: #000066; font-weight: bold;">in</span> <span style="color: #000066; font-weight: bold;">case</span> it <span style="color: #000066; font-weight: bold;">is</span> not replaced <span style="color: #000066; font-weight: bold;">with</span> a swf object. <span style="color: #339933;">--&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; swfobject.<span style="color: #660066;">createCSS</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#flashContent&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;display:block;text-align:left;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></div></td></tr></tbody></table></div>
<p>The flashvar called name will be available in your Flex application.</p>
<div class="codecolorer-container javascript mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">flashvars.<span style="color: #000066;">name</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;Flex-Blog Visitor&quot;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>The next option to embed your SWF is directly. For WordPress you have a great plugin called Kimili Flash Embed, this will generate the following code:</p>
<div class="codecolorer-container actionscript mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #66cc66;">&lt;</span>object classid=<span style="color: #ff0000;">&quot;clsid:D27CDB6E-AE6D-11cf-96B8-444553540000&quot;</span> id=<span style="color: #ff0000;">&quot;fm_FlashVarsExample_2040187859&quot;</span> <span style="color: #000000; font-weight: bold;">class</span>=<span style="color: #ff0000;">&quot;flashmovie&quot;</span> <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;500&quot;</span> <span style="color: #0066CC;">height</span>=<span style="color: #ff0000;">&quot;100&quot;</span><span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>param <span style="color: #0066CC;">name</span>=<span style="color: #ff0000;">&quot;movie&quot;</span> value=<span style="color: #ff0000;">&quot;http://www.flex-blog.com/samples/sample36/FlashVarsExample.swf&quot;</span><span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>param <span style="color: #0066CC;">name</span>=<span style="color: #ff0000;">&quot;allowscriptaccess&quot;</span> value=<span style="color: #ff0000;">&quot;sameDomain&quot;</span><span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>param <span style="color: #0066CC;">name</span>=<span style="color: #ff0000;">&quot;FlashVars&quot;</span> value=<span style="color: #ff0000;">&quot;name=Flex-Blog.com Visitor&quot;</span><span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;!</span>--<span style="color: #66cc66;">&#91;</span><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">!</span>IE<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&gt;</span>--<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>object <span style="color: #0066CC;">type</span>=<span style="color: #ff0000;">&quot;application/x-shockwave-flash&quot;</span> <span style="color: #0066CC;">data</span>=<span style="color: #ff0000;">&quot;http://www.flex-blog.com/samples/sample36/FlashVarsExample.swf&quot;</span> <span style="color: #0066CC;">name</span>=<span style="color: #ff0000;">&quot;fm_FlashVarsExample_2040187859&quot;</span> <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;500&quot;</span> <span style="color: #0066CC;">height</span>=<span style="color: #ff0000;">&quot;100&quot;</span><span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>param <span style="color: #0066CC;">name</span>=<span style="color: #ff0000;">&quot;allowscriptaccess&quot;</span> value=<span style="color: #ff0000;">&quot;sameDomain&quot;</span><span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>param <span style="color: #0066CC;">name</span>=<span style="color: #ff0000;">&quot;FlashVars&quot;</span> value=<span style="color: #ff0000;">&quot;name=Flex-Blog.com Visitor&quot;</span><span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;!</span>--<span style="color: #66cc66;">&lt;!</span><span style="color: #66cc66;">&#91;</span><span style="color: #b1b100;">endif</span><span style="color: #66cc66;">&#93;</span>--<span style="color: #66cc66;">&gt;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>a href=<span style="color: #ff0000;">&quot;http://adobe.com/go/getflashplayer&quot;</span><span style="color: #66cc66;">&gt;&lt;</span>img src=<span style="color: #ff0000;">&quot;http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif&quot;</span> alt=<span style="color: #ff0000;">&quot;Get Adobe Flash player&quot;</span><span style="color: #66cc66;">&gt;&lt;/</span>a<span style="color: #66cc66;">&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;!</span>--<span style="color: #66cc66;">&#91;</span><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">!</span>IE<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&gt;</span>--<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;/</span>object<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;!</span>--<span style="color: #66cc66;">&lt;!</span><span style="color: #66cc66;">&#91;</span><span style="color: #b1b100;">endif</span><span style="color: #66cc66;">&#93;</span>--<span style="color: #66cc66;">&gt;</span><br />
<span style="color: #66cc66;">&lt;/</span>object<span style="color: #66cc66;">&gt;</span></div></td></tr></tbody></table></div>
<p>Especially note this:</p>
<div class="codecolorer-container javascript mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #339933;">&lt;</span>param <span style="color: #000066;">name</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;FlashVars&quot;</span> value<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;name=Flex-Blog.com Visitor&quot;</span><span style="color: #339933;">&gt;</span></div></td></tr></tbody></table></div>
<h2>So how to use the FlashVar in your Flex application?</h2>
<p>In your application you have an Array available called:</p>
<div class="codecolorer-container actionscript mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0066CC;">this</span>.<span style="color: #006600;">parameters</span>;</div></td></tr></tbody></table></div>
<p>You can use it in your application as follows:</p>
<div class="codecolorer-container actionscript mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #66cc66;">&lt;</span>?<span style="color: #0066CC;">xml</span> <span style="color: #0066CC;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #66cc66;">&gt;</span><br />
<span style="color: #66cc66;">&lt;</span>s:Application xmlns:fx=<span style="color: #ff0000;">&quot;http://ns.adobe.com/mxml/2009&quot;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;xmlns:s=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/spark&quot;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;xmlns:mx=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/mx&quot;</span> <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;500&quot;</span> <span style="color: #0066CC;">height</span>=<span style="color: #ff0000;">&quot;100&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;initialize=<span style="color: #ff0000;">&quot;init(event)&quot;</span> viewSourceURL=<span style="color: #ff0000;">&quot;srcview/index.html&quot;</span><span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>fx:Script<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;!</span><span style="color: #66cc66;">&#91;</span>CDATA<span style="color: #66cc66;">&#91;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">events</span>.<span style="color: #006600;">FlexEvent</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#91;</span>Bindable<span style="color: #66cc66;">&#93;</span> <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> flashvarname:<span style="color: #0066CC;">String</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; protected <span style="color: #000000; font-weight: bold;">function</span> init<span style="color: #66cc66;">&#40;</span>event:FlexEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> obj:<span style="color: #0066CC;">Object</span> = <span style="color: #0066CC;">this</span>.<span style="color: #006600;">parameters</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; flashvarname = obj.<span style="color: #0066CC;">name</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;/</span>fx:Script<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>s:Label <span style="color: #0066CC;">text</span>=<span style="color: #ff0000;">&quot;Hello {flashvarname}&quot;</span> verticalAlign=<span style="color: #ff0000;">&quot;middle&quot;</span> <span style="color: #0066CC;">height</span>=<span style="color: #ff0000;">&quot;100%&quot;</span> <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;100%&quot;</span> textAlign=<span style="color: #ff0000;">&quot;center&quot;</span><span style="color: #66cc66;">/&gt;</span><br />
<span style="color: #66cc66;">&lt;/</span>s:Application<span style="color: #66cc66;">&gt;</span></div></td></tr></tbody></table></div>
<p>Please rate this post or leave a comment!</p>


<p>Related posts:<ol><li><a href='http://www.flex-blog.com/wordpress-flash-flex-comments-form/' rel='bookmark' title='Permanent Link: WordPress Flash / Flex Comments Form'>WordPress Flash / Flex Comments Form</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.flex-blog.com/flex-flashvars-in-as3-example/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Data Dependant Tree Icon with Tree in AdvancedDataGrid with iconFunction</title>
		<link>http://www.flex-blog.com/data-dependant-tree-icon-with-tree-in-advanceddatagrid-with-iconfunction/</link>
		<comments>http://www.flex-blog.com/data-dependant-tree-icon-with-tree-in-advanceddatagrid-with-iconfunction/#comments</comments>
		<pubDate>Fri, 30 Apr 2010 09:50:35 +0000</pubDate>
		<dc:creator>Arjan</dc:creator>
				<category><![CDATA[Examples]]></category>
		<category><![CDATA[AdvancedDataGrid]]></category>
		<category><![CDATA[Icon]]></category>
		<category><![CDATA[iconFunction]]></category>
		<category><![CDATA[labelFunction]]></category>
		<category><![CDATA[Tree]]></category>

		<guid isPermaLink="false">http://www.flex-blog.com/?p=1066</guid>
		<description><![CDATA[Line Break Author: Arjan (36 Articles) - Author Website Arjan is a SAP Consultant specialized in ABAP and Front End development techniques like Web Dynpro, Adobe Interactive Forms, Flex and AIR. In his free time he likes to create examples for Flex-Blog and other applications using Flex, AIR and PHP. Other hobbies are movies and [...]


Related posts:<ol><li><a href='http://www.flex-blog.com/drag-and-drop-from-datagrid-or-advanceddatagrid-to-tree/' rel='bookmark' title='Permanent Link: Drag and Drop from DataGrid or AdvancedDataGrid to Tree'>Drag and Drop from DataGrid or AdvancedDataGrid to Tree</a></li>
<li><a href='http://www.flex-blog.com/style-advanceddatagrid-depending-on-data-example/' rel='bookmark' title='Permanent Link: Style AdvancedDataGrid depending on data example'>Style AdvancedDataGrid depending on data example</a></li>
<li><a href='http://www.flex-blog.com/change-open-and-close-icons-on-flex-tree/' rel='bookmark' title='Permanent Link: Change open and close icons on Flex Tree'>Change open and close icons on Flex Tree</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div class="TweetButton_button" style="float: right; margin-left: 10px;;height:20px;margin-bottom:5px;">
<p>			<a href="http://twitter.com/share?url=http%3A%2F%2Fwww.flex-blog.com%2Fdata-dependant-tree-icon-with-tree-in-advanceddatagrid-with-iconfunction%2F&amp;text=Data Dependant Tree Icon with Tree in AdvancedDataGrid with iconFunction&amp;count=vertical&amp;via=FlexBlog&amp;lang=en&amp;related=AdvancedDataGrid,Icon,iconFunction,labelFunction,Tree"></p>
<p>				<img src="http://www.flex-blog.com/wp-content/plugins/tweetbutton-for-wordpress/images/tweet.png" style="border:none" /></p>
<p>			</a></p></div>
<p><small style="visibility:hidden; font-size:1px;">Line Break</small>
<div class="atab_box">
<p><b>Author: <a href="http://www.flex-blog.com/author/admin/">Arjan</a></b> <small>(36 Articles)</small> - <a href="http://www.flex-blog.com">Author Website</a></p>
<img alt='' src='http://0.gravatar.com/avatar/29187d7302c1efbed2d457ec26cfbe4d?s=50&amp;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D50&amp;r=G' class='avatar avatar-50 photo' height='50' width='50' />
<p style="min-height:65px;">Arjan is a SAP Consultant specialized in ABAP and Front End development techniques like Web Dynpro, Adobe Interactive Forms, Flex and AIR. In his free time he likes to create examples for Flex-Blog and other applications using Flex, AIR and PHP. Other hobbies are movies and music. He is also the co-owner of Flex-Blog.com.</p>
</div><p><br />
I&#8217;ve written a few posts about the AdvancedDataGrid, including one where you can show a Tree inside of it. I&#8217;ve never written a post about the iconFunction though, so I thought it would be a good idea to do that. This post described how you can use a Tree in an AdvancedDataGrid where the Tree Node icons are dependant of XML node name and other data in the XML element.<br />
<span id="more-1066"></span></p>
<p>In fact it&#8217;s quite straightforward, you just have to know how to do it. First, I will create some dummy XML data in my initialize method, from that data, I create an hierarchical data variable that I can use in my AdvancedDataGrid so that it shows a Tree.</p>
<p>Some variables we need:</p>
<div class="codecolorer-container actionscript mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">collections</span>.<span style="color: #006600;">HierarchicalData</span>;<br />
<br />
<span style="color: #66cc66;">&#91;</span>Bindable<span style="color: #66cc66;">&#93;</span><br />
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> dataHierarchy:HierarchicalData;<br />
<br />
<span style="color: #66cc66;">&#91;</span>Embed<span style="color: #66cc66;">&#40;</span>source=<span style="color: #ff0000;">&quot;assets/dialog-error.png&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span><br />
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> iconError:<span style="color: #000000; font-weight: bold;">Class</span>;<br />
<br />
<span style="color: #66cc66;">&#91;</span>Embed<span style="color: #66cc66;">&#40;</span>source=<span style="color: #ff0000;">&quot;assets/dialog-warning.png&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span><br />
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> iconWarning:<span style="color: #000000; font-weight: bold;">Class</span>;<br />
<br />
<span style="color: #66cc66;">&#91;</span>Embed<span style="color: #66cc66;">&#40;</span>source=<span style="color: #ff0000;">&quot;assets/weather-clear.png&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span><br />
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> iconClear:<span style="color: #000000; font-weight: bold;">Class</span>;<br />
<br />
<span style="color: #66cc66;">&#91;</span>Embed<span style="color: #66cc66;">&#40;</span>source=<span style="color: #ff0000;">&quot;assets/office.png&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span><br />
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> iconOffice:<span style="color: #000000; font-weight: bold;">Class</span>;</div></td></tr></tbody></table></div>
<p>The initialize method:</p>
<div class="codecolorer-container actionscript mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> init<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><br />
<span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> i:<span style="color: #0066CC;">int</span>;<br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Root Node: Corporate Finance</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> xmlData:<span style="color: #0066CC;">XML</span> = <span style="color: #66cc66;">&lt;</span>Finance<span style="color: #66cc66;">&gt;&lt;/</span>Finance<span style="color: #66cc66;">&gt;</span>;<br />
&nbsp; &nbsp; xmlData.<span style="color: #66cc66;">@</span>itemName = <span style="color: #ff0000;">&quot;Corporate Finance&quot;</span>;<br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Sales node</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> sales:<span style="color: #0066CC;">XML</span> = <span style="color: #66cc66;">&lt;</span>Sales<span style="color: #66cc66;">&gt;&lt;/</span>Sales<span style="color: #66cc66;">&gt;</span>;<br />
&nbsp; &nbsp; sales.<span style="color: #66cc66;">@</span>itemName = <span style="color: #ff0000;">&quot;Corporate Sales&quot;</span>;<br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Expenses Node</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> expenses:<span style="color: #0066CC;">XML</span> = <span style="color: #66cc66;">&lt;</span>Expenses<span style="color: #66cc66;">&gt;&lt;/</span>Expenses<span style="color: #66cc66;">&gt;</span>;<br />
&nbsp; &nbsp; expenses.<span style="color: #66cc66;">@</span>itemName = <span style="color: #ff0000;">&quot;Corporate Expenses&quot;</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Append Sales and Expenses to Coporate finance</span><br />
&nbsp; &nbsp; xmlData.<span style="color: #0066CC;">appendChild</span><span style="color: #66cc66;">&#40;</span>sales<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; xmlData.<span style="color: #0066CC;">appendChild</span><span style="color: #66cc66;">&#40;</span>expenses<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> salesItem:<span style="color: #0066CC;">XML</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Add some random sales items</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">for</span><span style="color: #66cc66;">&#40;</span> i=<span style="color: #cc66cc;">0</span>; i<span style="color: #66cc66;">&lt;</span><span style="color: #cc66cc;">5</span>; i++<span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; salesItem = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">XML</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&lt;</span>item<span style="color: #66cc66;">&gt;&lt;/</span>item<span style="color: #66cc66;">&gt;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; salesItem.<span style="color: #66cc66;">@</span>amount = <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">round</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">random</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">*</span> <span style="color: #cc66cc;">100000</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; salesItem.<span style="color: #66cc66;">@</span>itemName = <span style="color: #ff0000;">&quot;Random Sale &quot;</span> + i;<br />
&nbsp; &nbsp; &nbsp; &nbsp; sales.<span style="color: #0066CC;">appendChild</span><span style="color: #66cc66;">&#40;</span>salesItem<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Add some random expense items</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> expensesItem:<span style="color: #0066CC;">XML</span>;<br />
&nbsp; &nbsp; <span style="color: #b1b100;">for</span><span style="color: #66cc66;">&#40;</span> i=<span style="color: #cc66cc;">0</span>; i<span style="color: #66cc66;">&lt;</span><span style="color: #cc66cc;">5</span>; i++<span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; expensesItem = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">XML</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&lt;</span>item<span style="color: #66cc66;">&gt;&lt;/</span>item<span style="color: #66cc66;">&gt;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; expensesItem.<span style="color: #66cc66;">@</span>amount = <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">round</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">random</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">*</span> <span style="color: #cc66cc;">100000</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; expensesItem.<span style="color: #66cc66;">@</span>itemName = <span style="color: #ff0000;">&quot;Random Expense &quot;</span> + i;<br />
&nbsp; &nbsp; &nbsp; &nbsp; expenses.<span style="color: #0066CC;">appendChild</span><span style="color: #66cc66;">&#40;</span>expensesItem<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Greate hierarchy based on created XML</span><br />
&nbsp; &nbsp; dataHierarchy = <span style="color: #000000; font-weight: bold;">new</span> HierarchicalData<span style="color: #66cc66;">&#40;</span>xmlData<span style="color: #66cc66;">&#41;</span>;&nbsp; <br />
<span style="color: #66cc66;">&#125;</span></div></td></tr></tbody></table></div>
<p>Now they very simple layout:</p>
<div class="codecolorer-container actionscript mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #66cc66;">&lt;</span>s:<span style="color: #0066CC;">Button</span> label=<span style="color: #ff0000;">&quot;Generate New Data&quot;</span> click=<span style="color: #ff0000;">&quot;init()&quot;</span><span style="color: #66cc66;">/&gt;</span><br />
<br />
<span style="color: #66cc66;">&lt;</span>mx:AdvancedDataGrid id=<span style="color: #ff0000;">&quot;adg&quot;</span> <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;100%&quot;</span> <span style="color: #0066CC;">height</span>=<span style="color: #ff0000;">&quot;100%&quot;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;dataProvider=<span style="color: #ff0000;">&quot;{dataHierarchy}&quot;</span> iconFunction=<span style="color: #ff0000;">&quot;iconFunction&quot;</span><span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>mx:columns<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>mx:AdvancedDataGridColumn headerText=<span style="color: #ff0000;">&quot;Finance&quot;</span> <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;350&quot;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;labelFunction=<span style="color: #ff0000;">&quot;labelFunction&quot;</span><span style="color: #66cc66;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>mx:AdvancedDataGridColumn headerText=<span style="color: #ff0000;">&quot;Amount&quot;</span> dataField=<span style="color: #ff0000;">&quot;@amount&quot;</span> <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;150&quot;</span><span style="color: #66cc66;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;/</span>mx:columns<span style="color: #66cc66;">&gt;</span><br />
<span style="color: #66cc66;">&lt;/</span>mx:AdvancedDataGrid<span style="color: #66cc66;">&gt;</span></div></td></tr></tbody></table></div>
<p>The label function (declared on the first AdvancedDataGridColumn, to return the node name):</p>
<div class="codecolorer-container actionscript mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> labelFunction<span style="color: #66cc66;">&#40;</span>item:<span style="color: #0066CC;">XML</span>, col:AdvancedDataGridColumn<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">String</span><br />
<span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Return itemName as the label for the node</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">return</span> item.<span style="color: #66cc66;">@</span>itemName;<br />
<span style="color: #66cc66;">&#125;</span></div></td></tr></tbody></table></div>
<p>And last but not least, the icon function to return the icon depending on node name and other data (read comments in source for explanation):</p>
<div class="codecolorer-container actionscript mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> iconFunction<span style="color: #66cc66;">&#40;</span>item:<span style="color: #0066CC;">XML</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #000000; font-weight: bold;">Class</span><br />
<span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> parentName:<span style="color: #0066CC;">String</span>;<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">parentNode</span>:<span style="color: #0066CC;">XML</span>;<br />
&nbsp; &nbsp; <span style="color: #0066CC;">parentNode</span> = item.<span style="color: #006600;">parent</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Return office icon if node name not equal to item</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span> item.<span style="color: #0066CC;">name</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">!</span>= <span style="color: #ff0000;">&quot;item&quot;</span> <span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> iconOffice;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Check if parent not null</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">parentNode</span> <span style="color: #66cc66;">!</span>= <span style="color: #000000; font-weight: bold;">null</span> <span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Get parent name</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; parentName = <span style="color: #0066CC;">parentNode</span>.<span style="color: #0066CC;">name</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Sales below 30000: return error icon </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Expenses below 30000: return clear icon</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span> item.<span style="color: #66cc66;">@</span>amount <span style="color: #66cc66;">&lt;</span> <span style="color: #cc66cc;">30000</span> <span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> parentName == <span style="color: #ff0000;">&quot;Sales&quot;</span> ? iconError : iconClear;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Warning icon: the same threshold for both cases</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span> item.<span style="color: #66cc66;">@</span>amount <span style="color: #66cc66;">&lt;</span> <span style="color: #cc66cc;">60000</span> <span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> iconWarning;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// amount is greater than 60000, return clear if sales </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// and error if Expenses</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> parentName == <span style="color: #ff0000;">&quot;Sales&quot;</span> ? iconClear : iconError;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// default if none of the above apply</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">return</span> iconOffice;<br />
<span style="color: #66cc66;">&#125;</span></div></td></tr></tbody></table></div>
<p>That&#8217;s it! Here&#8217;s the sample application followed by the complete source code:<br />
<iframe src="http://www.flex-blog.com/samples/sample38/DataDependantTreeIconAdvancedDataGrid.html" width="100%" frameborder="0" height="400"></iframe></p>
<div class="codecolorer-container actionscript mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br />86<br />87<br />88<br />89<br />90<br />91<br />92<br />93<br />94<br />95<br />96<br />97<br />98<br />99<br />100<br />101<br />102<br />103<br />104<br />105<br />106<br />107<br />108<br />109<br />110<br />111<br />112<br />113<br />114<br />115<br />116<br />117<br />118<br />119<br />120<br />121<br />122<br />123<br />124<br />125<br />126<br />127<br />128<br />129<br />130<br />131<br /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #66cc66;">&lt;</span>?<span style="color: #0066CC;">xml</span> <span style="color: #0066CC;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #66cc66;">&gt;</span><br />
<span style="color: #66cc66;">&lt;</span>s:Application xmlns:fx=<span style="color: #ff0000;">&quot;http://ns.adobe.com/mxml/2009&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;xmlns:s=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/spark&quot;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;initialize=<span style="color: #ff0000;">&quot;init()&quot;</span> <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;500&quot;</span> <span style="color: #0066CC;">height</span>=<span style="color: #ff0000;">&quot;400&quot;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;xmlns:mx=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/mx&quot;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;minWidth=<span style="color: #ff0000;">&quot;955&quot;</span> minHeight=<span style="color: #ff0000;">&quot;600&quot;</span> viewSourceURL=<span style="color: #ff0000;">&quot;srcview/index.html&quot;</span><span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>s:layout<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>s:VerticalLayout paddingBottom=<span style="color: #ff0000;">&quot;5&quot;</span> paddingLeft=<span style="color: #ff0000;">&quot;5&quot;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; paddingRight=<span style="color: #ff0000;">&quot;5&quot;</span> paddingTop=<span style="color: #ff0000;">&quot;5&quot;</span><span style="color: #66cc66;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;/</span>s:layout<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>fx:Script<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;!</span><span style="color: #66cc66;">&#91;</span>CDATA<span style="color: #66cc66;">&#91;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">collections</span>.<span style="color: #006600;">HierarchicalData</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#91;</span>Bindable<span style="color: #66cc66;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> dataHierarchy:HierarchicalData;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#91;</span>Embed<span style="color: #66cc66;">&#40;</span>source=<span style="color: #ff0000;">&quot;assets/dialog-error.png&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> iconError:<span style="color: #000000; font-weight: bold;">Class</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#91;</span>Embed<span style="color: #66cc66;">&#40;</span>source=<span style="color: #ff0000;">&quot;assets/dialog-warning.png&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> iconWarning:<span style="color: #000000; font-weight: bold;">Class</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#91;</span>Embed<span style="color: #66cc66;">&#40;</span>source=<span style="color: #ff0000;">&quot;assets/weather-clear.png&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> iconClear:<span style="color: #000000; font-weight: bold;">Class</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#91;</span>Embed<span style="color: #66cc66;">&#40;</span>source=<span style="color: #ff0000;">&quot;assets/office.png&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> iconOffice:<span style="color: #000000; font-weight: bold;">Class</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> init<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> i:<span style="color: #0066CC;">int</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Root Node: Corporate Finance</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> xmlData:<span style="color: #0066CC;">XML</span> = <span style="color: #66cc66;">&lt;</span>Finance<span style="color: #66cc66;">&gt;&lt;/</span>Finance<span style="color: #66cc66;">&gt;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; xmlData.<span style="color: #66cc66;">@</span>itemName = <span style="color: #ff0000;">&quot;Corporate Finance&quot;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Sales node</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> sales:<span style="color: #0066CC;">XML</span> = <span style="color: #66cc66;">&lt;</span>Sales<span style="color: #66cc66;">&gt;&lt;/</span>Sales<span style="color: #66cc66;">&gt;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sales.<span style="color: #66cc66;">@</span>itemName = <span style="color: #ff0000;">&quot;Corporate Sales&quot;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Expenses Node</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> expenses:<span style="color: #0066CC;">XML</span> = <span style="color: #66cc66;">&lt;</span>Expenses<span style="color: #66cc66;">&gt;&lt;/</span>Expenses<span style="color: #66cc66;">&gt;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; expenses.<span style="color: #66cc66;">@</span>itemName = <span style="color: #ff0000;">&quot;Corporate Expenses&quot;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Append Sales and Expenses to Coporate finance</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; xmlData.<span style="color: #0066CC;">appendChild</span><span style="color: #66cc66;">&#40;</span>sales<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; xmlData.<span style="color: #0066CC;">appendChild</span><span style="color: #66cc66;">&#40;</span>expenses<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> salesItem:<span style="color: #0066CC;">XML</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Add some random sales items</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">for</span><span style="color: #66cc66;">&#40;</span> i=<span style="color: #cc66cc;">0</span>; i<span style="color: #66cc66;">&lt;</span><span style="color: #cc66cc;">5</span>; i++<span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; salesItem = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">XML</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&lt;</span>item<span style="color: #66cc66;">&gt;&lt;/</span>item<span style="color: #66cc66;">&gt;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; salesItem.<span style="color: #66cc66;">@</span>amount = <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">round</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">random</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">*</span> <span style="color: #cc66cc;">100000</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; salesItem.<span style="color: #66cc66;">@</span>itemName = <span style="color: #ff0000;">&quot;Random Sale &quot;</span> + i;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sales.<span style="color: #0066CC;">appendChild</span><span style="color: #66cc66;">&#40;</span>salesItem<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Add some random expense items</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> expensesItem:<span style="color: #0066CC;">XML</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">for</span><span style="color: #66cc66;">&#40;</span> i=<span style="color: #cc66cc;">0</span>; i<span style="color: #66cc66;">&lt;</span><span style="color: #cc66cc;">5</span>; i++<span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; expensesItem = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">XML</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&lt;</span>item<span style="color: #66cc66;">&gt;&lt;/</span>item<span style="color: #66cc66;">&gt;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; expensesItem.<span style="color: #66cc66;">@</span>amount = <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">round</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">random</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">*</span> <span style="color: #cc66cc;">100000</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; expensesItem.<span style="color: #66cc66;">@</span>itemName = <span style="color: #ff0000;">&quot;Random Expense &quot;</span> + i;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; expenses.<span style="color: #0066CC;">appendChild</span><span style="color: #66cc66;">&#40;</span>expensesItem<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Greate hierarchy based on created XML</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dataHierarchy = <span style="color: #000000; font-weight: bold;">new</span> HierarchicalData<span style="color: #66cc66;">&#40;</span>xmlData<span style="color: #66cc66;">&#41;</span>;&nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> labelFunction<span style="color: #66cc66;">&#40;</span>item:<span style="color: #0066CC;">XML</span>, col:AdvancedDataGridColumn<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">String</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Return itemName as the label for the node</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> item.<span style="color: #66cc66;">@</span>itemName;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> iconFunction<span style="color: #66cc66;">&#40;</span>item:<span style="color: #0066CC;">XML</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #000000; font-weight: bold;">Class</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> parentName:<span style="color: #0066CC;">String</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">parentNode</span>:<span style="color: #0066CC;">XML</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">parentNode</span> = item.<span style="color: #006600;">parent</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Return office icon if node name not equal to item</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span> item.<span style="color: #0066CC;">name</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">!</span>= <span style="color: #ff0000;">&quot;item&quot;</span> <span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> iconOffice;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Check if parent not null</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">parentNode</span> <span style="color: #66cc66;">!</span>= <span style="color: #000000; font-weight: bold;">null</span> <span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Get parent name</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; parentName = <span style="color: #0066CC;">parentNode</span>.<span style="color: #0066CC;">name</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Sales below 30000: return error icon </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Expenses below 30000: return clear icon</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span> item.<span style="color: #66cc66;">@</span>amount <span style="color: #66cc66;">&lt;</span> <span style="color: #cc66cc;">30000</span> <span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> parentName == <span style="color: #ff0000;">&quot;Sales&quot;</span> ? iconError : iconClear;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Warning icon: the same threshold for both cases</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span> item.<span style="color: #66cc66;">@</span>amount <span style="color: #66cc66;">&lt;</span> <span style="color: #cc66cc;">60000</span> <span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> iconWarning;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// amount is greater than 60000, return clear if sales </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// and error if Expenses</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> parentName == <span style="color: #ff0000;">&quot;Sales&quot;</span> ? iconClear : iconError;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// default if none of the above apply</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> iconOffice;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;/</span>fx:Script<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <br />
<span style="color: #66cc66;">&lt;</span>s:<span style="color: #0066CC;">Button</span> label=<span style="color: #ff0000;">&quot;Generate New Data&quot;</span> click=<span style="color: #ff0000;">&quot;init()&quot;</span><span style="color: #66cc66;">/&gt;</span><br />
<br />
<span style="color: #66cc66;">&lt;</span>mx:AdvancedDataGrid id=<span style="color: #ff0000;">&quot;adg&quot;</span> <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;100%&quot;</span> <span style="color: #0066CC;">height</span>=<span style="color: #ff0000;">&quot;100%&quot;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;dataProvider=<span style="color: #ff0000;">&quot;{dataHierarchy}&quot;</span> iconFunction=<span style="color: #ff0000;">&quot;iconFunction&quot;</span><span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>mx:columns<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>mx:AdvancedDataGridColumn headerText=<span style="color: #ff0000;">&quot;Finance&quot;</span> <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;350&quot;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;labelFunction=<span style="color: #ff0000;">&quot;labelFunction&quot;</span><span style="color: #66cc66;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>mx:AdvancedDataGridColumn headerText=<span style="color: #ff0000;">&quot;Amount&quot;</span> dataField=<span style="color: #ff0000;">&quot;@amount&quot;</span> <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;150&quot;</span><span style="color: #66cc66;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;/</span>mx:columns<span style="color: #66cc66;">&gt;</span><br />
<span style="color: #66cc66;">&lt;/</span>mx:AdvancedDataGrid<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <br />
<span style="color: #66cc66;">&lt;/</span>s:Application<span style="color: #66cc66;">&gt;</span></div></td></tr></tbody></table></div>


<p>Related posts:<ol><li><a href='http://www.flex-blog.com/drag-and-drop-from-datagrid-or-advanceddatagrid-to-tree/' rel='bookmark' title='Permanent Link: Drag and Drop from DataGrid or AdvancedDataGrid to Tree'>Drag and Drop from DataGrid or AdvancedDataGrid to Tree</a></li>
<li><a href='http://www.flex-blog.com/style-advanceddatagrid-depending-on-data-example/' rel='bookmark' title='Permanent Link: Style AdvancedDataGrid depending on data example'>Style AdvancedDataGrid depending on data example</a></li>
<li><a href='http://www.flex-blog.com/change-open-and-close-icons-on-flex-tree/' rel='bookmark' title='Permanent Link: Change open and close icons on Flex Tree'>Change open and close icons on Flex Tree</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.flex-blog.com/data-dependant-tree-icon-with-tree-in-advanceddatagrid-with-iconfunction/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>WordPress Flash / Flex Comments Form</title>
		<link>http://www.flex-blog.com/wordpress-flash-flex-comments-form/</link>
		<comments>http://www.flex-blog.com/wordpress-flash-flex-comments-form/#comments</comments>
		<pubDate>Wed, 28 Apr 2010 17:22:35 +0000</pubDate>
		<dc:creator>Roelof</dc:creator>
				<category><![CDATA[Examples]]></category>
		<category><![CDATA[ExternalInterface]]></category>
		<category><![CDATA[Flash Builder 4]]></category>
		<category><![CDATA[Flashvars]]></category>
		<category><![CDATA[Gravatar]]></category>
		<category><![CDATA[HTTPService]]></category>
		<category><![CDATA[MD5]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.flex-blog.com/?p=1059</guid>
		<description><![CDATA[Line Break Author: Roelof (11 Articles) - Author Website Roelof is a SAP Consultant specialized in Front-End development. In his spare free time he is either developing on the web, playing basketball, watching soccer, travelling or just being lazy. He is also the co-owner of Flex-Blog.com. This post is not an example, but a showcase! [...]


Related posts:<ol><li><a href='http://www.flex-blog.com/call-javascript-function-from-flex-flash-builder-as3/' rel='bookmark' title='Permanent Link: Call Javascript function from Flex / Flash Builder (AS3)'>Call Javascript function from Flex / Flash Builder (AS3)</a></li>
<li><a href='http://www.flex-blog.com/tinyurl-usage-with-flash-builder/' rel='bookmark' title='Permanent Link: TinyURL usage with Flash Builder'>TinyURL usage with Flash Builder</a></li>
<li><a href='http://www.flex-blog.com/flex-4-flash-builder-4-repeater-changed-to-datagroup/' rel='bookmark' title='Permanent Link: Flex 4 / Flash Builder 4: Repeater changed to DataGroup'>Flex 4 / Flash Builder 4: Repeater changed to DataGroup</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div class="TweetButton_button" style="float: right; margin-left: 10px;;height:20px;margin-bottom:5px;">
<p>			<a href="http://twitter.com/share?url=http%3A%2F%2Fwww.flex-blog.com%2Fwordpress-flash-flex-comments-form%2F&amp;text=WordPress Flash / Flex Comments Form&amp;count=vertical&amp;via=FlexBlog&amp;lang=en&amp;related=ExternalInterface,Flash+Builder+4,Flashvars,Gravatar,HTTPService,MD5,wordpress"></p>
<p>				<img src="http://www.flex-blog.com/wp-content/plugins/tweetbutton-for-wordpress/images/tweet.png" style="border:none" /></p>
<p>			</a></p></div>
<p><small style="visibility:hidden; font-size:1px;">Line Break</small>
<div class="atab_box">
<p><b>Author: <a href="http://www.flex-blog.com/author/roelof/">Roelof</a></b> <small>(11 Articles)</small> - <a href="http://www.flex-blog.com">Author Website</a></p>
<img alt='' src='http://0.gravatar.com/avatar/2caba20bc811d080f88174249b682d14?s=50&amp;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D50&amp;r=G' class='avatar avatar-50 photo' height='50' width='50' />
<p style="min-height:65px;">Roelof is a SAP Consultant specialized in Front-End development. In his spare free time he is either developing on the web, playing basketball, watching soccer, travelling or just being lazy. He is also the co-owner of Flex-Blog.com.</p>
</div><p></p>
<p>This post is not an example, but a showcase! As you&#8217;ve seen, we have been creating <a href="/components/">WordPress Plugins in Flex</a> for a while now, which you can download for free.</p>
<p>While creating these plugins, we have learned that Flex and WordPress are a powerful combination, which we should use more often. A while ago, I was looking at our website, and saw our comment form, which was not really impressing me. So I started creating one in Flex.<br />
<span id="more-1059"></span><br />
Some technical info:</p>
<ul>
<li>The comment form was created in Flash Builder 4.</li>
<li>The panel look was changed using Skinning.</li>
<li>We receive WordPress data through Flashvars.</li>
<li>We post data via a HTTPService.</li>
<li>We refresh the screen using Javascript (ExternalInterface).</li>
<li>Gravatar support, using the gravatar api. (which uses an MD5 hash of the emailaddress)</li>
</ul>
<p>Check this great Flex &amp; WordPress Showcase underneath every post. Let us know what you think about it! If you like it we might make a WordPress Plugin for it!</p>
<p>This showcase gave me a lot of inspiration for more examples on Flex Blog. Oh and btw, leave a comment <img src='http://www.flex-blog.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> !</p>


<p>Related posts:<ol><li><a href='http://www.flex-blog.com/call-javascript-function-from-flex-flash-builder-as3/' rel='bookmark' title='Permanent Link: Call Javascript function from Flex / Flash Builder (AS3)'>Call Javascript function from Flex / Flash Builder (AS3)</a></li>
<li><a href='http://www.flex-blog.com/tinyurl-usage-with-flash-builder/' rel='bookmark' title='Permanent Link: TinyURL usage with Flash Builder'>TinyURL usage with Flash Builder</a></li>
<li><a href='http://www.flex-blog.com/flex-4-flash-builder-4-repeater-changed-to-datagroup/' rel='bookmark' title='Permanent Link: Flex 4 / Flash Builder 4: Repeater changed to DataGroup'>Flex 4 / Flash Builder 4: Repeater changed to DataGroup</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.flex-blog.com/wordpress-flash-flex-comments-form/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
