<?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>hubflanger &#187; JSFL</title>
	<atom:link href="http://hubflanger.com/tag/jsfl/feed/" rel="self" type="application/rss+xml" />
	<link>http://hubflanger.com</link>
	<description>adventures in code</description>
	<lastBuildDate>Mon, 29 Mar 2010 22:41:12 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<atom:link rel='hub' href='http://hubflanger.com/?pushpress=hub'/>
		<item>
		<title>Building Flash Projects with Ant and Flex Builder – Part 5</title>
		<link>http://hubflanger.com/building-flash-projects-with-ant-and-flex-builder-part-5/</link>
		<comments>http://hubflanger.com/building-flash-projects-with-ant-and-flex-builder-part-5/#comments</comments>
		<pubDate>Fri, 27 Nov 2009 00:24:10 +0000</pubDate>
		<dc:creator>Peng</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Ant]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Flex Builder]]></category>
		<category><![CDATA[JSFL]]></category>

		<guid isPermaLink="false">http://hubflanger.com/?p=287</guid>
		<description><![CDATA[In this final installment of my series of tutorials on using Ant with Flex Builder, I&#8217;ll show you how to create a Preloader asset in the Flash IDE and export that as a SWC to be used in your Actionscript source code.
1. Download tutorial files
To begin this tutorial, please make sure you have set up [...]]]></description>
			<content:encoded><![CDATA[<p>In this final installment of my series of tutorials on using Ant with Flex Builder, I&#8217;ll show you how to create a Preloader asset in the Flash IDE and export that as a SWC to be used in your Actionscript source code.</p>
<h3>1. Download tutorial files</h3>
<p>To begin this tutorial, please make sure you have set up your workspace as suggested in <a href="/building-flash-projects-with-ant-and-flex-builder-part-1/#settingUpYourWorkspace">Part 1</a>.</p>
<p><a href="/demos/ant_demo5/">View Demo</a></p>
<p><a href="http://github.com/hubflanger/AS3_Ant_Tutorial_5">Download Source Files</a></p>
<p><span id="more-287"></span></p>
<h3>2. Examine preloaderAsset.fla</h3>
<p>The <code>preloaderAsset.fla</code> has in its library a movieclip symbol named <code>preloader</code>, linked to a class <code>PreloaderAsset</code>. Note that there is no physical Actionscript file named &#8220;PreloaderAsset.as&#8221;. This class will be created by the Flash compiler when we run the <code>compilePreloaderSWC</code> JSFL script. </p>
<h3>3. Examine the compilePreloaderSWC JSFL</h3>
<p>This script retrieves the <code>preloader</code> library symbol and exports it as a SWC to a designated location in your file system. Update the path for <code>libs/PreloaderAsset.swc</code> to reference your project directory.</p>
<div class="codeblock">
<pre>
fl.getDocumentDOM().library.selectItem("preloader", true, true);
var currentSelection = fl.getDocumentDOM().library.getSelectedItems();
currentSelection[0].exportSWC("file:///Users/peng/Workspace/FlexBuilder/Hubflanger/AS3_Ant_Tutorial_5/libs/PreloaderAsset.swc");
</pre>
</div>
<h3>4. Examine the compilePreloaderSWC Task</h3>
<p>The <code>compilePreloaderSWC</code> task invokes the <code>compilePreloaderSWC.jsfl</code> script and compiles a SWC named <code>PreloaderAsset.swc</code> into the <code>libs</code> folder of your project directory using the Flash IDE.</p>
<div class="codeblock">
<pre>
&lt;target name="compilePreloaderSWC" description="Compile the Preloader SWC with the Flash IDE"&gt;
  &lt;echo&gt;Flash IDE Compiler for file ${preloaderFLA}&lt;/echo&gt;
  &lt;echo message="|*|*|*| class cache clear | source save | compiler start |*|*|*|"/&gt;
  &lt;exec executable="open"&gt;
    &lt;arg line="${compilePreloaderSWC_jsfl} ${preloaderFLA}"/&gt;
  &lt;/exec&gt;
&lt;/target&gt;
</pre>
</div>
<h3>5. Examine Preloader.as</h3>
<p>Add the SWC into your classpath using the project&#8217;s <code>Properties->Actionscript Build Path->Library Path</code> panel. With the SWC added to the library path, the <code>Preloader</code> class can now reference the <code>PreloaderAsset</code> class and create an instance of the <code>PreloaderAsset</code> object. This allows you to add the visual asset into your <code>Preloader</code> display container. The <code>Preloader</code> class also provides functionality to update the properties of the <code>PreloaderAsset</code> instance.</p>
<div class="codeblock">
<pre>
package
{
  import flash.display.*;
  import flash.events.*;
  import flash.text.*;

  public class Preloader extends Sprite
  {
    private var _asset:PreloaderAsset;

    public function Preloader()
    {
      _asset = new PreloaderAsset();
      addChild( _asset );
    }

    public function updateProgress( bytesLoaded:uint, bytesTotal:uint ):void
    {
      var ratio:Number = bytesLoaded / bytesTotal;
      _asset.bar.scaleX = ratio;
      _asset.progessTxt.text = bytesLoaded + " kb / " + bytesTotal + " kb";
    }
  }
}
</pre>
</div>
<h3>6. Examine Demo5.as</h3>
<p>The document class <code>Demo5</code> creates a <code>Preloader</code> instance and a <code>Loader</code> instance to load an external SWF. It responds to load progress events from the <code>Loader</code> by and calling the  <code>updateProgress()</code> method of the <code>Preloader</code> instance.</p>
<div class="codeblock">
<pre>
package
{
  import flash.net.URLRequest;
  import flash.display.*;
  import flash.events.*;

  import Preloader;

  public class Demo5 extends Sprite
  {
    private var preloader:Preloader;
    private var loader:Loader;

    public function Demo5()
    {
      preloader = new Preloader();
      preloader.x = 150;
      preloader.y = 150;
      addChild( preloader );

      loader = new Loader();
      loader.contentLoaderInfo.addEventListener( Event.COMPLETE, loadCompleteHandler );
      loader.contentLoaderInfo.addEventListener( ProgressEvent.PROGRESS, loadProgressHandler );
      loader.load( new URLRequest( "externalAssets.swf" ));
    }

    private function loadProgressHandler( evt:ProgressEvent ):void
    {
      preloader.updateProgress( evt.bytesLoaded, evt.bytesTotal );
    }

    private function loadCompleteHandler( evt:Event ):void
    {
      removeChild( preloader );
      evt.target.removeEventListener( Event.COMPLETE, loadCompleteHandler );
      evt.target.removeEventListener( ProgressEvent.PROGRESS, loadProgressHandler );
      addChild( loader );
    }
  }
}
</pre>
</div>
<h3>7. Wrapping it all up</h3>
<p>The <code>compileMain</code> task includes the <code>PreloaderAsset.swc</code> by adding it to the compiler&#8217;s <code>library-path</code> option. This option will merge all classes embedded in the SWC into your SWF.</p>
<div class="codeblock">
<pre>
&lt;compiler .library-path dir="${LIB_DIR}" append="true"&gt;
  &lt;include name="PreloaderAsset.swc" /&gt;
&lt;/compiler&gt;
</pre>
</div>
<p>I hope you&#8217;ve found this series of tutorial helpful in optimizing your Flash-Actionscript development workflow. Please leave any  requests and suggestions in the comments.</p>
]]></content:encoded>
			<wfw:commentRss>http://hubflanger.com/building-flash-projects-with-ant-and-flex-builder-part-5/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Building Flash Projects with Ant and Flex Builder – Part 4b</title>
		<link>http://hubflanger.com/building-flash-projects-with-ant-and-flex-builder-part-4b/</link>
		<comments>http://hubflanger.com/building-flash-projects-with-ant-and-flex-builder-part-4b/#comments</comments>
		<pubDate>Mon, 03 Aug 2009 04:52:34 +0000</pubDate>
		<dc:creator>Peng</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Ant]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Flex Builder]]></category>
		<category><![CDATA[JSFL]]></category>

		<guid isPermaLink="false">http://hubflanger.com/?p=251</guid>
		<description><![CDATA[Part 4b of the Ant series expands on Part 4a by adding a Flash UI Component to the SWC. Please review Part 4a before proceeding with this tutorial.
1. Download tutorial files
To begin this tutorial, please make sure you have set up your workspace as suggested in Part 1.
View Demo
Download Source Files

2. Examine assets.fla
We begin by [...]]]></description>
			<content:encoded><![CDATA[<p>Part 4b of the Ant series expands on <a href="/building-flash-projects-with-ant-and-flex-builder-part-4a">Part 4a</a> by adding a Flash UI Component to the SWC. Please review <a href="/building-flash-projects-with-ant-and-flex-builder-part-4a">Part 4a</a> before proceeding with this tutorial.</p>
<h3>1. Download tutorial files</h3>
<p>To begin this tutorial, please make sure you have set up your workspace as suggested in <a href="/building-flash-projects-with-ant-and-flex-builder-part-1/#settingUpYourWorkspace">Part 1</a>.</p>
<p><a href="/demos/ant_demo_4b/">View Demo</a></p>
<p><a href="http://github.com/hubflanger/AS3_Ant_Tutorial_4b">Download Source Files</a></p>
<p><span id="more-251"></span></p>
<h3>2. Examine assets.fla</h3>
<p>We begin by dragging an instance of the <code>Button</code> UI Component from the <em>Components Panel</em>. This creates a <code>Button</code> symbol in the library. Note that the <code>Button</code> symbol is linked to the <code>fl.controls.Button</code> class. The <em>Publish Settings</em> of the FLA are set to compile the SWF to the <code>../libs/</code> directory. Under the <em>Flash</em> tab, note that the <em>Export SWC</em> option is checked. This causes the Flash compiler to output a companion SWC whenever a SWF is being published.</p>
<h3>3. Examine compileAssetsSWC.jsfl</h3>
<p>As in previous examples, the <code>compileAssetsSWC.jsfl</code> script opens the <code>assets</code> FLA and tells it to compile its SWF. </p>
<h3>4. Examine the compileAssetsSWC task in build.xml</h3>
<p>As in previous examples, the <code>compileAssetsSWC</code> task calls the <code>compileAssetsSWC.jsfl</code> script passing along a reference to the <code>assets</code> FLA. Run the task by double-clicking <code>compileAssetsSWC</code> in the Ant panel in Flex Builder. Due to the publish settings, an <code>assets.swc</code> file will be published to the <code>libs</code> folder along with <code>assets.swf</code>. We can ignore <code>assets.swf</code> as it won&#8217;t be needed for this tutorial.</p>
<div class="codeblock">
<pre>
&lt;target name="compileAssetsSWC" description="Compile the assets SWC with the Flash IDE"&gt;
  &lt;echo&gt;Flash IDE Compiler for file ${assetsFLA}&lt;/echo&gt;
  &lt;echo message="|*|*|*| class cache clear | source save | compiler start |*|*|*|"/&gt;
  &lt;exec executable="open"&gt;
    &lt;arg line="${compileAssetsSWC_jsfl} ${assetsFLA}"/&gt;
  &lt;/exec&gt;
&lt;/target&gt;
</pre>
</div>
<h3>5. Adding assets.swc to your Classpath</h3>
<p>Add the <code>assets</code> SWC to your classpath as described in <a href="/building-flash-projects-with-ant-and-flex-builder-part-4a/#step5">Step 5</a> of tutorial <a href="/building-flash-projects-with-ant-and-flex-builder-part-4a">Part 4a</a>.</p>
<h3>6. Examine Demo4.as</h3>
<p>In addition to <code>Square</code> instance, <code>Demo4.as</code> creates an instance of the <code>Button</code> component and adds it to the stage. </p>
<div class="codeblock">
<pre>
package
{
  import flash.display.*;
  import fl.controls.Button;

  public class Demo4 extends Sprite
  {
    private var square:Square;
    private var button:Button;

    public function Demo4()
    {
      square = new Square();
      square.x = 200;
      square.y = 100;
      addChild( square );

      button = new Button();
      button.x = 200;
      button.y = 250;
      addChild( button );
    }
  }
}
</pre>
</div>
<h3>7. Adding assets.swc to the MXMLC compiler</h3>
<p>As in <a href="/building-flash-projects-with-ant-and-flex-builder-part-4a">Part 4a</a>, we add a reference to <code>assets.swc</code> for the MXMLC compiler with the code snippet below, in <code>build.xml</code>. Run the <code>compileProject</code> task and load <code>index.html</code> in your web browser. You&#8217;ll see a green square and a <code>Button</code> component in your SWF.</p>
<div class="codeblock">
<pre>
&lt;compiler.library-path dir="${LIB_DIR}" append="true"&gt;
  &lt;include name="assets.swc" /&gt;
&lt;/compiler.library-path&gt;
</pre>
</div>
<h3>Coming up</h3>
<p>In the next and <a href="http://hubflanger.com/building-flash-projects-with-ant-and-flex-builder-part-5/">final installment</a> of this series of tutorials on Ant, we shall explore using a SWC to create a Preloader for your application.</p>
]]></content:encoded>
			<wfw:commentRss>http://hubflanger.com/building-flash-projects-with-ant-and-flex-builder-part-4b/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Building Flash Projects with Ant and Flex Builder &#8211; Part 4a</title>
		<link>http://hubflanger.com/building-flash-projects-with-ant-and-flex-builder-part-4a/</link>
		<comments>http://hubflanger.com/building-flash-projects-with-ant-and-flex-builder-part-4a/#comments</comments>
		<pubDate>Mon, 03 Aug 2009 03:33:30 +0000</pubDate>
		<dc:creator>Peng</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Ant]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Flex Builder]]></category>
		<category><![CDATA[JSFL]]></category>

		<guid isPermaLink="false">http://hubflanger.com/?p=161</guid>
		<description><![CDATA[First off, if you&#8217;ve been waiting for this installment of my series of tutorials on Ant, I offer my sincere apologies. I&#8217;ve been sidetracked by iPhone development and haven&#8217;t been able to find time to finish off these tutorials. As promised, here&#8217;s a follow up to my previous tutorials.
In Part 4a, I shall show you [...]]]></description>
			<content:encoded><![CDATA[<p>First off, if you&#8217;ve been waiting for this installment of my series of tutorials on Ant, I offer my sincere apologies. I&#8217;ve been sidetracked by iPhone development and haven&#8217;t been able to find time to finish off these tutorials. As promised, here&#8217;s a follow up to my previous tutorials.</p>
<p>In Part 4a, I shall show you how to compile a Flash library symbol as a SWC, add this SWC to your Actionscript classpath and compile your application with the Flex MXMLC compiler.</p>
<h3>1. Download tutorial files</h3>
<p>To begin this tutorial, please make sure you have set up your workspace as suggested in <a href="http://hubflanger.com/building-flash-projects-with-ant-and-flex-builder-part-1/#settingUpYourWorkspace">Part 1</a>.</p>
<p><a href="http://hubflanger.com/demos/ant_demo_4a/">View Demo</a></p>
<p><a href="http://github.com/hubflanger/AS3_Ant_Tutorial_4a">Download Source Files</a></p>
<p><span id="more-161"></span></p>
<h3>2. Examine assets.fla</h3>
<p>In <code>fla/assets.fla</code>, you&#8217;ll find in the library, a simple square graphic linked to a class named <code>Square</code>. </p>
<h3>3. Examine compileSquareSWC.jsfl</h3>
<p>This JSFL script targets the <code>square</code> symbol in the library, and exports it as a SWC into the specified directory. In this case, my target output directory is <code>file:///Users/peng/Workspace/FlexBuilder/Hubflanger/<br />AS3_Ant_Tutorial_4a/libs/</code>. You should enter the correct path to the <code>libs</code> folder in your project.</p>
<div class="codeblock">
<pre>
fl.getDocumentDOM().library.selectItem("square", true, true);
var currentSelection = fl.getDocumentDOM().library.getSelectedItems();
currentSelection[0].exportSWC("file:///Users/peng/Workspace/FlexBuilder/Hubflanger/AS3_Ant_Tutorial_4a/libs/square.swc");
</pre>
</div>
<h3>4. Examine the compileSquareSWC task in build.xml</h3>
<p>The <code>build</code> file contains a task named <code>compileSquareSWC</code> which calls the <code>compileSquareSWC.jsfl</code> script passing along a reference to the <code>assets</code> FLA. Run the task by double-clicking <code>compileSquareSWC</code> in the Ant panel in Flex Builder. You&#8217;ll see that a SWC named <code>square</code> has been exported to the <code>libs</code> folder.</p>
<div class="codeblock">
<pre>
&lt;target name="compileSquareSWC" description="Compile the square SWC with the Flash IDE"&gt;
  &lt;echo&gt;Flash IDE Compiler for file ${assetsFLA}&lt;/echo&gt;
  &lt;echo message="|*|*|*| class cache clear | source save | compiler start |*|*|*|"/&gt;
  &lt;exec executable="open"&gt;
    &lt;arg line="${compileSquareSWC_jsfl} ${assetsFLA}"/&gt;
  &lt;/exec&gt;
&lt;/target&gt;
</pre>
</div>
<p><a name="step5"></a></p>
<h3>5. Adding square.swc to your Classpath</h3>
<p>Before you can create a reference to the <code>Square</code> class, you need to add the SWC to your classpath. To do so, first right-click on your project and open the <em>Properties</em> panel. In <em>ActionScript Build Path</em>, select the <em>Library Path</em> tab. Click the <em>Add SWC</em> button, navigate to the <code>libs</code> folder and select the <code>square.swc</code> file. Alternatively, you can click the <em>Add SWC Folder</em> button and select the <code>libs</code> folder. This will add all the SWCs in that folder to your classpath.</p>
<p>By adding the SWC to your classpath in Flex Builder, you&#8217;ll be able to reference the <code>Square</code> class in your Actionscript classes along with code completion.</p>
<h3>6. Examine Demo4.as</h3>
<p><code>Demo4.as</code> creates an instance of the <code>Square</code> object and adds it to the stage. </p>
<div class="codeblock">
<pre>
package
{
  import flash.display.*;

  public class Demo4 extends Sprite
  {
    private var square:Square;

    public function Demo4()
    {
      square = new Square();
      square.x = 200;
      square.y = 100;
      addChild( square );
    }
  }
}
</pre>
</div>
<h3>7. Adding square.swc to the MXMLC compiler</h3>
<p>In order to compile the application, we also need to add a reference to <code>square.swc</code> for the MXMLC compiler. The code snippet below found in <code>build.xml</code> does just that. Run the <code>compileMain</code> task and load <code>index.html</code> in your web browser. You&#8217;ll see a green square in your SWF. Similar to <a href="http://hubflanger.com/building-flash-projects-with-ant-and-flex-builder-part-3/">Part 3</a>, the <code>compileProject</code> task allows you to execute both <code>compileMain</code> and <code>compileSquareSWC</code> in sequence with a simple double-click.</p>
<div class="codeblock">
<pre>
&lt;compiler.library-path dir="${LIB_DIR}" append="true"&gt;
  &lt;include name="square.swc" /&gt;
&lt;/compiler.library-path&gt;
</pre>
</div>
<h3>Coming up</h3>
<p>In <a href="http://hubflanger.com/building-flash-projects-with-ant-and-flex-builder-part-4b/">Part 4b</a>, we&#8217;ll see how we can compile Flash UI Components to a SWC and reference them in our Actionscript classes.</p>
]]></content:encoded>
			<wfw:commentRss>http://hubflanger.com/building-flash-projects-with-ant-and-flex-builder-part-4a/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Building Flash Projects with Ant and Flex Builder &#8211; Part 3</title>
		<link>http://hubflanger.com/building-flash-projects-with-ant-and-flex-builder-part-3/</link>
		<comments>http://hubflanger.com/building-flash-projects-with-ant-and-flex-builder-part-3/#comments</comments>
		<pubDate>Tue, 17 Feb 2009 02:58:13 +0000</pubDate>
		<dc:creator>Peng</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Ant]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Flex Builder]]></category>
		<category><![CDATA[JSFL]]></category>

		<guid isPermaLink="false">http://hubflanger.com/?p=160</guid>
		<description><![CDATA[In Part 3 of this tutorial, we shall use a combination of the MXMLC compiler and JSFL script to compile an external SWF which will be loaded into your main SWF.
1. Download tutorial files
To begin this tutorial, please make sure you have set up your workspace as suggested in Part 1.
View Demo
Download Source Files

2. Examine [...]]]></description>
			<content:encoded><![CDATA[<p>In Part 3 of this tutorial, we shall use a combination of the MXMLC compiler and JSFL script to compile an external SWF which will be loaded into your main SWF.</p>
<h3>1. Download tutorial files</h3>
<p>To begin this tutorial, please make sure you have set up your workspace as suggested in <a href="http://hubflanger.com/building-flash-projects-with-ant-and-flex-builder-part-1/#settingUpYourWorkspace">Part 1</a>.</p>
<p><a href="http://hubflanger.com/demos/ant_demo3/">View Demo</a></p>
<p><a href="http://github.com/hubflanger/AS3_Ant_Tutorial_3">Download Source Files</a></p>
<p><span id="more-160"></span></p>
<h3>2. Examine externalAssets.fla</h3>
<p>In <code>fla/externalAssets.fla</code>, you&#8217;ll find a bitmap image in the first frame of the main timeline. This FLA is set up to publish a SWF named <code>externalAssets.swf</code> into the <code>bin-debug</code> folder. </p>
<h3>3. Examine compileSWF.jsfl</h3>
<p>You&#8217;ll notice that this JSFL script is exactly the same as the one in <a href="http://hubflanger.com/building-flash-projects-with-ant-and-flex-builder-part-1/#compileSWF_JSFL">Part 1</a>. As we shall soon see, this script is completely reusable and we shall use it to compile the <code>externalAssets.swf</code>.</p>
<h3>4. Examine the compileAssetsSWF task in build.xml</h3>
<p>The <code>build</code> file contains a task named <code>compileAssetsSWF</code> which is similar to the task named <code>compileMain</code> previously mentioned <a href="http://hubflanger.com/building-flash-projects-with-ant-and-flex-builder-part-1/">Part 1</a> of this tutorial. It reuses the <code>compileSWF.jsfl</code> script to compile a SWF by passing in <code>assetsFLA</code> as its argument.</p>
<div class="codeblock">
<pre>
&lt;target name="compileAssetsSWF" description="Compile the Assets SWF with the Flash IDE"&gt;
  &lt;echo&gt;Flash IDE Compiler for file ${assetsFLA}&lt;/echo&gt;
  &lt;echo message="|*|*|*| class cache clear | source save | compiler start |*|*|*|"/&gt;
  &lt;exec executable="open"&gt;
    &lt;arg line="${compileSWF_jsfl} ${assetsFLA}"/&gt;
  &lt;/exec&gt;
&lt;/target&gt;
</pre>
</div>
<h3>5. Examine Demo3.as</h3>
<p><code>Demo3.as</code> creates a Loader instance which loads in an external SWF called <code>externalAssets.swf</code>. The <code>loadCompleteHandler</code> then adds the Loader instance onto the main stage.</p>
<div class="codeblock">
<pre>
package
{
  import flash.display.*;
  import flash.events.Event;
  import flash.net.URLRequest;

  public class Demo3 extends Sprite
  {
    private var loader:Loader;

    public function Demo3()
    {
      loader = new Loader();
      loader.contentLoaderInfo.addEventListener( Event.COMPLETE, loadCompleteHandler );
      loader.load( new URLRequest( "externalAssets.swf" ));
    }    

    private function loadCompleteHandler( evt:Event ):void
    {
      evt.target.removeEventListener( Event.COMPLETE, loadCompleteHandler );
      addChild( loader );
    }
  }
}
</pre>
</div>
<h3>6. Examine the compileMain task in build.xml</h3>
<p>We also have a <code>compileMain</code> task which is the same as the one in <a href="http://hubflanger.com/building-flash-projects-with-ant-and-flex-builder-part-2/#compileMain">Part 2</a> except that it passes in Demo3.as as the argument to the MXMLC compiler.</p>
<div class="codeblock">
<pre>
&lt;target name="compileMain"&gt;
  &lt;echo&gt;Compiles Demo3.as file and outputs demo3.swf&lt;/echo&gt;
  &lt;mxmlc file="${SRC_DIR}/Demo3.as" output="${DEPLOY_DIR}/demo3.swf"
    actionscript-file-encoding="UTF-8"
    incremental="false"
    debug="true"
    default-frame-rate="31"
    default-background-color="0xCCCCCC"&gt;

    &lt;load-config filename="${FLEX_HOME}/frameworks/flex-config.xml"/&gt;
    &lt;source-path path-element="${FLEX_HOME}/frameworks"/&gt;
    &lt;source-path path-element="${SRC_DIR}" /&gt;

    &lt;!-- Set size of output SWF file. --&gt;
    &lt;default-size width="550" height="400" /&gt;
  &lt;/mxmlc&gt;
&lt;/target&gt;
</pre>
</div>
<h3>7. Examine the compileProject task in build.xml</h3>
<p>Finally, we have a composite task named <code>compileProject</code> which allows you to execute its dependent tasks ie. <code>compileMain</code> and <code>compileAssetsSWF</code> in sequence with just a double-click.</p>
<div class="codeblock">
<pre>
&lt;target name="compileProject" depends="compileAssetsSWF, compileMain" /&gt;
</pre>
</div>
<h3>Coming up</h3>
<p>As you can see, Ant tasks are highly flexible &#8211; allowing you to customize your workflow by combining varies different techniques, whether you prefer the Flash IDE or the MXMLC compiler. In <a href="http://hubflanger.com/building-flash-projects-with-ant-and-flex-builder-part-4a/">Part 4</a>, we shall discuss using Ant to compile SWCs and how to add SWCs to your workflow.</p>
]]></content:encoded>
			<wfw:commentRss>http://hubflanger.com/building-flash-projects-with-ant-and-flex-builder-part-3/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Building Flash Projects with Ant and Flex Builder &#8211; Part 2</title>
		<link>http://hubflanger.com/building-flash-projects-with-ant-and-flex-builder-part-2/</link>
		<comments>http://hubflanger.com/building-flash-projects-with-ant-and-flex-builder-part-2/#comments</comments>
		<pubDate>Tue, 17 Feb 2009 02:00:00 +0000</pubDate>
		<dc:creator>Peng</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Ant]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Flex Builder]]></category>
		<category><![CDATA[JSFL]]></category>

		<guid isPermaLink="false">http://hubflanger.com/?p=159</guid>
		<description><![CDATA[In Part 2 of this tutorial, we&#8217;ll compile an ActionScript 3 only project simply by launching the MXMLC compiler with an Ant task in Flex Builder.
1. Download tutorial files
To begin this tutorial, please make sure you have set up your workspace as suggested in Part 1.
View Demo
Download Source Files

2. Examine Demo2.as
Demo2.as is exactly the same [...]]]></description>
			<content:encoded><![CDATA[<p>In Part 2 of this tutorial, we&#8217;ll compile an ActionScript 3 only project simply by launching the MXMLC compiler with an Ant task in Flex Builder.</p>
<h3>1. Download tutorial files</h3>
<p>To begin this tutorial, please make sure you have set up your workspace as suggested in <a href="http://hubflanger.com/building-flash-projects-with-ant-and-flex-builder-part-1/#settingUpYourWorkspace">Part 1</a>.</p>
<p><a href="http://hubflanger.com/demos/ant_demo2/">View Demo</a></p>
<p><a href="http://github.com/hubflanger/AS3_Ant_Tutorial_2">Download Source Files</a></p>
<p><span id="more-159"></span></p>
<h3>2. Examine Demo2.as</h3>
<p><code>Demo2.as</code> is exactly the same as <code>Demo1.as</code> in <a href="http://hubflanger.com/building-flash-projects-with-ant-and-flex-builder-part-1/">Part 1</a> of this tutorial. Except this time around, we do not have an FLA linked to <code>Demo2</code> as its document class.</p>
<div class="codeblock">
<pre>
package
{
  import flash.display.Sprite;
  import flash.text.TextField;
  import flash.text.TextFormat;

  public class Demo2 extends Sprite
  {
    public function Demo2()
    {
      var format:TextFormat = new TextFormat();
      format.font = "Arial";
      format.size = 16;
      format.color = 0x000000;

      var label:TextField = new TextField();
      label.width = 500;
      label.defaultTextFormat = format;
      label.text = "Welcome to my ANT Demo!";
      label.x = 100;
      label.y = 150;
      addChild( label );
    }
  }
}
</pre>
</div>
<p><a name="compileMain"></a></p>
<h3>3. Examine build.xml</h3>
<p>The <code>compileMain</code> task here launches the MXMLC compiler with the <code>Demo2.as</code> file as its argument and outputs <code>demo2.swf</code>.</p>
<div class="codeblock">
<pre>
&lt;target name="compileMain"&gt;
  &lt;echo&gt;Compiles Demo2.as file and outputs demo2.swf&lt;/echo&gt;
  &lt;mxmlc file="${SRC_DIR}/Demo2.as" output="${DEPLOY_DIR}/demo2.swf"
    actionscript-file-encoding="UTF-8"
    incremental="false"
    debug="true"
    default-frame-rate="31"
    default-background-color="0xCCCCCC"&gt;

    &lt;load-config filename="${FLEX_HOME}/frameworks/flex-config.xml"/&gt;
    &lt;source-path path-element="${FLEX_HOME}/frameworks"/&gt;
    &lt;source-path path-element="${SRC_DIR}" /&gt;

    &lt;!-- Set size of output SWF file. --&gt;
    &lt;default-size width="550" height="400" /&gt;
  &lt;/mxmlc&gt;
&lt;/target&gt;
</pre>
</div>
<h3>Coming up</h3>
<p>This is a quick and painless one, isn&#8217;t it? In <a href="http://hubflanger.com/building-flash-projects-with-ant-and-flex-builder-part-3/">Part 3</a>, we&#8217;ll use a combination of the MXMLC compiler and JSFL script to compile an external SWF which will be loaded into your main SWF.</p>
]]></content:encoded>
			<wfw:commentRss>http://hubflanger.com/building-flash-projects-with-ant-and-flex-builder-part-2/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Building Flash Projects with Ant and Flex Builder &#8211; Part 1</title>
		<link>http://hubflanger.com/building-flash-projects-with-ant-and-flex-builder-part-1/</link>
		<comments>http://hubflanger.com/building-flash-projects-with-ant-and-flex-builder-part-1/#comments</comments>
		<pubDate>Mon, 02 Feb 2009 03:00:46 +0000</pubDate>
		<dc:creator>Peng</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Ant]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Flex Builder]]></category>
		<category><![CDATA[JSFL]]></category>

		<guid isPermaLink="false">http://hubflanger.com/?p=116</guid>
		<description><![CDATA[As more Flash developers migrate towards using tools like Flex Builder and FDT for code editing, some of us have found that switching between the Flash IDE and Flex Builder doesn&#8217;t necessarily present the most seamless workflow. Compiling with the Flash IDE is slow and cumbersome; building an entire Flash project with code in Flex [...]]]></description>
			<content:encoded><![CDATA[<p>As more Flash developers migrate towards using tools like Flex Builder and FDT for code editing, some of us have found that switching between the Flash IDE and Flex Builder doesn&#8217;t necessarily present the most seamless workflow. Compiling with the Flash IDE is slow and cumbersome; building an entire Flash project with code in Flex Builder doesn&#8217;t integrate nicely the designer&#8217;s workflow either. Until Flash Catalyst becomes available and magically cures all our designer-developer workflow headaches, what we need is a way to leverage each tool for what it does best, ie. the Flash IDE for drawing and layout, and Flex Builder for code.</p>
<p>Apache Ant is a software tool for automating software build processes implemented using the Java language. Ant uses XML to describe the build process and its dependencies, so no knowledge of Java is necessary for  running Ant in your Flex Builder environment. By default the XML file is named build.xml.</p>
<p>In this series of tutorials, I will show you how to use Ant to create a workflow between the Flash IDE and Flex Builder. In Part 1 of this tutorial, we shall use Ant and JSFL to launch a FLA to publish a SWF.</p>
<p><span id="more-116"></span><br />
JSFL is a Javascript-based scripting language for scripting the Flash IDE, allowing you to do things such as publish a SWF, etc. just by launching a script from the command line. Documentation for JSFL can be found here: <a href="http://livedocs.adobe.com/flash/9.0/main/flash_cs3_extending.pdf">http://livedocs.adobe.com/flash/9.0/main/flash_cs3_extending.pdf</a>. </p>
<p>Combined with Ant, they provide a powerful toolset for the aspiring Flash/Actionscript developer. </p>
<p><a name="settingUpYourWorkspace"></a></p>
<h3>1. Setting up your workspace</h3>
<p>The standalone Flex Builder install is built on top of a stripped down version of Eclipse and does not come with built-in support for Ant. To get Ant support in the Flex Builder, follow the instructions in these tutorials:</p>
<p><a href="http://www.peterelst.com/blog/2006/09/03/flex-builder-2-ant-support/" target="_blank">http://www.peterelst.com/blog/2006/09/03/flex-builder-2-ant-support/</a></p>
<p><a href="http://blog.jodybrewster.net/2008/04/09/installing-ant-in-flex-builder-3/" target="_blank">http://blog.jodybrewster.net/2008/04/09/installing-ant-in-flex-builder-3/</a></p>
<p>If you&#8217;re using FDT or the Flex Builder plug-in for Eclipse, the standard Eclipse install comes with built-in support for Ant, so you&#8217;re good to go.</p>
<h3>2. Download tutorial files</h3>
<p>This tutorial assumes a working knowledge of Flex Builder. You should already know how to create an Actionscript project in Flex Builder. The directory structure is set up like a typical project in Flex Builder, with <code>bin-debug</code> as the output folder, <code>src</code> containing the Actionscript files and <code>fla</code> containing the FLAs. </p>
<p><a href="http://hubflanger.com/demos/ant_demo1/">View Demo</a></p>
<p><a href="http://github.com/hubflanger/AS3_Ant_Tutorial_1">Download Source Files</a></p>
<h3>3. Examine demo1.fla</h3>
<p><code>demo1.fla</code> is a simple FLA which points to Demo1.as as its document class. It is set up to publish a SWF named <code>demo1.swf</code> to the <code>bin-debug</code> folder.</p>
<p>The Demo1 class creates a textField containing &#8220;Welcome to my Ant Demo!&#8221; and adds it to the stage.</p>
<p><a name="compileSWF_JSFL"></a></p>
<h3>4. Examine compileSWF.jsfl</h3>
<p>The JSFL script for launching <code>demo1.fla</code> and publishing <code>demo1.swf</code> resides in the <code>jsfl</code> folder. It starts off by clearing the ASO cache and Flash IDE&#8217;s Output Panel. Then it saves the FLA and publishes the SWF.</p>
<div class="codeblock">
<pre>
function clearASOCache( path ) {
  if (!FLfile.exists( path )) {
    fl.trace( path + "does not exist" );
    return;
  }
  FLfile.remove( path );
}

clearASOCache ( fl.configURI + "Classes/aso" );
fl.outputPanel.clear();
fl.getDocumentDOM().save();
fl.getDocumentDOM().publish();
</pre>
</div>
<h3>5. Examine build.xml</h3>
<p>This Ant build file contains a couple of references to <code>demo1.fla</code> and <code>compileSWF.jsfl</code> named <code>demoFLA</code> and <code> compileSWF_jsfl</code> respectively. These properties provide shortcuts to commonly referenced resources in your project and allows you define them in a single convenient location.</p>
<p>The <code>target</code> named <code>compileMain</code> is the Ant task that calls the <code>compileSWF_jsfl</code> script, passing it the property <code>demoFLA</code>. The JSFL script then takes over by launching the FLA and compiling the SWF.</p>
<div class="codeblock">
<pre>
&lt;project name="Flex Ant Tasks Demo1" default="compileMain" basedir="."&gt;&gt;
  &lt;property name="demoFLA" value="fla/demo1.fla" /&gt;
  &lt;property name="compileSWF_jsfl" value="jsfl/compileSWF.jsfl" /&gt;

  &lt;!-- This task launches the compileSWF.jsfl script to compile demo1.swf using the Flash IDE --&gt;
  &lt;target name="compileMain" description="Compile the demo1 SWF with the Flash IDE"&gt;
    &lt;echo&gt;Flash IDE Compiler for file ${mainFLA}&lt;/echo&gt;
    &lt;echo message="|*|*|*| class cache clear | source save | compiler start |*|*|*|"/&gt;
    &lt;exec executable="open"&gt;
      &lt;arg line="${compileSWF_jsfl} ${demoFLA}"/&gt;
    &lt;/exec&gt;
  &lt;/target&gt;
&lt;/project&gt;
</pre>
</div>
<h3>6. Using the Outline Panel</h3>
<p>Launch the Outline Panel by selecting Window->Other Views->General->Outline from the top menu. In the Outline Panel, you&#8217;ll be able to browse the list of properties and targets defined in your build file. Clicking an item in the list will cause the the editor jump to the line where that particular item is defined, making it quick and easy to navigate and edit an Ant build file (<a href="http://hubflanger.com/wp-content/uploads/ant-tutorial-part1-fig1.jpg">fig. 1</a>).</p>
<h3>7. Using the Ant Panel</h3>
<p>Next, we launch the Ant Panel by selecting Window->Other Views->Ant->Ant in the top menu. To see the list of Ant tasks available within <code>build.xml</code>, just drag the file into the Ant Panel (<a href="http://hubflanger.com/wp-content/uploads/ant-tutorial-part1-fig2.jpg">fig. 2</a>). Now, whenever you need to execute an Ant task, just double-click the task or right-click on it and select Run As->Ant Build.</p>
<p>That&#8217;s it. As you can see, it&#8217;s quite easy to get started with Ant. Even better, Ant is a tool that grows with your project, becoming more powerful and complex as your project demands it. </p>
<p>Before we proceed to the next part of this tutorial, I would like to thank the kind folks at the New York City Flash User Group, <a href="http://flashcodersny.org/" target="_blank">FlashCodersNY</a>, for sharing their knowledge on Ant. This tutorial would not be possible without their generosity.</p>
<h3>Coming up</h3>
<p>In <a href="http://hubflanger.com/building-flash-projects-with-ant-and-flex-builder-part-2/">Part 2</a> of this tutorial, we shall use Flex Ant Tasks to compile a SWF with the MXMLC compiler.</p>
]]></content:encoded>
			<wfw:commentRss>http://hubflanger.com/building-flash-projects-with-ant-and-flex-builder-part-1/feed/</wfw:commentRss>
		<slash:comments>29</slash:comments>
		</item>
	</channel>
</rss>
