<?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/"
	>

<channel>
	<title>Web App Solution Blog &#187; flex</title>
	<atom:link href="http://www.webappsolution.com/wordpress/category/flex/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.webappsolution.com/wordpress</link>
	<description>When you're in need of an appsolution</description>
	<pubDate>Thu, 05 Apr 2012 19:39:33 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Styling MX Alert in a Spark World</title>
		<link>http://www.webappsolution.com/wordpress/2012/04/05/styling-mx-alert-in-a-spark-world/</link>
		<comments>http://www.webappsolution.com/wordpress/2012/04/05/styling-mx-alert-in-a-spark-world/#comments</comments>
		<pubDate>Thu, 05 Apr 2012 19:39:33 +0000</pubDate>
		<dc:creator>brianr</dc:creator>
		
		<category><![CDATA[flex]]></category>

		<category><![CDATA[spark]]></category>

		<guid isPermaLink="false">http://www.webappsolution.com/wordpress/?p=1050</guid>
		<description><![CDATA[If you&#8217;ve ever tried to style the MX Alert in a Spark Application (Flex 4.x), then you know it&#8217;s painful&#8230;the solution?
Save yourself some time and just create a custom Alert view and skin and use the PopupManager to show/hide the sucker. Takes about 5 mins and ensures you can style it to your hearts content.
 Tweet This [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;ve ever tried to style the MX Alert in a Spark Application (Flex 4.x), then you know it&#8217;s painful&#8230;the solution?</p>
<p>Save yourself some time and just create a custom Alert view and skin and use the PopupManager to show/hide the sucker. Takes about 5 mins and ensures you can style it to your hearts content.</p>
<p align="left"><a class="tt" href="http://twitter.com/home/?status=Styling+MX+Alert+in+a+Spark+World+http://tinyurl.com/6mu7bgu" title="Post to Twitter"><img class="nothumb" src="http://www.webappsolution.com/wordpress/wp-content/plugins/tweet-this/icons/tt-twitter.png" alt="Post to Twitter" /></a> <a class="tt" href="http://twitter.com/home/?status=Styling+MX+Alert+in+a+Spark+World+http://tinyurl.com/6mu7bgu" title="Post to Twitter">Tweet This Post</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.webappsolution.com/wordpress/2012/04/05/styling-mx-alert-in-a-spark-world/feed/</wfw:commentRss>
		</item>
		<item>
		<title>One Java Service POJO for AMF/XML/JSON with Spring BlazeDS &amp; Jersey JAX-RS</title>
		<link>http://www.webappsolution.com/wordpress/2012/03/23/one-java-service-pojo-for-amfxmljson-with-spring-blazeds-jersey-jax-rs/</link>
		<comments>http://www.webappsolution.com/wordpress/2012/03/23/one-java-service-pojo-for-amfxmljson-with-spring-blazeds-jersey-jax-rs/#comments</comments>
		<pubDate>Fri, 23 Mar 2012 13:19:52 +0000</pubDate>
		<dc:creator>brianr</dc:creator>
		
		<category><![CDATA[blazeds]]></category>

		<category><![CDATA[flex]]></category>

		<category><![CDATA[java]]></category>

		<category><![CDATA[jersey jax-rs]]></category>

		<category><![CDATA[sencha extjs]]></category>

		<guid isPermaLink="false">http://www.webappsolution.com/wordpress/?p=1009</guid>
		<description><![CDATA[Introduction
I was reading Christophe Coenraets&#8217; blog post on RESTful services with jQuery and Java using JAX-RS and Jersey and it got me thinking&#8230;in order to serve technology agnostic Java Service POJOs to HTML5/JavaScript clients as well as Flex/AIR/Flash clients without writing two service layers and a whole bunch of extra code, why not just put Jersey&#8217;s JAX-RS framework next [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Introduction</strong></p>
<p>I was reading Christophe Coenraets&#8217; blog post on <a href="http://coenraets.org/blog/2011/12/restful-services-with-jquery-and-java-using-jax-rs-and-jersey/" target="_blank">RESTful services with jQuery and Java using JAX-RS and Jersey</a> and it got me thinking&#8230;in order to serve technology agnostic Java Service POJOs to HTML5/JavaScript clients as well as Flex/AIR/Flash clients without writing two service layers and a whole bunch of extra code, why not just put <a href="http://jersey.java.net/" target="_blank">Jersey&#8217;s JAX-RS framework</a> next to <a href="http://www.springsource.org/spring-flex" target="_blank">Spring BlazeDS framework</a>?</p>
<p><strong>Tutorial Goal</strong>: Create one Java Service POJO capable of handling RESTful services with XML/JSON over HTTP as well as AMF over HTTP (for RemoteObjects with the Flash Platform) and demonstrate this via a <a href="http://www.sencha.com/products/extjs/" target="_blank">Sencha ExtJS</a> (JavaScript) app and <a href="http://incubator.apache.org/flex/" target="_blank">Apache Flex</a> app.</p>
<p><strong>NOTE</strong>: I could&#8217;ve used Spring&#8217;s owen REST framework, but I found Jersey easier than Spring&#8217;s 3.02 impl that I&#8217;m using and Christophe already banged this out in Jersey so I really just needed to add the Flex part with Spring BlazeDS &#8212; big thanks to <a href="http://twitter.com/#!/ccoenraets" target="_blank">@ccoenraets</a> for kicking this post off for me! &#8230;the point is you can use either Spring or Jersey&#8217;s REST impl.</p>
<p>The following is a quick example of a simple Java CRUD Service for beers (because, well, I like beers &#8212; <a href="http://untappd.com/" target="_blank">Untappd</a>) that serves both HTML5/JavaScript clients via XML/JSON over HTTP as well as Flex clients via AMF over HTTP using Spring BlazeDS.</p>
<p><strong>Download Sample Code</strong></p>
<ul>
<li><a href="http://www.webappsolution.com/blog/SpringBlazeDSJerseyServer.war">Java WAR Project</a></li>
<li><a href="http://www.webappsolution.com/blog/SpringBlazeDSJerseyFlex.fxp">Flex Project</a></li>
</ul>
<p><strong>Assumptions</strong></p>
<ul>
<li><span>This post assumes you know what </span><a href="http://www.ibm.com/developerworks/webservices/library/ws-restful/" target="_blank">RESTful Services are</a><span> and have read </span><a href="http://coenraets.org/blog/2011/12/restful-services-with-jquery-and-java-using-jax-rs-and-jersey/" target="_blank">RESTful services with jQuery and Java using JAX-RS and Jersey</a><span> so you&#8217;re familiar with Jersey.</span></li>
<li><span>This post assumes you&#8217;re familiar with Flex and using </span><a href="http://opensource.adobe.com/wiki/display/blazeds/BlazeDS" target="_blank">BlazeDS for RemoteObject</a><span> calls with the Flash Platform.</span></li>
<li>This post assumes you&#8217;re familiar with JavaScript and/or <a href="http://www.sencha.com/products/extjs/" target="_blank">Sencha ExtJS</a> (a JavaScript framework similar to Flex with a robust UI library, services, and prescribed MVC architecture).</li>
<li>This example uses a Tomcat 7 server running on http://localhost:8080/SpringBlazeDSJerseyServer and will refer to that URL throughout the post.</li>
</ul>
<p><strong>How&#8217;s It Work At A High Level?</strong><br />
Both Spring BlazeDS and Jersey work off of the same simple principle of servlet filtering which is configured in web.xml and explained in detail further down in the article &#8212; in our example the following mappings take care of everything</p>
<p>Spring BlazeDS = http://localhost:8080/SpringBlazeDSJerseyServer/messagebroker/*</p>
<p>Jersey = http://localhost:8080/SpringBlazeDSJerseyServer/rest/*</p>
<p><strong>Bottom line, these frameworks sit next to each other in the servlet container and do not interfere with each other or use each other in any way.</strong> These simply share the same Java Service so you&#8217;re not coding one for Flex and one for HTML/JavaScript.</p>
<p><strong>One Java Service to Rule Them All</strong></p>
<p>Let&#8217;s take a quick peak at the Java Service BeerService and see what&#8217;s so special about it. The key to exposing this service to both BlazeDS and Jersey is in the annotations; review the comments above the class to see what each does.</p>
<pre class="brush: java;">
package com.webappsolution.springbdsjersey.service.impl;

/**
 * &lt;b&gt;Spring BlazeDS Annotations&lt;/b&gt;
 * &lt;p&gt;
 * The annotation Service is used to tell Spring this object is a service bean.
 * The annotation RemotingDestination is used to expose it as a Flex Remoting destination.
 * The annotation RemotingInclude above individual methods is used to expose public methods of the service to Flex
 * as opposed to RemotingExclude which hides them from a Flex client.
 * &lt;/p&gt;
 *
 * &lt;b&gt;Jersey JAX-RS Annotations&lt;/b&gt;
 * &lt;p&gt;
 * The annotation Path is used to define the base URL pattern (after the app server's context) to map to this RESTful Jersey service.
 * The annotation GET above individual methods is used to define the HTTP action/verb associated with the service method.
 * The annotation Produces above individual methods is used to define the request and response types for the service method.
 * The annotation GET Path(&quot;{id}&quot;) above individual methods is used to add specific method parameters for the service method via REST path.
 * &lt;/p&gt;
 */
@Service(&quot;beerService&quot;)
@RemotingDestination
@Path(&quot;/beer&quot;)
public class BeerService implements IBeerService
{
	private static Log logger = LogFactory.getLog(BeerService.class);

	BeerDAO dao = new BeerDAO();

	@Override
	@RemotingInclude // BDS
	@GET // JERSEY
	@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) // JERSEY
	public List&lt;BeerDTO&gt; findAll()
	{
		logger.debug(&quot;findAll&quot;);
		return dao.findAll();
	}

	@Override
	@RemotingInclude // BDS
	@GET @Path(&quot;{id}&quot;) // JERSEY
	@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) // JERSEY
	public BeerDTO findById(@PathParam(&quot;id&quot;) String id)
	{
		logger.debug(&quot;findById: &quot; + id);
		return dao.findById(Integer.parseInt(id));
	}

	@Override
	public BeerDTO create()
	{
		logger.debug(&quot;create&quot;);
		return null;
	}

	@Override
	public BeerDTO update()
	{
		logger.debug(&quot;update&quot;);
		return null;
	}

	@Override
	public void delete()
	{
		logger.debug(&quot;delete&quot;);
	}

}
</pre>
<p>Next we&#8217;ll need to add an annotation to our simple BeerDTO so Jersey knows how to convert it to XML or JSON; take note of the annotation XMLRootElement:</p>
<pre class="brush: java;">
@XmlRootElement
public class BeerDTO
{
	private int id;
	private String name;
	private String brewery;

	public BeerDTO()
	{
		// TODO Auto-generated constructor stub
	}

	public int getId()
	{
		return id;
	}

	public void setId(int id)
	{
		this.id = id;
	}

	public String getName()
	{
		return name;
	}

	public void setName(String name)
	{
		this.name = name;
	}

	public void setBrewery(String brewery)
	{
		this.brewery = brewery;
	}

	public String getBrewery()
	{
		return brewery;
	}
}
</pre>
<p>This has no effect on our DTO when being used by Spring BlazeDS.</p>
<p>After that the other big piece to getting this thing cranking is the required JARs (which I packaged up in the WAR so you can play easily) and checking out the web descriptor for the app (web.xml) as it maps incoming servlet requests for Jersey and BlazeDS appropriately.</p>
<p><strong>web.xml - Spring BlazeDS config</strong></p>
<pre class="brush: xml;">
&lt;!-- ================================================= --&gt;
&lt;!-- SPRING BLAZEDS PROJECT SETUP --&gt;
&lt;!-- ================================================= --&gt;
&lt;!--	This will configure the BlazeDS message broker as a Spring-managed bean using the simple message-broker tag.
		This will bootstrap the BlazeDS message broker. When you use the message-broker tag without mapping child elements,
		all incoming DispatcherServlet requests are mapped to the MessageBroker.
		You can add mapping child elements if you need more control.
		Any requests hitting the URL http://SpringBlazeDSJerseyServer/messagebroker/* will get mapped to Spring BlazeDS.
                The component scanning for Spring BlazeDS services is done in app-context-flex.xml.
--&gt;
&lt;!-- ================================================= --&gt;
&lt;context-param&gt;
	&lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
	&lt;param-value&gt;
		classpath:/spring/config/applicationContext.xml
	&lt;/param-value&gt;
&lt;/context-param&gt;

&lt;listener&gt;
	&lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt;
&lt;/listener&gt;
&lt;listener&gt;
	&lt;listener-class&gt;flex.messaging.HttpFlexSession&lt;/listener-class&gt;
&lt;/listener&gt;
&lt;servlet&gt;
	&lt;servlet-name&gt;flexspring&lt;/servlet-name&gt;
	&lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;
	&lt;init-param&gt;
		&lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
		&lt;param-value&gt;&lt;/param-value&gt;
	&lt;/init-param&gt;
	&lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
&lt;/servlet&gt;
&lt;servlet-mapping&gt;
	&lt;servlet-name&gt;flexspring&lt;/servlet-name&gt;
	&lt;url-pattern&gt;/messagebroker/*&lt;/url-pattern&gt;
&lt;/servlet-mapping&gt;
</pre>
<p><strong>web.xml - Jersey config</strong></p>
<pre class="brush: xml;">
&lt;!-- ================================================= --&gt;
&lt;!-- JERSEY --&gt;
&lt;!-- ================================================= --&gt;
&lt;!--	Configure Jersey JAX-RS to handle RESTful services
		Any requests hitting the URL http://SpringBlazeDSJerseyServer/rest/*
		will get mapped to Jersey. The param &quot;com.sun.jersey.config.property.packages&quot;
		with a value of &quot;com.webappsolution.springbdsjersey.service&quot; tells Jersey
		the package to scan for Jersey enabled services. You can add more than 1.
--&gt;
&lt;!-- ================================================= --&gt;
&lt;servlet&gt;
	&lt;servlet-name&gt;Jersey&lt;/servlet-name&gt;
	&lt;servlet-class&gt;com.sun.jersey.spi.container.servlet.ServletContainer&lt;/servlet-class&gt;
	&lt;init-param&gt;
		&lt;param-name&gt;com.sun.jersey.config.property.packages&lt;/param-name&gt;
		&lt;param-value&gt;com.webappsolution.springbdsjersey.service&lt;/param-value&gt;
	&lt;/init-param&gt;
	&lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
&lt;/servlet&gt;

&lt;servlet-mapping&gt;
	&lt;servlet-name&gt;Jersey&lt;/servlet-name&gt;
	&lt;url-pattern&gt;/rest/*&lt;/url-pattern&gt;
&lt;/servlet-mapping&gt;
</pre>
<p><strong>Quick HTTP REST Test</strong><br />
Start the Server and hit the following URL: <a href="http://localhost:8080/SpringBlazeDSJerseyServer/rest/beer" target="_blank">http://localhost:8080/SpringBlazeDSJerseyServer/rest/beer</a> and you should see an XML list of Beers. This is good and means you&#8217;re ready to test the Flex side. </p>
<p>As Christophe points out, you can also use the cURL command in terminal to see the results: </p>
<ul>
<li><strong>Get All Beers</strong>: curl -i -X GET http://localhost:8080/SpringBlazeDSJerseyServer/rest/beer</li>
<li><strong>Get Beer By ID</strong>: curl -i -X GET http://localhost:8080/SpringBlazeDSJerseyServer/rest/beer/1</li>
<li><strong>Get All Beers - XML</strong>: curl -i -X GET http://localhost:8080/SpringBlazeDSJerseyServer/rest/beer -H &#8216;Accept:application/xml&#8217;</li>
<li><strong>Get All Beers - JSON</strong>: curl -i -X GET http://localhost:8080/SpringBlazeDSJerseyServer/rest/beer -H &#8216;Accept:application/json&#8217;</li>
</ul>
<p><strong>Flex RemoteObject Beer Service Example</strong><br />
Our simple Flex example has a button that invokes the RemoteObject BeerService.findAll() method and uses the ArrayCollection response to populate a DataGrid.</p>
<pre class="brush: as3;">
protected var beerService:RemoteObject;

protected function init(event:FlexEvent):void
{
	this.beerService = new RemoteObject(&quot;beerService&quot;);
	this.beerService.endpoint = &quot;http://localhost:8080/SpringBlazeDSJerseyServer/messagebroker/amf&quot;;
	this.beerService.addEventListener(ResultEvent.RESULT, onBeerServiceResult);
	this.beerService.addEventListener(FaultEvent.FAULT, onBeerServiceRFault);
}

protected function onBeerServiceBtnClick(event:MouseEvent):void
{
	this.beerService.findAll();
}

protected function onBeerServiceResult(event:ResultEvent):void
{
	this.beerDG.dataProvider = event.result as ArrayCollection;
}

protected function onBeerServiceRFault(event:FaultEvent):void
{
	Alert.show(&quot;Beer Service Error = &quot; + event.fault.faultDetail, &quot;Error&quot;);
}
</pre>
<p>Assuming your server is still running, run the Flex app and click the &#8220;Get Beers!&#8221; button and watch the DataGrid populate with some solid brews. Your Flex app should look like:</p>
<p><img src="http://www.webappsolution.com/wordpress/wp-content/uploads/2012/03/spring-bds-jersey-get-all-flex.png" alt="" /></p>
<p><strong>Sencha ExtJS RESTful Beer Service Example</strong><br />
Similarly, our simple ExtJS example has a button that invokes the RESTful service method BeerService.findAll() via a Proxy within a store that requests JSON as the data format&#8211; the response is also mapped back to the Grid.</p>
<p>First, let&#8217;s define the matching Beer Model on the client &#8212; this matches our BeerDTO on the server and is similar to how we&#8217;d mapped Flex ActionScript objects to the same Java BeerDTO.</p>
<pre class="brush: as3;">
Ext.define('Beer', {
	extend: 'Ext.data.Model',
	fields:
		[ 'id', 'name', 'brewery' ],
});
</pre>
<p>Next we&#8217;ll create a Store that uses a REST proxy to interact with the Jersey Services and is responsible for mapping the Beer Model we just created to the JOSN request and responses from Jersey. There&#8217;s some additional CRUD code that isn&#8217;t actually being used in this post but will in the future.</p>
<pre class="brush: as3;">
var store = Ext.create('Ext.data.Store', {
    autoLoad: false,
    autoSync: true,
    model: 'Beer',
    proxy: {
    	headers: {
            'accept': 'application/json'
        },
        type: 'rest',
        url: 'http://localhost:8080/SpringBlazeDSJerseyServer/rest/beer',
        reader: {
            type: 'json',
            root: 'beerDTO'
        },
        writer: {
            type: 'json'
        }
    },
    listeners: {
        write: function(store, operation){
            var record = operation.getRecords()[0],
                name = Ext.String.capitalize(operation.action),
                verb;

            if (name == 'Destroy') {
                record = operation.records[0];
                verb = 'Destroyed';
            } else {
                verb = name + 'd';
            }
            Ext.example.msg(name, Ext.String.format(&quot;{0} user: {1}&quot;, verb, record.getId()));

        }
    }
});
</pre>
<p>Finally we&#8217;ll create our Grid and Button to invoke the service:</p>
<pre class="brush: as3;">
var grid = Ext.create('Ext.grid.Panel', {
    renderTo: document.body,
    plugins: [rowEditing],
    width: 500,
    height: 300,
    frame: true,
    title: 'Beers',
    store: store,
    iconCls: 'icon-beer',
    columns: [{
        text: 'ID',
        width: 40,
        sortable: true,
        dataIndex: 'id'
    }, {
        text: 'Name',
        flex: 1,
        sortable: true,
        dataIndex: 'name',
        field: {
            xtype: 'textfield'
        }
    }, {
        header: 'Brewery',
        flex: 1,
        sortable: true,
        dataIndex: 'brewery',
        field: {
            xtype: 'textfield'
        }
    }]
});

Ext.create('Ext.Button', {
    text: 'Get Beers!',
    renderTo: Ext.getBody(),
    handler: function() {
    	store.load();
    }
});
</pre>
<p>Assuming you&#8217;re server is still running, run the ExtJS app by hitting the URL <a href="http://localhost:8080/SpringBlazeDSJerseyServer/extjs/springblazedsjersey/restful.html" target="_blank">http://localhost:8080/SpringBlazeDSJerseyServer/extjs/springblazedsjersey/restful.html</a> and click the &#8220;Get Beers!&#8221; button and watch the DataGrid populate with some solid brews. Your ExtJS app should look like:</p>
<p><img src="http://www.webappsolution.com/wordpress/wp-content/uploads/2012/03/spring-bds-jersey-get-all-extjs.png" alt="" /></p>
<p>Any questions?</p>
<p align="left"><a class="tt" href="http://twitter.com/home/?status=One+Java+Service+POJO+for+AMF%2FXML%2FJSON+with+Spring+BlazeDS+%26+Jersey+JAX-RS+http://tinyurl.com/7hdqsxf" title="Post to Twitter"><img class="nothumb" src="http://www.webappsolution.com/wordpress/wp-content/plugins/tweet-this/icons/tt-twitter.png" alt="Post to Twitter" /></a> <a class="tt" href="http://twitter.com/home/?status=One+Java+Service+POJO+for+AMF%2FXML%2FJSON+with+Spring+BlazeDS+%26+Jersey+JAX-RS+http://tinyurl.com/7hdqsxf" title="Post to Twitter">Tweet This Post</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.webappsolution.com/wordpress/2012/03/23/one-java-service-pojo-for-amfxmljson-with-spring-blazeds-jersey-jax-rs/feed/</wfw:commentRss>
		</item>
		<item>
		<title>How to Make a SWFLoader Scroll</title>
		<link>http://www.webappsolution.com/wordpress/2011/04/07/how-to-make-a-swfloader-scroll/</link>
		<comments>http://www.webappsolution.com/wordpress/2011/04/07/how-to-make-a-swfloader-scroll/#comments</comments>
		<pubDate>Thu, 07 Apr 2011 11:56:25 +0000</pubDate>
		<dc:creator>brianr</dc:creator>
		
		<category><![CDATA[flex]]></category>

		<category><![CDATA[fix]]></category>

		<category><![CDATA[scrollbars]]></category>

		<category><![CDATA[scrolling]]></category>

		<category><![CDATA[swfloader]]></category>

		<category><![CDATA[workaround]]></category>

		<guid isPermaLink="false">http://www.webappsolution.com/wordpress/?p=1006</guid>
		<description><![CDATA[By default, the SWFLoader doesn&#8217;t scroll so developers often wrap it in a scrolling mx container like a Canvas (since it does scroll and it&#8217;s scroll policies are set to auto). What I didn&#8217;t think about was that I&#8217;d have to know the actual size of the content I was loading in order for the [...]]]></description>
			<content:encoded><![CDATA[<p>By default, the SWFLoader doesn&#8217;t scroll so developers often wrap it in a scrolling mx container like a Canvas (since it does scroll and it&#8217;s scroll policies are set to auto). What I didn&#8217;t think about was that I&#8217;d have to know the actual size of the content I was loading in order for the scrollbars to appear. I tested this in both an MX Application and a Spark Application with Flex SDK 4.5 and achieved the same results.</p>
<p>To reiterate, my small test app below suggests that <strong><em>developers must know the size of the content they are loading in SWFLoader in order for the scrollbars to appear around that loaded content. </em></strong></p>
<p>When I think about it, it makes sense&#8230;at the same time it caught me by surprise when I first implemented it in an app. Hoping this piece of info helps developers loading legacy or 3rd party SWFs they don&#8217;t have control over.</p>
<pre class="brush: as3;">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;s:Application
	xmlns:fx=&quot;http://ns.adobe.com/mxml/2009&quot;
	xmlns:s=&quot;library://ns.adobe.com/flex/spark&quot;
	xmlns:mx=&quot;library://ns.adobe.com/flex/mx&quot;
	minWidth=&quot;0&quot;
	minHeight=&quot;0&quot;
	creationComplete=&quot;init(event)&quot;
	backgroundColor=&quot;#FF0000&quot;
	&gt;

	&lt;fx:Script&gt;
		&lt;![CDATA[
			import mx.containers.Canvas;
			import mx.controls.SWFLoader;
			import mx.events.FlexEvent;

			protected function init(event:FlexEvent):void
			{
				var swfLoaderContainer:Canvas = new Canvas();
				swfLoaderContainer.percentWidth = 100;
				swfLoaderContainer.percentHeight = 100;
				this.addElement(swfLoaderContainer);

				var swfLoader:SWFLoader = new SWFLoader();
				swfLoader.width = 1200; // does not add scroll bar
				swfLoader.height = 800; // does not add scroll bar
//				swfLoader.percentWidth = 100; // DOES NOT add scroll bar
//				swfLoader.percentHeight = 100; // DOES NOT add scroll bar
				swfLoader.scaleContent = false;
				swfLoaderContainer.addElement(swfLoader);

				var context:LoaderContext = new LoaderContext(false, new ApplicationDomain());
				swfLoader.loaderContext = context;
				swfLoader.load(&quot;SWFToLoad.swf&quot;);
			}

		]]&gt;
	&lt;/fx:Script&gt;

&lt;/s:Application&gt;
</pre>
<p align="left"><a class="tt" href="http://twitter.com/home/?status=How+to+Make+a+SWFLoader+Scroll+http://tinyurl.com/3wogy2k" title="Post to Twitter"><img class="nothumb" src="http://www.webappsolution.com/wordpress/wp-content/plugins/tweet-this/icons/tt-twitter.png" alt="Post to Twitter" /></a> <a class="tt" href="http://twitter.com/home/?status=How+to+Make+a+SWFLoader+Scroll+http://tinyurl.com/3wogy2k" title="Post to Twitter">Tweet This Post</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.webappsolution.com/wordpress/2011/04/07/how-to-make-a-swfloader-scroll/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Getting Flex Spark &amp; MX Components to Use Embedded Fonts :: Part 2</title>
		<link>http://www.webappsolution.com/wordpress/2011/04/06/getting-flex-spark-mx-components-to-use-embedded-fonts-part-2/</link>
		<comments>http://www.webappsolution.com/wordpress/2011/04/06/getting-flex-spark-mx-components-to-use-embedded-fonts-part-2/#comments</comments>
		<pubDate>Wed, 06 Apr 2011 17:19:09 +0000</pubDate>
		<dc:creator>brianr</dc:creator>
		
		<category><![CDATA[flex]]></category>

		<category><![CDATA[flex builder]]></category>

		<category><![CDATA[css]]></category>

		<category><![CDATA[embedded-fonts]]></category>

		<category><![CDATA[legend]]></category>

		<category><![CDATA[mx]]></category>

		<category><![CDATA[spark]]></category>

		<category><![CDATA[style]]></category>

		<guid isPermaLink="false">http://www.webappsolution.com/wordpress/?p=990</guid>
		<description><![CDATA[In my last post about this I found an ugly workaround in order to get embedded fonts to work in both MX and Spark Components. Since then I&#8217;ve learned the best way to do this is simply to select the checkbox in the Project Properties -> Flex Compiler -> &#8220;Use Flash Text Engine in MX [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.webappsolution.com/wordpress/2011/01/20/getting-spark-mx-components-to-use-embedded-fonts/" target="_blank">In my last post about this</a> I found an ugly workaround in order to get embedded fonts to work in both MX and Spark Components. Since then I&#8217;ve learned the best way to do this is simply to select the checkbox in the Project Properties -> Flex Compiler -> &#8220;Use Flash Text Engine in MX Components&#8221; checkbox = true.</p>
<p><strong>NOTE</strong>: Using Flash Builder Burrito and Flex Hero 4.5 &#8212; haven&#8217;t tested to see if this was the previous issue or not but I wanted to make note of it.</p>
<p><img class="alignleft size-full wp-image-995" title="Use Flash Text Engine in MX Components" src="http://www.webappsolution.com/wordpress/wp-content/uploads/2011/04/screen-shot-2011-04-06-at-10348-pm4.png" alt="Use Flash Text Engine in MX Components" width="334" height="268" />This seems to make embedded fonts play nice in both MX and Spark components in almost every situation. The one I couldn&#8217;t seem to get around was mx:Legend.</p>
<p>When I embedded a font and used this compiler setting, I would randomly see only a couple of my legend labels show up. However, by using just a small piece of my old workaround I was soon back in business.</p>
<p><strong>NOTE</strong>: There is one rather large drawback to this though&#8230;you have to embed your font twice &#8212; once for Spark and once for MX.</p>
<p>Your css should look something like this:</p>
<pre class="brush: as3;">
/********************************************************
/ Fonts
/*******************************************************/
@font-face
{
	src: url(&quot;/resources/font/MyriadPro-Regular.otf&quot;);
	font-family: SparkEmbeddedFont;
	font-weight: normal;
	embed-as-cff: true;
}

@font-face
{
	src: url(&quot;/resources/font/MyriadPro-Bold.otf&quot;);
	font-family: SparkEmbeddedFont;
	font-weight: bold;
	embed-as-cff: true;
}

/********************************************************
/ NOTE: Due to an issue with the legend and embedded
/ fonts we need to embed the font as non cff too.
/*******************************************************/
@font-face
{
	src: url(&quot;/resources/font/MyriadPro-Regular.otf&quot;);
	font-family: MXEmbeddedFont;
	font-weight: normal;
	embed-as-cff: false;
}

@font-face
{
	src: url(&quot;/resources/font/MyriadPro-Bold.otf&quot;);
	font-family: MXEmbeddedFont;
	font-weight: bold;
	embed-as-cff: false;
}

/************************************************************
/ Flex Class-Level Styles
/************************************************************/
s|Application
{
	font-family: SparkEmbeddedFont;
	color: #000000;
}

mx|LegendItem, mx|PieSeries
{
	font-family: MXEmbeddedFont;
	font-size: 12;
	textFieldClass: ClassReference(&quot;mx.core.UITextField&quot;);
}
</pre>
<p align="left"><a class="tt" href="http://twitter.com/home/?status=Getting+Flex+Spark+%26+MX+Components+to+Use+Embedded+Fonts+%3A%3A+Part+2+http://tinyurl.com/42t5xn3" title="Post to Twitter"><img class="nothumb" src="http://www.webappsolution.com/wordpress/wp-content/plugins/tweet-this/icons/tt-twitter.png" alt="Post to Twitter" /></a> <a class="tt" href="http://twitter.com/home/?status=Getting+Flex+Spark+%26+MX+Components+to+Use+Embedded+Fonts+%3A%3A+Part+2+http://tinyurl.com/42t5xn3" title="Post to Twitter">Tweet This Post</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.webappsolution.com/wordpress/2011/04/06/getting-flex-spark-mx-components-to-use-embedded-fonts-part-2/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Flex 4 ModuleManager &amp; CSS Inheriting Styles</title>
		<link>http://www.webappsolution.com/wordpress/2011/03/17/flex-4-modulemanager-css-inheriting-styles/</link>
		<comments>http://www.webappsolution.com/wordpress/2011/03/17/flex-4-modulemanager-css-inheriting-styles/#comments</comments>
		<pubDate>Thu, 17 Mar 2011 22:24:30 +0000</pubDate>
		<dc:creator>brianr</dc:creator>
		
		<category><![CDATA[flex]]></category>

		<category><![CDATA[css]]></category>

		<category><![CDATA[flex-4]]></category>

		<category><![CDATA[module]]></category>

		<category><![CDATA[module-manager]]></category>

		<category><![CDATA[spark]]></category>

		<category><![CDATA[styles]]></category>

		<guid isPermaLink="false">http://www.webappsolution.com/wordpress/?p=980</guid>
		<description><![CDATA[A client I&#8217;m working with has a Flex 3.5 app that&#8217;s being migrated to 4.5 and one of the immediate issues we ran into (after we got it compiling successfully) was that the modules didn&#8217;t inherit the styles from the main app&#8230;worked fine in 3.5, but not in 4.5, so what gives?
So I created a [...]]]></description>
			<content:encoded><![CDATA[<p>A client I&#8217;m working with has a Flex 3.5 app that&#8217;s being migrated to 4.5 and one of the immediate issues we ran into (after we got it compiling successfully) was that the modules didn&#8217;t inherit the styles from the main app&#8230;worked fine in 3.5, but not in 4.5, so what gives?</p>
<p>So I created a simple PoC with a ModuleLoader and it did indeed pick up on the main apps styles as expected. Next I changed my PoC to resemble the client&#8217;s architecture a bit more and used a ModuleManager to load the module &#8212; low and behold, the module didn&#8217;t inherit the main app&#8217;s styles.</p>
<p>After some reading on Adobe&#8217;s docs I found the following as the key fix:</p>
<p><a href="http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0bf64277-7ffd.html#WS2db454920e96a9e51e63e3d11c0bf69084-7d20" target="_blank">Using the ModuleManager class to load modules</a></p>
<blockquote><p>
You can use the ModuleManager class to load the module. This technique is less abstract than using the  tag, but it does provide you with greater control over how and when the module is loaded.</p>
<p>To use the ModuleManager to load a module in ActionScript:</p>
<ol>
<li>Get a reference to the module’s IModuleInfo interface by using the ModuleManager getModule() method.</li>
<li>Call the interface’s load() method.</li>
<p><strong><font color="#0000FF">The application that loads the module should pass in its moduleFactory property. This lets the module know who its parent style manager is.</font></strong> When using the load() method, you can specify the application’s moduleFactory with the fourth parameter, as the following example shows:</p>
<pre class="brush: as3;">info.load(null, null, null, moduleFactory);</pre>
<li>Use the factory property of the interface to call the create() method and cast the return value as the module’s class. If you are adding the module to a container, you can cast the return value as an IVisualElement (for Spark containers) or a DisplayObject (for MX containers) so that they can be added to the display list.</li>
</ol>
</blockquote>
<p>So the key is passing in a reference to the moduleFactory when calling the ModuleManager.load() method. The 4th parameter is the moduleManager. If you don&#8217;t have a reference the main app lying around, just use:</p>
<pre class="brush: as3;">info.load(null, null, null, FlexGlobals.topLevelApplication.moduleFactory);</pre>
<p><a href="http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0bf64277-7ffd.html#WS2db454920e96a9e51e63e3d11c0bf69084-7d20" target="_blank">Link to Adobe&#8217;s Docs on this.</a></p>
<p align="left"><a class="tt" href="http://twitter.com/home/?status=Flex+4+ModuleManager+%26+CSS+Inheriting+Styles+http://mizgd.th8.us" title="Post to Twitter"><img class="nothumb" src="http://www.webappsolution.com/wordpress/wp-content/plugins/tweet-this/icons/tt-twitter.png" alt="Post to Twitter" /></a> <a class="tt" href="http://twitter.com/home/?status=Flex+4+ModuleManager+%26+CSS+Inheriting+Styles+http://mizgd.th8.us" title="Post to Twitter">Tweet This Post</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.webappsolution.com/wordpress/2011/03/17/flex-4-modulemanager-css-inheriting-styles/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Great Ant Build Series for Flex</title>
		<link>http://www.webappsolution.com/wordpress/2011/02/23/great-ant-build-series-for-flex/</link>
		<comments>http://www.webappsolution.com/wordpress/2011/02/23/great-ant-build-series-for-flex/#comments</comments>
		<pubDate>Wed, 23 Feb 2011 13:54:54 +0000</pubDate>
		<dc:creator>brianr</dc:creator>
		
		<category><![CDATA[ant]]></category>

		<category><![CDATA[flex]]></category>

		<category><![CDATA[automated-builds]]></category>

		<category><![CDATA[build-tool]]></category>

		<category><![CDATA[maven]]></category>

		<guid isPermaLink="false">http://www.webappsolution.com/wordpress/?p=970</guid>
		<description><![CDATA[Many people have asked if we use Maven or Ant for Flex builds&#8230;while we like Maven for Java, we don&#8217;t like Maven for Flex. It&#8217;s not that we don&#8217;t like Maven in general (obviously since we&#8217;re cool with it for Java), we just found it&#8217;s almost too much trouble with Flex. It never fails to [...]]]></description>
			<content:encoded><![CDATA[<p>Many people have asked if we use <a href="http://maven.apache.org/" target="_blank">Maven</a> or <a href="http://ant.apache.org/" target="_blank">Ant</a> for Flex builds&#8230;while we like Maven for Java, we don&#8217;t like Maven for Flex. It&#8217;s not that we don&#8217;t like Maven in general (obviously since we&#8217;re cool with it for Java), we just found it&#8217;s almost too much trouble with Flex. It never fails to make us want to pull our hair out and say &#8220;Why bother?&#8221; &#8212; Yes, we have used <a href="http://flexmojos.sonatype.org/" target="_blank">FlexMojos</a> and we&#8217;re still not convinced. So we use Ant for Flex builds.</p>
<p>Instead of writing our own Ant build tutorial series for Flex, we&#8217;d like to push you to <a href="http://www.unitedmindset.com/jonbcampos/" target="_blank">Jon Campos</a>&#8217;s tutorials:</p>
<p>January 7th, 2010 - <a href="http://www.unitedmindset.com/jonbcampos/2010/01/07/using-ant-to-build-an-application/" target="_blank">Using ANT to build an Application</a><br />
January 14th, 2010 - <a href="http://www.unitedmindset.com/jonbcampos/2010/01/14/building-a-library-with-ant/" target="_blank">Building a Library with ANT</a><br />
January 19th, 2010 - <a href="http://www.unitedmindset.com/jonbcampos/2010/01/19/building-the-html-wrapper-with-ant/" target="_blank">Building the HTML Wrapper with ANT</a><br />
January 20th, 2010 - <a href="http://www.unitedmindset.com/jonbcampos/2010/01/20/building-a-custom-html-wrapper-with-ant/" target="_blank">Building a Custom HTML Wrapper with ANT</a><br />
January 21st, 2010 - <a href="http://www.unitedmindset.com/jonbcampos/2010/01/21/including-assets-files-with-ant/" target="_blank">Including Assets Files with ANT</a><br />
January 26th, 2010 - <a href="http://www.unitedmindset.com/jonbcampos/2010/01/26/building-a-library-and-application-with-ant/" target="_blank">Building a Library and Application with ANT</a><br />
January 28th, 2010 - <a href="http://www.unitedmindset.com/jonbcampos/2010/01/28/building-asdocs-with-ant/" target="_blank">Building ASDocs with ANT</a><br />
February 2nd, 2010 - <a href="http://www.unitedmindset.com/jonbcampos/2010/02/02/run-flex-unit-tests-from-ant/" target="_blank">Run Flex Unit Tests from ANT</a><br />
February 4th, 2010 - <a href="http://www.unitedmindset.com/jonbcampos/2010/02/04/run-flexmonkey-tests-from-ant/" target="_blank">Run FlexMonkey Tests from ANT</a><br />
February 9th, 2010 - <a href="http://www.unitedmindset.com/jonbcampos/2010/02/09/the-master-flex-ant-file/" target="_blank">The Master Flex ANT File</a></p>
<p>Thanks for an awesome series <a href="http://www.unitedmindset.com/jonbcampos/" target="_blank">Jon</a>.</p>
<p>As a side note, if someone can convince me that mvn + flex is better/easier than ant by all means ping me. <a href="mailto:brianr@webappsolution.com">brianr@webappsolution.com</a></p>
<p align="left"><a class="tt" href="http://twitter.com/home/?status=Great+Ant+Build+Series+for+Flex+http://xw42o.th8.us" title="Post to Twitter"><img class="nothumb" src="http://www.webappsolution.com/wordpress/wp-content/plugins/tweet-this/icons/tt-twitter.png" alt="Post to Twitter" /></a> <a class="tt" href="http://twitter.com/home/?status=Great+Ant+Build+Series+for+Flex+http://xw42o.th8.us" title="Post to Twitter">Tweet This Post</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.webappsolution.com/wordpress/2011/02/23/great-ant-build-series-for-flex/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Getting Spark &amp; MX Components to Use Embedded Fonts :: UPDATED**</title>
		<link>http://www.webappsolution.com/wordpress/2011/01/20/getting-spark-mx-components-to-use-embedded-fonts/</link>
		<comments>http://www.webappsolution.com/wordpress/2011/01/20/getting-spark-mx-components-to-use-embedded-fonts/#comments</comments>
		<pubDate>Thu, 20 Jan 2011 20:40:03 +0000</pubDate>
		<dc:creator>brianr</dc:creator>
		
		<category><![CDATA[actionscript]]></category>

		<category><![CDATA[flex]]></category>

		<category><![CDATA[css]]></category>

		<category><![CDATA[embedded-fonts]]></category>

		<category><![CDATA[halo]]></category>

		<category><![CDATA[mx]]></category>

		<category><![CDATA[spark]]></category>

		<category><![CDATA[style]]></category>

		<guid isPermaLink="false">http://www.webappsolution.com/wordpress/?p=956</guid>
		<description><![CDATA[You&#8217;d think embedding a font and declaring it as an Spark Application style would cascade down to all components &#8212; after all, CSS = Cascading Style Sheet, right? Well, it doesn&#8217;t. The font won&#8217;t show up in your MX components. 
After bumping our heads against this about 8-9 months ago we decided to move on&#8230;I [...]]]></description>
			<content:encoded><![CDATA[<p>You&#8217;d think embedding a font and declaring it as an Spark Application style would cascade down to all components &#8212; after all, CSS = Cascading Style Sheet, right? Well, it doesn&#8217;t. The font won&#8217;t show up in your MX components. </p>
<p>After bumping our heads against this about 8-9 months ago we decided to move on&#8230;I recently had to come back to it and found <a href="http://ria101.wordpress.com/2010/05/27/flex-font-embedding-with-spark-and-halo-made-easy/" target="_blank">this helpful link</a> that allowed me to do the following to get this working as expected.</p>
<p><strong>UPDATE*</strong>: Added style for MX DataGrid.</p>
<pre class="brush: as3;">
@namespace s &quot;library://ns.adobe.com/flex/spark&quot;;
@namespace mx &quot;library://ns.adobe.com/flex/mx&quot;;

@font-face
{
	src: url(&quot;/resources/fonts/Chalkboard.ttc&quot;);
	font-family: ChalkboardEmbedded;
	font-weight: normal;
	font-style: normal;
	embed-as-cff: true;
}

s|Application
{
	font-family: ChalkboardEmbedded;
	font-size: 12;
}

mx|global
{
	textFieldClass: ClassReference(&quot;mx.core.UIFTETextField&quot;);
}

mx|DataGrid
{
	defaultDataGridItemEditor: ClassReference(&quot;mx.controls.MXFTETextInput&quot;);
	defaultDataGridItemRenderer: ClassReference(&quot;mx.controls.dataGridClasses.FTEDataGridItemRenderer&quot;);
}
</pre>
<p><strong>The class-level global style is what does the trick</strong> as it instructs all MX components using text fields to use the UIFTETextField class &#8212; it allows MX or Halo components to leverage CFF embedded fonts.</p>
<p>Run the app with those styles defined and you&#8217;ll notice that one component still doesn&#8217;t want to listen &#8212; the title of the Spark Panel (or at least that&#8217;s the only component I&#8217;ve run across so far that doesn&#8217;t work).</p>
<p>I tried defining the style for the Spark Panel specifically, but no dice. I also tried creating a new skin for the Spark Panel and set the fontFamily property of the titleDisplay to my embedded font of ChalkboardEmbedded and that also failed. Anyone else come up with a solution for this?</p>
<p><strong>UPDATE*</strong>: This approach failed for the following MX classes:</p>
<ul>
<li>ProgressBar</li>
<li>FormHeading</li>
</ul>
<p>This approach failed for the following Spark classes:</p>
<ul>
<li>Panel</li>
</ul>
<p><strong>UPDATE*</strong>:I spoke to several Adobeans on the Flex Doc team and this is unfortunately a known issue:</p>
<blockquote><p>This approach works for most components, but not Panel and a couple others (he identified Panel and ProgressBar in his blog). I suspect he found a bug. This whole thing about using the same embedded font in MX and Spark components was meant to be a temporary solution until Spark had parity with MX controls. A year and a half later, and there&#8217;s still no parity, so there&#8217;s no surprise that users are running into this. </p>
<p>Brian, I would ask him to submit a bug. </p>
<p>He can take a look at the spec: <a href="http://opensource.adobe.com/wiki/display/flexsdk/Font+Embedding+Reprise" target="_blank">http://opensource.adobe.com/wiki/display/flexsdk/Font+Embedding+Reprise</a></p>
<p>That spec seems to indicate that Panel and ProgressBar should work the way it is documented.</p></blockquote>
<p align="left"><a class="tt" href="http://twitter.com/home/?status=Getting+Spark+%26+MX+Components+to+Use+Embedded+Fonts+%3A%3A+UPDATED%2A%2A+http://9m394.th8.us" title="Post to Twitter"><img class="nothumb" src="http://www.webappsolution.com/wordpress/wp-content/plugins/tweet-this/icons/tt-twitter.png" alt="Post to Twitter" /></a> <a class="tt" href="http://twitter.com/home/?status=Getting+Spark+%26+MX+Components+to+Use+Embedded+Fonts+%3A%3A+UPDATED%2A%2A+http://9m394.th8.us" title="Post to Twitter">Tweet This Post</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.webappsolution.com/wordpress/2011/01/20/getting-spark-mx-components-to-use-embedded-fonts/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Swiz EventHandler Filtering With Pub/Sub Topics - Part 2</title>
		<link>http://www.webappsolution.com/wordpress/2010/12/29/swiz-eventhandler-filtering-with-topics-part-2/</link>
		<comments>http://www.webappsolution.com/wordpress/2010/12/29/swiz-eventhandler-filtering-with-topics-part-2/#comments</comments>
		<pubDate>Wed, 29 Dec 2010 21:15:40 +0000</pubDate>
		<dc:creator>brianr</dc:creator>
		
		<category><![CDATA[flex]]></category>

		<category><![CDATA[swiz]]></category>

		<category><![CDATA[eventhandler]]></category>

		<category><![CDATA[metadata]]></category>

		<category><![CDATA[pub-sub-topics]]></category>

		<guid isPermaLink="false">http://www.webappsolution.com/wordpress/?p=946</guid>
		<description><![CDATA[After giving my first pass at this a little thought (which gives all of the details and explains how I got here) I realized the topic value defined in the EventHandler metadata tag was essentially hardcoded and set at compile time &#8212; this can work for some situations, but obviously isn&#8217;t ideal. I then decided [...]]]></description>
			<content:encoded><![CDATA[<p>After giving <a href="http://www.webappsolution.com/wordpress/2010/12/29/swiz-eventhandler-filtering-with-topics/" target="_blank">my first pass</a> at this a little thought (which gives all of the details and explains how I got here) I realized the topic value defined in the EventHandler metadata tag was essentially hardcoded and set at compile time &#8212; this can work for some situations, but obviously isn&#8217;t ideal. I then decided I needed a way to filter events in Swiz by topics with data and values set at runtime. The event dispatching is still the same:</p>
<pre class="brush: as3;">
/**
 * Allows this class to dispatch global events. Only methods using an
 * EventHandler metatadata tag with the property of scope=&quot;global&quot; can
 * handle this event. This means other modules and even the shell application
 * can handle this event if we want.
 *
 * &lt;p&gt;
 * The event dispatcher is injected by Swiz due to the [Dispatcher] metadata
 * and the class member's type of IEventDispatcher.
 * &lt;/p&gt;
 */
[Dispatcher(scope=&quot;global&quot;)]
public var globalDispatcher:IEventDispatcher;
...
public function sayHello():void
{
	logger.debug(&quot;sayHello&quot;);

	var appEvt:AppEvent;

	appEvt = new AppEvent(AppEvent.SAY_HELLO);
	appEvt.hello = &quot;Hello World!&quot;;
    appEvt.topic = &quot;wasiTopic&quot;;
	this.globalDispatcher.dispatchEvent(appEvt);
}
</pre>
<p>But the event handling is setup with a new, additional attribute called topicProperty. </p>
<pre class="brush: as3;">
public var myTopic:String = &quot;wasiTopic&quot;;
...
[EventHandler(event=&quot;AppEvent.SAY_HELLO&quot;, properties=&quot;hello&quot;, scope=&quot;global&quot;, topicProperty=&quot;myTopic&quot;)]
public function helloWithTopic(hello:String):void
{
	logger.debug(&quot;hello = &quot; + hello); // WORKS
}
</pre>
<p>This now allows the developer to set the member variable for the object doing the event handling at runtime. Internally in Swiz&#8217;s <code>org.swizframework.utils.event.EventHandler</code>&#8217;s method <code>public function handleEvent( event:Event ):void</code> we now look for the attribute &#8220;topic&#8221; and &#8220;topicProperty&#8221; in the EventHandler metadata. If the user has set the topicProperty, the method looks at the Bean that&#8217;s using EventHandler and inspects it for this String property and then compares it to the topic passed in the event. This requires some more changes to the Swiz class <code>org.swizframework.utils.event.EventHandler</code>.</p>
<p>Grab the changes I made to Swiz <a href="http://webappsolution.com/flex/blog/examples/swiz-eventhandling-with-topics.zip" target="_blank">here</a>.</p>
<p align="left"><a class="tt" href="http://twitter.com/home/?status=Swiz+EventHandler+Filtering+With+Pub%2FSub+Topics+-+Part+2+http://mcawd.th8.us" title="Post to Twitter"><img class="nothumb" src="http://www.webappsolution.com/wordpress/wp-content/plugins/tweet-this/icons/tt-twitter.png" alt="Post to Twitter" /></a> <a class="tt" href="http://twitter.com/home/?status=Swiz+EventHandler+Filtering+With+Pub%2FSub+Topics+-+Part+2+http://mcawd.th8.us" title="Post to Twitter">Tweet This Post</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.webappsolution.com/wordpress/2010/12/29/swiz-eventhandler-filtering-with-topics-part-2/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Swiz EventHandler Filtering With Pub/Sub Topics - Part 1</title>
		<link>http://www.webappsolution.com/wordpress/2010/12/29/swiz-eventhandler-filtering-with-topics/</link>
		<comments>http://www.webappsolution.com/wordpress/2010/12/29/swiz-eventhandler-filtering-with-topics/#comments</comments>
		<pubDate>Wed, 29 Dec 2010 18:47:22 +0000</pubDate>
		<dc:creator>brianr</dc:creator>
		
		<category><![CDATA[flex]]></category>

		<category><![CDATA[swiz]]></category>

		<category><![CDATA[tutorial]]></category>

		<category><![CDATA[eventhandler]]></category>

		<category><![CDATA[filtering]]></category>

		<category><![CDATA[metatadata]]></category>

		<category><![CDATA[pub-sub-topics]]></category>

		<guid isPermaLink="false">http://www.webappsolution.com/wordpress/?p=930</guid>
		<description><![CDATA[We tend to build many Flex applications with modules, so having the ability to broadcast and listen for messages based on the scope attribute for both Dispatchers and EventHandlers is essential in Swiz. 
UPDATE: Part 2 has Swiz framework code changes and a more robust solution.
If you don&#8217;t know about Swiz Event Scoping, then read [...]]]></description>
			<content:encoded><![CDATA[<p>We tend to build many Flex applications with modules, so having the ability to broadcast and listen for messages based on the <a href="http://swizframework.jira.com/wiki/display/SWIZ/Module+Support" target="_blank">scope attribute for both Dispatchers and EventHandlers is essential in Swiz</a>. </p>
<p>UPDATE: <a href="http://www.webappsolution.com/wordpress/2010/12/29/swiz-eventhandler-filtering-with-topics-part-2/" target="_blank">Part 2</a> has Swiz framework code changes and a more robust solution.</p>
<p>If you don&#8217;t know about Swiz Event Scoping, then read on; otherwise, skip to the section labeled <a href="#topics">Filtering With Topics below</a>.</p>
<p><strong>Background</strong></p>
<p>You can read the actual documentation from Swiz in the last link, but the gist is that you can tell Swiz to either broadcast events on a &#8220;global&#8221; level (using the highest level Application object) or on a &#8220;local&#8221; level (using the Module itself) and then listen to those events in the same fashion. This allows you to tell modules to listen to events only from themselves and not other modules (that might have the same events) or to listen to all events from your main, shell application and/or all other modules. Let&#8217;s look at a quick example by assuming the dispatching code is in LoginViewMediator and the handling code is in LoginController in a Module.</p>
<p><strong>Local Event Dispatching</strong></p>
<p>Local Event Dispatching From LoginViewMediator</p>
<pre class="brush: as3;">
/**
 * Allows this class to dispatch local events. Only methods using an
 * EventHandler metatadata tag with the property of scope=&quot;local&quot; can
 * handle this event.
 *
 * &lt;p&gt;
 * The event dispatcher is injected by Swiz due to the [Dispatcher] metadata
 * and the class member's type of IEventDispatcher.
 * &lt;/p&gt;
 */
[Dispatcher(scope=&quot;local&quot;)]
public var localDispatcher:IEventDispatcher;
...
public function login(userName:String, password:String):void
{
	logger.debug(&quot;login&quot;);

	var appEvt:AppEvent;

	appEvt = new AppEvent(AppEvent.SERVICE_LOGIN);
	appEvt.username = userName;
	appEvt.password = password;
	this.localDispatcher.dispatchEvent(appEvt);
}
</pre>
<p>Local Event Handling in LoginController</p>
<pre class="brush: as3;">
[EventHandler(event=&quot;AppEvent.SERVICE_LOGIN&quot;, properties=&quot;username, password&quot;, scope=&quot;local&quot;)]
public function login(username:String, password:String):void
{
	logger.debug(&quot;login: username = &quot; + username + &quot;, password = &quot; + password);
}
</pre>
<p>If we had other Modules with this same EventHandler statement in their LoginController they would not fire because we specified the scope as local. If we change the scope property to global and the AppEvent is in a common library that all Modules can use, then they would each hear this event and all fire, which in many cases is not what you want. Just so we have a full understanding of what&#8217;s going on, let&#8217;s show an example of broadcasting global events in a similar fashion:</p>
<p><strong>Global Event Dispatching</strong></p>
<p>Global Event Dispatching From ModuleA</p>
<pre class="brush: as3;">
/**
 * Allows this class to dispatch global events. Only methods using an
 * EventHandler metatadata tag with the property of scope=&quot;global&quot; can
 * handle this event. This means other modules and even the shell application
 * can handle this event if we want.
 *
 * &lt;p&gt;
 * The event dispatcher is injected by Swiz due to the [Dispatcher] metadata
 * and the class member's type of IEventDispatcher.
 * &lt;/p&gt;
 */
[Dispatcher(scope=&quot;global&quot;)]
public var globalDispatcher:IEventDispatcher;
...
public function sayHello():void
{
	logger.debug(&quot;sayHello&quot;);

	var appEvt:AppEvent;

	appEvt = new AppEvent(AppEvent.SAY_HELLO);
	appEvt.hello = &quot;Hello World!&quot;;
	this.globalDispatcher.dispatchEvent(appEvt);
}
</pre>
<p>Global Event Handling in Module B</p>
<pre class="brush: as3;">
[EventHandler(event=&quot;AppEvent.SAY_HELLO&quot;, properties=&quot;hello&quot;, scope=&quot;global&quot;)]
public function hello(hello:String):void
{
	logger.debug(&quot;hello = &quot; + hello);
}
</pre>
<p><a name="topics"><strong>Filtering With Topics</strong></a></p>
<p>Again, this is awesome&#8230;but what if you want to broadcast a message that you only want some of the modules to hear? You could obviously put in some simple logic in the event handler that determines if your Module was supposed to listen to the event based on a parameter passed in the EventHandler MetaData, but this could potentially become a large and unwieldy task that you&#8217;ll need to apply to all new modules&#8230;so what if we introduce filtering of Swiz events via a topic attribute in the EventHandler metadata and a corresponding topic property in our dispatched event?</p>
<p>To do this, we&#8217;ll need to do some quick monkey patching to Swiz (by creating the same package structure and adding the same classes we want to change that exist in the Swiz SWC). First, let&#8217;s add the topic property to the <code>org.swizframework.metadata.EventHandlerMetadataTag</code>. Add the topic property:</p>
<pre class="brush: as3;">
protected var _topic:String;
public function get topic():String
{
	return _topic;
}
</pre>
<p>Then add the following to the method <code>override public function copyFrom( metadataTag:IMetadataTag ):void</code></p>
<pre class="brush: as3;">
if( hasArg( &quot;topic&quot; ) )
    _topic = getArg( &quot;topic&quot; ).value;
</pre>
<p>Next we&#8217;ll edit the method <code>public function handleEvent( event:Event ):void</code> in <code>org.swizframework.utils.event.EventHandler</code>. Add the following right after the first if() statement:</p>
<pre class="brush: as3;">
// look for a topic -- if the one exists in the EventHandler MeataData and
// the event does not have one or the value does not equal the EventHandler's
// then we'll filter out this event and not allow it
if(metadataTag.topic != null)
{
	if(event[&quot;topic&quot;] == null)
	{
		return;
	}
	else if(event[&quot;topic&quot;] != metadataTag.topic)
	{
		return;
	}
}
</pre>
<p>That&#8217;s it. Let&#8217;s give it a whirl by using a global dispatcher again, but adding a topic property to the event and a topic attribute to the EventHandler metadata.</p>
<p>Global Event Dispatching From ModuleA</p>
<pre class="brush: as3;">
/**
 * Allows this class to dispatch global events. Only methods using an
 * EventHandler metatadata tag with the property of scope=&quot;global&quot; can
 * handle this event. This means other modules and even the shell application
 * can handle this event if we want.
 *
 * &lt;p&gt;
 * The event dispatcher is injected by Swiz due to the [Dispatcher] metadata
 * and the class member's type of IEventDispatcher.
 * &lt;/p&gt;
 */
[Dispatcher(scope=&quot;global&quot;)]
public var globalDispatcher:IEventDispatcher;
...
public function sayHello():void
{
	logger.debug(&quot;sayHello&quot;);

	var appEvt:AppEvent;

	appEvt = new AppEvent(AppEvent.SAY_HELLO);
	appEvt.hello = &quot;Hello World!&quot;;
        appEvt.topic = &quot;wasiTopic&quot;;
	this.globalDispatcher.dispatchEvent(appEvt);
}
</pre>
<p>Global Event Handling in Module B</p>
<pre class="brush: as3;">
[EventHandler(event=&quot;AppEvent.SAY_HELLO&quot;, properties=&quot;hello&quot;, scope=&quot;global&quot;, topic=&quot;wasiTopic&quot;)]
public function helloWithTopic(hello:String):void
{
	logger.debug(&quot;hello = &quot; + hello); // WORKS
}

[EventHandler(event=&quot;AppEvent.SAY_HELLO&quot;, properties=&quot;hello&quot;, scope=&quot;global&quot;)]
public function helloWithOutTopic(hello:String):void
{
	logger.debug(&quot;hello = &quot; + hello); // NOPE
}

[EventHandler(event=&quot;AppEvent.SAY_HELLO&quot;, properties=&quot;hello&quot;, scope=&quot;global&quot;, topic=&quot;fooTopic&quot;)]
public function helloWithOutTopic(hello:String):void
{
	logger.debug(&quot;hello = &quot; + hello); // NOPE
}
</pre>
<p>UPDATE: <a href="http://www.webappsolution.com/wordpress/2010/12/29/swiz-eventhandler-filtering-with-topics-part-2/" target="_blank">Part 2</a> has Swiz framework code changes and a more robust solution.</p>
<p align="left"><a class="tt" href="http://twitter.com/home/?status=Swiz+EventHandler+Filtering+With+Pub%2FSub+Topics+-+Part+1+http://wzsfn.th8.us" title="Post to Twitter"><img class="nothumb" src="http://www.webappsolution.com/wordpress/wp-content/plugins/tweet-this/icons/tt-twitter.png" alt="Post to Twitter" /></a> <a class="tt" href="http://twitter.com/home/?status=Swiz+EventHandler+Filtering+With+Pub%2FSub+Topics+-+Part+1+http://wzsfn.th8.us" title="Post to Twitter">Tweet This Post</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.webappsolution.com/wordpress/2010/12/29/swiz-eventhandler-filtering-with-topics/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Some Helpful Settings For Maven Builds</title>
		<link>http://www.webappsolution.com/wordpress/2010/12/20/some-helpful-settings-for-maven-builds/</link>
		<comments>http://www.webappsolution.com/wordpress/2010/12/20/some-helpful-settings-for-maven-builds/#comments</comments>
		<pubDate>Tue, 21 Dec 2010 02:36:57 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[actionscript]]></category>

		<category><![CDATA[air]]></category>

		<category><![CDATA[eclipse]]></category>

		<category><![CDATA[flash builder]]></category>

		<category><![CDATA[flex]]></category>

		<category><![CDATA[flex builder]]></category>

		<category><![CDATA[maven]]></category>

		<category><![CDATA[builder]]></category>

		<category><![CDATA[flash]]></category>

		<guid isPermaLink="false">http://www.webappsolution.com/wordpress/?p=924</guid>
		<description><![CDATA[When running Maven builds, there are typically a few settings that are useful to have in your ~/.bash_profile (for Mac or similar, depending on your shell) to help get things off on the right foot.
Set memory usage to 1024M minimum.
export MAVEN_OPTS=-Xmx1024m
Set the path to the appropriate SDK for Flash Builder
FLASH4_SDK=&#8217;/Applications/Adobe Flash Builder 4 Plug-in/sdks/3.5.0&#8242;
Set the [...]]]></description>
			<content:encoded><![CDATA[<p>When running Maven builds, there are typically a few settings that are useful to have in your ~/.bash_profile (for Mac or similar, depending on your shell) to help get things off on the right foot.</p>
<p>Set memory usage to 1024M minimum.<br />
<em>export MAVEN_OPTS=-Xmx1024m</em></p>
<p>Set the path to the appropriate SDK for Flash Builder<br />
<em>FLASH4_SDK=&#8217;/Applications/Adobe Flash Builder 4 Plug-in/sdks/3.5.0&#8242;</em></p>
<p>Set the path for ADL if building AIR applications<br />
<em>ADL_PATH=${FLASH4_SDK}/bin</em></p>
<p>Set the path to the Flash Player for launching FlexUnit tests<br />
<em>FLASH_PLAYER_PATH=&#8217;/Applications/Adobe Flash Builder 4 Plug-in/Player/mac/Flash Player.app/Contents/MacOS&#8217;</em></p>
<p>Append these to the current path<br />
<em>export PATH=${PATH}:${ADL_PATH}<br />
export PATH=${PATH}:${FLASH_PLAYER_PATH}</em></p>
<p align="left"><a class="tt" href="http://twitter.com/home/?status=Some+Helpful+Settings+For+Maven+Builds+http://58ikg.th8.us" title="Post to Twitter"><img class="nothumb" src="http://www.webappsolution.com/wordpress/wp-content/plugins/tweet-this/icons/tt-twitter.png" alt="Post to Twitter" /></a> <a class="tt" href="http://twitter.com/home/?status=Some+Helpful+Settings+For+Maven+Builds+http://58ikg.th8.us" title="Post to Twitter">Tweet This Post</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.webappsolution.com/wordpress/2010/12/20/some-helpful-settings-for-maven-builds/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Substitution Tokens in Resource Bundle Strings in Flex</title>
		<link>http://www.webappsolution.com/wordpress/2010/12/09/substitution-tokens-in-resource-bundle-strings-in-flex/</link>
		<comments>http://www.webappsolution.com/wordpress/2010/12/09/substitution-tokens-in-resource-bundle-strings-in-flex/#comments</comments>
		<pubDate>Thu, 09 Dec 2010 20:04:19 +0000</pubDate>
		<dc:creator>brianr</dc:creator>
		
		<category><![CDATA[flex]]></category>

		<category><![CDATA[resource bundle]]></category>

		<category><![CDATA[locale]]></category>

		<category><![CDATA[localization]]></category>

		<category><![CDATA[resource-manager]]></category>

		<category><![CDATA[string]]></category>

		<category><![CDATA[substitution]]></category>

		<category><![CDATA[tokens]]></category>

		<guid isPermaLink="false">http://www.webappsolution.com/wordpress/?p=917</guid>
		<description><![CDATA[There&#8217;s many times where you want to use a Resource Bundle String in-conjunction with variable data. People often breakup the RB String into 2 pieces like so:
part1=My name is
part2=and I like
And then put it back together in AS like:

var part1:String = ResourceManager.getInstance().getString('Labels', 'part1');
var name:String = &#34;Brian Riley&#34;;
var part2:String = ResourceManager.getInstance().getString('Labels', 'part2');
var likes:String = &#34;beer.&#34;;

var myStr:String [...]]]></description>
			<content:encoded><![CDATA[<p>There&#8217;s many times where you want to use a Resource Bundle String in-conjunction with variable data. People often breakup the RB String into 2 pieces like so:</p>
<p>part1=My name is<br />
part2=and I like</p>
<p>And then put it back together in AS like:</p>
<pre class="brush: as3;">
var part1:String = ResourceManager.getInstance().getString('Labels', 'part1');
var name:String = &quot;Brian Riley&quot;;
var part2:String = ResourceManager.getInstance().getString('Labels', 'part2');
var likes:String = &quot;beer.&quot;;

var myStr:String = part1 + &quot; &quot; + name + &quot; &quot; + part2 + &quot; &quot; + likes;
</pre>
<p>Which works, but it&#8217;s a lot of unnecessary code. Take advantage of the tokens allowed in RBs and do the following:</p>
<p>likes=My name is {0} and I like {1}</p>
<pre class="brush: as3;">
var likes:String = ResourceManager.getInstance().getString('Labels', 'likes', [&quot;Brian Riley&quot;, &quot;beer.&quot;]);
</pre>
<p>The ResourceManager class will automatically substitue the tokens {0} and {1} in order and replace them with the array of strings provided as the last param in the getString() method.</p>
<p>Much simpler, right?</p>
<p align="left"><a class="tt" href="http://twitter.com/home/?status=Substitution+Tokens+in+Resource+Bundle+Strings+in+Flex+http://m9idg.th8.us" title="Post to Twitter"><img class="nothumb" src="http://www.webappsolution.com/wordpress/wp-content/plugins/tweet-this/icons/tt-twitter.png" alt="Post to Twitter" /></a> <a class="tt" href="http://twitter.com/home/?status=Substitution+Tokens+in+Resource+Bundle+Strings+in+Flex+http://m9idg.th8.us" title="Post to Twitter">Tweet This Post</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.webappsolution.com/wordpress/2010/12/09/substitution-tokens-in-resource-bundle-strings-in-flex/feed/</wfw:commentRss>
		</item>
		<item>
		<title>RemoteObject ActionScript &amp; Java Serialization Tips</title>
		<link>http://www.webappsolution.com/wordpress/2010/12/01/remoteobject-actionscript-java-serialization-tips/</link>
		<comments>http://www.webappsolution.com/wordpress/2010/12/01/remoteobject-actionscript-java-serialization-tips/#comments</comments>
		<pubDate>Wed, 01 Dec 2010 13:13:11 +0000</pubDate>
		<dc:creator>brianr</dc:creator>
		
		<category><![CDATA[actionscript]]></category>

		<category><![CDATA[blazeds]]></category>

		<category><![CDATA[flex]]></category>

		<category><![CDATA[java]]></category>

		<category><![CDATA[remote-object]]></category>

		<category><![CDATA[remoteclass-metadata]]></category>

		<category><![CDATA[serialization]]></category>

		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://www.webappsolution.com/wordpress/?p=891</guid>
		<description><![CDATA[When working with RemoteObjects (ROs) in the Flash Player via a server-side library like BlazeDS, LCDS, or WebORB, there are several simple stumbling blocks that often lead to the case where you receive back untyped, generic ActionScript (AS) Object objects as opposed to the mapping you set up between your AS objects and your Java [...]]]></description>
			<content:encoded><![CDATA[<p>When working with <a href="http://livedocs.adobe.com/flex/3/html/help.html?content=data_access_4.html" target="_blank">RemoteObjects</a> (ROs) in the Flash Player via a server-side library like <a href="http://opensource.adobe.com/wiki/display/blazeds/BlazeDS" target="_blank">BlazeDS</a>, <a href="http://www.adobe.com/products/livecycle/dataservices/" target="_blank">LCDS</a>, or <a href="http://www.themidnightcoders.com/products.html" target="_blank">WebORB</a>, there are several simple stumbling blocks that often lead to the case where you receive back untyped, generic ActionScript (AS) Object objects as opposed to the mapping you set up between your AS objects and your Java objects. I&#8217;ll note the most common issues quickly and move on to provide additional explanation where necessary.</p>
<p><strong>Common Issues</strong></p>
<ul>
<li>Incorrect spelling / mapping of Java class in RemoteClass metadata in AS object: <em>[RemoteClass(alias="fullyQualifiedJavaClass")]</em></li>
<li>Incorrect spelling / capitalization of properties.</li>
<li>Not providing empty constructors in Java object.</li>
<li>Not using formal getter / setters methods for properties in Java object.</li>
<li>AS mapped object not compiled into the SWF. This happens when using ArrayCollections and the item isn&#8217;t referenced anywhere in the application and thus not compiled into the SWF.</li>
</ul>
<p><strong>Nonexistent or Incorrect ActionScript Mapping</strong><br />
In order to tell the Flash Player to serialize your Java <a href="http://martinfowler.com/eaaCatalog/dataTransferObject.html" target="_blank">Data Transfer Objects</a> (DTOs) to your explicit AS objects you&#8217;ll need to make sure you include the all important [RemoteClass(alias="fully qualified Java class we're mapping to")] metadata.</p>
<p>The most common culprit here is usually a simple misspelling of the fully qualified Java object in your RemoteClass metadata, but here&#8217;s a list of other common things to note before we look at an example:</p>
<p><strong>REQUIRED:</strong></p>
<ul>
<li>You must include the metadata <em>[RemoteClass(alias="fullyQualifiedJavaClass")]</em>. Make sure the name of Java object is the fully qualified name.</li>
<li>The properties you want to map must be public.</li>
<li>The properties you want to map must be spelled and capitalized exactly the same as they appear in your Java class.</li>
<li>If your Java object extends another object and you want the properties in the super class also mapped to your AS object, you must either a) create that class in AS and map it to the base Java object or b) add those properties directly into your AS object.</li>
<li>If your AS object contains complex objects that exist in the Java side and you want that object mapped correctly you&#8217;ll need to create that class in AS and map its corresponding Java object.</li>
<li>If your AS object contains an Array or ArrayCollection that will be populated with objects you expect to be mapped, you&#8217;ll need to a) ensure the corresponding AS object is mapped and b) is compiled into the application. A simple trick to ensure that your AS object is compiled into the app is to declare ArrayCollections like so: <em>public var foos:ArrayCollection = new ArrayCollection();Foo;</em> This also helps you and other developers see what kind of AS object is expected in the list like a Java generic. The compiler and player obviously won&#8217;t throw errors or complain if the objects aren&#8217;t of that type, but from a readability perspective it&#8217;s quite helpful.</li>
</ul>
<p><strong>OPTIONAL/MISNOMER</strong></p>
<ul>
<li>You can specify your public properties as either regular, old public properties or using the getter and setter functions.</li>
<li>The package of your AS object does not need to match the package of your Java object. The aforementioned RemoteClass metadata takes care of that for you.</li>
<li>You do not need a constructor in your AS object.</li>
<li>You can have extra, non-mapped properties in your AS object.</li>
<li>You do not need to implement the same interface as your Java object. In fact, you can use additional, client-side only interfaces to extend your AS object and it will not effect the mapping.</li>
<li>You do not need to annotate the class with the [Bindable] metadata. It&#8217;s often the case where it is because you&#8217;re using the object as a doman/model/vo on the client and want other things to bind to it, but it&#8217;s not required.</li>
<li>You can have methods in your AS obj that do not map to methods in your Java object.</li>
</ul>
<pre class="brush: as3;">
package com.webappsolution.myapp.model
{
	[RemoteClass(alias=&quot;com.webappsolution.myapp.dto.PersonDTO&quot;)]
	public class PersonModel extends FooModel implements IUniqueItem
	{
		public function PersonModel()
		{
			super();
		}

		// mapping using getter ans setter functions for public properties
		// also implements IUniqueItem interface
		private var _id:String;
		public function get id():String
		{
			return _id;
		}
		public function set id(value:String):void
		{
			_id = value;
		}

		public var age:int = 0;
		public var firstName:String = &quot;&quot;;
		public var lastName:String = &quot;&quot;;
		public var birthDate:Date = new Date();
		public var isBeerDrinker:Boolean = true;
		public var complexObject:ComplexObject = new ComplexObject();

		// put in the references to the types of items we exopect in the collection
		// to ensure that they are compiled into the swf. this also provides a
		// nice readability clue as well to other developers.
		public var foos:ArrayCollection = new ArrayCollection();Foo;

		// not mapped
		public var isDisabled:Boolean;
		protected var uid:int;

		// not mapped
		public function getFullName():String
		{
			return this.firstName + &quot; &quot; + this.lastName;
		}

	}
}
</pre>
<p><strong>Java Object Issues</strong><br />
There&#8217;s a couple quick gotchas here that should be noted when creating Java objects that you wish to map to AS objects, as many of the important issues are covered above in the AS section &#8212; I&#8217;ll list these quickly followed by a small example.</p>
<p><strong>REQUIRED:</strong></p>
<ul>
<li>You must provide an empty constructor.</li>
<li>You must use formal getters and setters for your properties. You cannot just list out public properties in Java like we do in AS.</li>
</ul>
<p><strong>OPTIONAL:</strong></p>
<ul>
<li>While an empty constructor is required, it&#8217;s ok to override it and provide multiple constructors as well.</li>
<li>You can have extra, non-mapped properties in your Java object.</li>
<li>You can implement interfaces in your Java object that do not exist in your AS object.</li>
<li>Considering using the <a href="http://martinfowler.com/eaaCatalog/dataTransferObject.html" target="_blank">DTO pattern</a> on the Java side to pass objects across the wire as opposed to allowing AS objects to map to domain/entity objects in your Java tier. This can be especially important when using domain/entity objects that are mapped to a database via Hibernate &#8212; there are lazy loading issues here that can cause less than fully populated object graphs to come across the wire to your Flex app. Instead, put a service layer in front of your domain object layer that returns DTOs.</li>
</ul>
<pre class="brush: java;">
package com.webappsolution.myapp.dto;

import ...

public class PersonDTO implements IStuff
{
	private String id;
	private int age;
	private String firstName;
	private String lastName;
	private Date birthDate;
	private boolean isBeerDrinker;
	private ComplexObject complexObject;

	public PersonDTO()
	{
	}
	public PersonDTO(String fName, String lName)
	{
		this.firstName = fName;
		this.lastName = lName;
	}
	public PersonDTO(String fName, String lName, int age)
	{
		this.firstName = fName;
		this.lastName = lName;
		this.age = age;
	}

	public long getId()
	{
		return id;
	}

	public void setId(long id)
	{
		this.id = id;
	}

	public String getFirstName()
	{
		return firstName;
	}

	public void setFirstName(String firstName)
	{
		this.firstName = firstName;
	}

	public String getLastName()
	{
		return lastName;
	}

	public void setLastName(String lastName)
	{
		this.lastName = lastName;
	}

	// omitting the rest of the public getters / setters for brevity, but you'd
	// need one for each property you want to map
}
</pre>
<p>For more information on RemoteObjects, please visit the Adobe Flex documentation:<a href="http://help.adobe.com/en_US/Flex/4.0/AccessingData/WS2db454920e96a9e51e63e3d11c0bf69084-7fda.html" target="_blank"> Using RemoteObject components </a></p>
<p align="left"><a class="tt" href="http://twitter.com/home/?status=RemoteObject+ActionScript+%26+Java+Serialization+Tips+http://zyfgo.th8.us" title="Post to Twitter"><img class="nothumb" src="http://www.webappsolution.com/wordpress/wp-content/plugins/tweet-this/icons/tt-twitter.png" alt="Post to Twitter" /></a> <a class="tt" href="http://twitter.com/home/?status=RemoteObject+ActionScript+%26+Java+Serialization+Tips+http://zyfgo.th8.us" title="Post to Twitter">Tweet This Post</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.webappsolution.com/wordpress/2010/12/01/remoteobject-actionscript-java-serialization-tips/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Flex &amp; ActionScript Regex List</title>
		<link>http://www.webappsolution.com/wordpress/2010/09/01/actionscript-regex-list/</link>
		<comments>http://www.webappsolution.com/wordpress/2010/09/01/actionscript-regex-list/#comments</comments>
		<pubDate>Wed, 01 Sep 2010 12:53:11 +0000</pubDate>
		<dc:creator>brianr</dc:creator>
		
		<category><![CDATA[actionscript]]></category>

		<category><![CDATA[flex]]></category>

		<category><![CDATA[regex]]></category>

		<category><![CDATA[tutorial]]></category>

		<category><![CDATA[code]]></category>

		<guid isPermaLink="false">http://www.webappsolution.com/wordpress/?p=840</guid>
		<description><![CDATA[I&#8217;m not great with regex since I don&#8217;t use it a ton so I constantly find myself looking up simple, reusable regex statements&#8230;thought I&#8217;d just start listing them as I use them in case someone else finds them useful. This will start with just a couple examples that we&#8217;ll continue to add to.
Assume the following [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m not great with regex since I don&#8217;t use it a ton so I constantly find myself looking up simple, reusable regex statements&#8230;thought I&#8217;d just start listing them as I use them in case someone else finds them useful. This will start with just a couple examples that we&#8217;ll continue to add to.</p>
<p>Assume the following vars:</p>
<pre class="brush: as3;">
var myString:String;
var pattern:RegExp;
var resultString:String;
var isSuccess:Boolean;
</pre>
<p><strong>Remove All Spaces</strong></p>
<pre class="brush: as3;">
myString = &quot;The quick brown fox.&quot;;
pattern = /\s+/g;
resultString = myString.replace(pattern, &quot;&quot;);
trace(resultString); // Thequickbrownfox.
</pre>
<p><strong>Remove Special Characters &#038; Spaces</strong></p>
<pre class="brush: as3;">
myString = &quot;The 123 quick 456 brown !@#$% fox.&quot;;
pattern = /\W/g;
resultString = myString.replace(pattern, &quot;&quot;);
trace(resultString); // The123quick456brownfox
</pre>
<p><strong>Remove Special Characters &#038; Numbers &#038; Spaces</strong></p>
<pre class="brush: as3;">
myString = &quot;The 123 quick 456 brown !@#$% fox.&quot;;
pattern = /[^a-zA-Z]+/g;
resultString = myString.replace(pattern, &quot;&quot;);
trace(resultString); // Thequickbrownfox
</pre>
<p><strong>Test URL String</strong></p>
<pre class="brush: as3;">
myString = &quot;http://yahoo.com&quot;;
pattern = /^http(s)?:\/\/((\d+\.\d+\.\d+\.\d+)|(([\w-]+\.)+([a-z,A-Z][\w-]*)))(:[1-9][0-9]*)?(\/([\w-.\/:%+@&amp;=]+[\w- .\/?:%+@&amp;=]*)?)?(#(.*))?$/i;
isSuccess = pattern.test(myString);
trace(isSuccess); // true
myString = &quot;htt://yahoo.com&quot;;
isSuccess = pattern.test(myString);
trace(isSuccess); // false
</pre>
<p><strong>Trim String (With Tabs &#038; Returns): Courtesy of <a href="http://jeffchannell.com/ActionScript-3/as3-trim.html" target="_blank">Jeff Channel</a></strong></p>
<pre class="brush: as3;">
myString = myString = &quot;The quick brown fox.                   		&quot;;
pattern = /^\s+|\s+$/gs;
resultString = myString.replace(pattern, &quot;&quot;);
trace(resultString); // &quot;The quick brown fox.&quot;
</pre>
<p align="left"><a class="tt" href="http://twitter.com/home/?status=Flex+%26+ActionScript+Regex+List+http://ciya4.th8.us" title="Post to Twitter"><img class="nothumb" src="http://www.webappsolution.com/wordpress/wp-content/plugins/tweet-this/icons/tt-twitter.png" alt="Post to Twitter" /></a> <a class="tt" href="http://twitter.com/home/?status=Flex+%26+ActionScript+Regex+List+http://ciya4.th8.us" title="Post to Twitter">Tweet This Post</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.webappsolution.com/wordpress/2010/09/01/actionscript-regex-list/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Set Flex to Focus on Application Load</title>
		<link>http://www.webappsolution.com/wordpress/2010/08/31/set-flex-to-focus-on-application-load/</link>
		<comments>http://www.webappsolution.com/wordpress/2010/08/31/set-flex-to-focus-on-application-load/#comments</comments>
		<pubDate>Tue, 31 Aug 2010 20:49:24 +0000</pubDate>
		<dc:creator>brianr</dc:creator>
		
		<category><![CDATA[flex]]></category>

		<category><![CDATA[tutorial]]></category>

		<category><![CDATA[browser]]></category>

		<category><![CDATA[chrome]]></category>

		<category><![CDATA[code]]></category>

		<category><![CDATA[focus]]></category>

		<category><![CDATA[issue]]></category>

		<category><![CDATA[safari]]></category>

		<guid isPermaLink="false">http://www.webappsolution.com/wordpress/?p=834</guid>
		<description><![CDATA[By default a Flex application is not in focus in the browser when it loads. This can be especially frustrating if you have say a login view and would like the username field to be in focus when the application starts cranking. However, with some simple JavaScript we can set the Flash object to focus [...]]]></description>
			<content:encoded><![CDATA[<p>By default a Flex application is not in focus in the browser when it loads. This can be especially frustrating if you have say a login view and would like the username field to be in focus when the application starts cranking. However, with some simple JavaScript we can set the Flash object to focus when the application loads.</p>
<p><strong>NOTE</strong>: This will not work in Safari, Chrome, or any other browser that leverages <a href="http://www.google.com/url?sa=t&amp;source=web&amp;cd=1&amp;ved=0CBkQFjAA&amp;url=http%3A%2F%2Fwebkit.org%2F&amp;ei=c2N9TO7lM4SglAeIpNDsCw&amp;usg=AFQjCNEGJ7R9gMF3znWbtSquGFEELChj0g&amp;sig2=tw8sF2Y2JEcIHkzB8TvNAg" target="_blank">Webkit</a>, as it doesn&#8217;t allow the focus to be set on embedded objects. If you&#8217;re targeting IE and Firefox the proposed solution below will work.</p>
<p>For example purposes, let&#8217;s assume we want to make our username TextInput field have focus when the Flex app starts rocking.</p>
<p>First, set the focus to the username field &#8212; assume a ViewMediator is doing this:</p>
<pre class="brush: as3;">
this.view.userNameTextInput.setFocus();
</pre>
<p>Create a simple JavaScript method to set the focus of the browser to your Flex application. Create this method in the index.template.html file in your Flex project &#8212; just drop it right before the closing HTML </body> tag at the bottom of the file:</p>
<pre class="brush: js;">
&lt;script type=&quot;text/javascript&quot;&gt;
function onFlexInitialized()
{
	//alert(&quot;onFlexInitialized&quot;);

	&lt;!-- Force the browser to set flex app with focus --&gt;
	document.getElementById(&quot;${application}&quot;).focus();
}
&lt;/script&gt;
</pre>
<p>Next catch the application complete event and call the JS method we just created &#8212; I put in how to remove the event handler for the app complete for both Flex 3 and 4:</p>
<pre class="brush: as3;">
/**
 * Constructor.
 */
public function AppController()
{
	FlexGlobals.topLevelApplication.addEventListener(FlexEvent.APPLICATION_COMPLETE, onAppComplete); // Flex 4
        //Application.application.addEventListener(FlexEvent.APPLICATION_COMPLETE, onAppComplete); // Flex 3
}

/**
 * Handles the application complete event.
 */
protected function onAppComplete(e:FlexEvent):void
{
	FlexGlobals.topLevelApplication.removeEventListener(FlexEvent.APPLICATION_COMPLETE, onAppComplete); // Flex 4
        //Application.application.removeEventListener(FlexEvent.APPLICATION_COMPLETE, onAppComplete); // Flex 3

	if(ExternalInterface.available)
	{
		ExternalInterface.call(&quot;onFlexInitialized&quot;);
	}
}
</pre>
<p>And that&#8217;s it. Again, it doesn&#8217;t work in Safari and Chrome. Here are the 2 defects logged for each brower&#8217;s bug-base respectively: <a href="http://code.google.com/p/chromium/issues/detail?id=27868" target="_blank">Chrome</a>, <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=93149" target="_blank">Safari</a>.</p>
<p align="left"><a class="tt" href="http://twitter.com/home/?status=Set+Flex+to+Focus+on+Application+Load+http://5ttiw.th8.us" title="Post to Twitter"><img class="nothumb" src="http://www.webappsolution.com/wordpress/wp-content/plugins/tweet-this/icons/tt-twitter.png" alt="Post to Twitter" /></a> <a class="tt" href="http://twitter.com/home/?status=Set+Flex+to+Focus+on+Application+Load+http://5ttiw.th8.us" title="Post to Twitter">Tweet This Post</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.webappsolution.com/wordpress/2010/08/31/set-flex-to-focus-on-application-load/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Unable to export SWC oem</title>
		<link>http://www.webappsolution.com/wordpress/2010/04/07/unable-to-export-swc-oem/</link>
		<comments>http://www.webappsolution.com/wordpress/2010/04/07/unable-to-export-swc-oem/#comments</comments>
		<pubDate>Wed, 07 Apr 2010 19:35:12 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[actionscript]]></category>

		<category><![CDATA[flash builder]]></category>

		<category><![CDATA[flex]]></category>

		<category><![CDATA[flash]]></category>

		<category><![CDATA[flex builder]]></category>

		<guid isPermaLink="false">http://www.webappsolution.com/wordpress/?p=763</guid>
		<description><![CDATA[Been switching environments a bit lately from Flash Builder to Flex Builder and back and using different SDKs.
When importing a new project that someone had checked in from a different version, the .flexLibProperties file was causing this issue.
After much scouring, I found something that worked.
Open .flexLibProperties and find the section &#60;includeResource/&#62;. Remove everything in that [...]]]></description>
			<content:encoded><![CDATA[<p>Been switching environments a bit lately from Flash Builder to Flex Builder and back and using different SDKs.</p>
<p>When importing a new project that someone had checked in from a different version, the .flexLibProperties file was causing this issue.</p>
<p>After much scouring, I found something that worked.</p>
<p>Open .flexLibProperties and find the section &lt;includeResource/&gt;. Remove everything in that section.</p>
<p>Made the problem disappear.</p>
<p align="left"><a class="tt" href="http://twitter.com/home/?status=Unable+to+export+SWC+oem+http://9x7if.th8.us" title="Post to Twitter"><img class="nothumb" src="http://www.webappsolution.com/wordpress/wp-content/plugins/tweet-this/icons/tt-twitter.png" alt="Post to Twitter" /></a> <a class="tt" href="http://twitter.com/home/?status=Unable+to+export+SWC+oem+http://9x7if.th8.us" title="Post to Twitter">Tweet This Post</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.webappsolution.com/wordpress/2010/04/07/unable-to-export-swc-oem/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>

