<?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>FlasCC</title>
	<atom:link href="http://blogs.adobe.com/flascc/feed/" rel="self" type="application/rss+xml" />
	<link>http://blogs.adobe.com/flascc</link>
	<description>Using Adobe Flash C++ Compiler</description>
	<lastBuildDate>Mon, 18 Mar 2013 16:57:53 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>FlasCC and Link Time Optimization</title>
		<link>http://blogs.adobe.com/flascc/2013/03/18/flascc-and-link-time-optimization/</link>
		<comments>http://blogs.adobe.com/flascc/2013/03/18/flascc-and-link-time-optimization/#comments</comments>
		<pubDate>Mon, 18 Mar 2013 16:57:53 +0000</pubDate>
		<dc:creator>speterse</dc:creator>
				<category><![CDATA[FlasCC]]></category>
		<category><![CDATA[LTO]]></category>

		<guid isPermaLink="false">http://blogs.adobe.com/flascc/?p=450</guid>
		<description><![CDATA[The FlasCC toolchain is closely modeled after a typical native C/C++ development toolchain. It contains all of the tools you would expect from such a toolchain, including a compiler (with preprocesser), an assembler, a linker, an nm symbol lister, an &#8230; <a href="http://blogs.adobe.com/flascc/2013/03/18/flascc-and-link-time-optimization/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>The FlasCC toolchain is closely modeled after a typical native C/C++ development toolchain. It contains all of the tools you would expect from such a toolchain, including a compiler (with preprocesser), an assembler, a linker, an nm symbol lister, an ar archiver, etc.<br />
<span id="more-450"></span></p>
<p>As with many such toolchains, FlasCC uses the preprocess, compile, assemble, link model. Each is an individual step, although the compiler driver may perform multiple steps with a single invocation.</p>
<p>In the following example, the compiler driver is used to go from a simple .c file to a final executable in a single command:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="c" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/* everyone's favorite C program: hello.c */</span>
<span style="color: #993333;">int</span> main<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Hello, world!<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p><code><br />
# preprocess, compile, assemble, link, resulting in final executable<br />
&gt; flascc/sdk/usr/bin/gcc hello.c –o hello.exe</code></p>
<p>Under the hood, it’s going through 4 distinct stages.</p>
<p><b>Stage 1: Preprocessing</b></p>
<p>The preprocessing stage works the same way with FlasCC as with a conventional native toolchain. It processes <code>#include</code> directives, expands macros, etc.</p>
<p><code># preprocess hello.c resulting in preprocessed C in hello.i<br />
&gt; flascc/sdk/usr/bin/gcc –E hello.c –o hello.i</code></p>
<p><b>Stage 2: Compilation</b></p>
<p>The compilation stage compiles the preprocessed C code into “assembly code.” In a native toolchain, this would result in x86, arm, etc. assembly code. For FlasCC, “assembly code” is ActionScript 3 (AS3) code.</p>
<p><code># compile hello.i resulting in “assembly code” in hello.s<br />
&gt; flascc/sdk/usr/bin/gcc –S hello.i –o hello.s </code></p>
<p><b>Stage 3: Assembly</b></p>
<p>The assembly stage “assembles” the ActionScript 3 code generated in the previous stage into “object code.” In actuality, it is doing a full compile of the AS3 code using the ASC2 compiler, resulting in an ActionScript Bytecode (or ABC) file. There is some additional work done to compile the single file into multiple AS3 “scripts” to allow lazy initialization of FlasCC modules at runtime. While the resulting file is actually ABC, the nm and ar utilities have been extended to understand them.</p>
<p><code># assemble hello.s resulting in object code in hello.o<br />
&gt; flascc/sdk/usr/bin/gcc –c hello.s –o hello.o</code></p>
<p>The nm tool can be used to list symbols of an ABC “object file.”</p>
<p><code> # list C symbols in hello.o<br />
&gt; flascc/sdk/usr/bin/nm hello.o<br />
00000000 T _main<br />
         U _puts<br />
00000000 W abort<br />
00000000 W memcpy<br />
00000000 W memmove<br />
00000000 W memset<br />
</code></p>
<p>The ar tool can be used to build an archive containing ABC “object files”</p>
<p><code># create an archive containing hello.o<br />
&gt; flascc/sdk/usr/bin/ar cr hello.a hello.o</code></p>
<p><code># list the C symbols in the hello.a archive<br />
&gt; flascc/sdk/usr/bin/nm hello.a </p>
<p>hello.o:<br />
00000000 T _main<br />
         U _puts<br />
00000000 W abort<br />
00000000 W memcpy<br />
00000000 W memmove<br />
00000000 W memset<br />
</code></p>
<p><b>Stage 4: Link</b></p>
<p>Finally, we can link hello.o into a standalone executable.</p>
<p><code># link hello.o into an executable<br />
&gt; flascc/sdk/usr/bin/gcc hello.o –o hello.exe</code></p>
<p><code># execute the exe<br />
&gt; ./hello.exe<br />
Hello, world!<br />
</code></p>
<p><a href="http://blogs.adobe.com/flascc/2012/11/17/using-configure-scripts-with-flascc/" title="Using configure scripts with FlasCC" target="_blank">This</a> blog post describes why you might want a standalone executable built using FlasCC. But in most cases, you would want to build a SWF instead.</p>
<p><code># link hello.o into a SWF<br />
&gt; flascc/sdk/usr/bin/gcc hello.o –emit-swf –o hello.swf</code></p>
<h2>Link Time Optimization (LTO)</h2>
<p>FlasCC is built on the <a href="http://llvm.org" target="_blank">LLVM Compiler Infrastructure</a> and is therefore able to take advantage of LLVM’s powerful link time optimization features. LTO can, in many cases, result in substantially faster and smaller SWFs. LTO is enabled on a file-by-file basis by passing the <code>–flto</code> flag to the compiler driver for each source file that is to participate.</p>
<p>Using the <code>–flto</code> flag (or the <code>–O4</code> optimization level which implies <code>–flto</code>) when compiling source into object code results in an LLVM bitcode file instead of an ABC.</p>
<p><code># compile hello.c into LLVM bitcode<br />
&gt; flascc/sdk/usr/bin/gcc hello.c –c –flto –o hello.o </code></p>
<p>The relevant tools can consume both ABC and LLVM bitcode files.<br />
<code><br />
# nm still works<br />
&gt; flascc/sdk/usr/bin/nm hello.o<br />
00000000 T _main<br />
         U _puts<br />
00000000 W abort<br />
00000000 W memcpy<br />
00000000 W memmove<br />
00000000 W memset</p>
<p># ar still works<br />
&gt; flascc/sdk/usr/bin/ar cr hello.a hello.o</p>
<p># contents of archives still accessible<br />
&gt; flascc/sdk/usr/bin/nm hello.a<br />
hello.o:<br />
00000000 T _main<br />
         U _puts<br />
00000000 W abort<br />
00000000 W memcpy<br />
00000000 W memmove<br />
00000000 W memset</p>
<p># build a LTO-ed version of hello.exe<br />
&gt; flascc/sdk/usr/bin/gcc –flto hello.o –o hello.exe<br />
</code></p>
<p>FlasCC comes with both ABC and LLVM bitcode flavored standard libraries. So a fully LTO build (<code>–flto</code> or <code>–O4</code> passed to the compiler driver for each source file and for the link step) will do link time optimization of the standard C and C++ libraries as well as object files generated from user code.</p>
<h2>Differences Between LTO and non-LTO Builds in FlasCC</h2>
<p>One big difference between LTO and non-LTO builds in FlasCC is where AS3 generation and compilation happens. In a non-LTO build, AS3 is generated and compiled to ABC as each source file is compiled. Subsequently, the generated ABCs are combined in the link step to create a SWF or executable. Compared to compiling AS3, combining ABCs is a relatively inexpensive operation. So compiling each source file is relatively expensive, but linking is relatively cheap. Changing a single source file in a project means recompiling that source file and relinking.</p>
<p>In an LTO build, each source file is compiled to LLVM bitcode. In the link step, the LLVM bitcode files generated from source are linked together into a single aggregate bitcode file. That bitcode file can then be optimized. Since bitcode from various source files have been combined into this single unit, optimizations can be applied across functions and data from multiple source files.</p>
<p>After optimization, the bitcode is then used to generate a single AS3 file that is then compiled with ASC2. This results in compile time characteristics that are the opposite of non-LTO builds. Here, compilation of source is cheap and linking in expensive. This also means that, since the generated AS3 depends on the aggregate LLVM bitcode file, and the aggregate LLVM bitcode file depends on each LLVM bitcode file derived from source (as well as bitcode for the C/C++ standard libraries in a fully LTO build), all AS3 must be regenerated and recompiled every time any source file in a project is changed!</p>
<p>So, as a general rule, it makes sense to use LTO for release-type builds because the longer compile time will result in smaller/faster SWF files.  On the other hand if you are creating debug-type builds it makes sense to avoid LTO for faster compile times making it easier to iterate on the code.</p>
<table width="500" cellspacing="0">
<tr>
<td style="border-bottom: 1px solid #CCC;"><strong>Build Type</strong></td>
<td style="border-bottom: 1px solid #CCC;"><strong>Compile Performance</strong></td>
<td style="border-bottom: 1px solid #CCC;"><strong>SWF Performance</strong></td>
<td style="border-bottom: 1px solid #CCC;"><strong>SWF File Size</strong></td>
</tr>
<tr>
<td>LTO</td>
<td>Slower</td>
<td>Faster</td>
<td>Smaller</td>
</tr>
<tr>
<td>Non-LTO</td>
<td>Faster</td>
<td>Slower</td>
<td>Larger</td>
</tr>
</table>
<p></p>
<p>A bit more on this topic can be found in the <a href="http://www.adobe.com/devnet-docs/flascc/docs/Reference.html" target="_blank">reference guide</a> in the <em>Optimizing SWFs and SWCs</em> subsection of the <em><a href="http://www.adobe.com/devnet-docs/flascc/docs/Reference.html#section_gcc" target="_blank">Compiling With GCC</a></em> section.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.adobe.com/flascc/2013/03/18/flascc-and-link-time-optimization/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>FlasCC 1.0.1 Released</title>
		<link>http://blogs.adobe.com/flascc/2013/02/07/flascc-1-0-1-released/</link>
		<comments>http://blogs.adobe.com/flascc/2013/02/07/flascc-1-0-1-released/#comments</comments>
		<pubDate>Thu, 07 Feb 2013 21:42:10 +0000</pubDate>
		<dc:creator>stshongr</dc:creator>
				<category><![CDATA[FlasCC]]></category>

		<guid isPermaLink="false">http://blogs.adobe.com/flascc/?p=592</guid>
		<description><![CDATA[FlasCC 1.0.1 has been released containing fixes for some commonly experienced bugs. Download the latest FlasCC SDK as part of a Creative Cloud subscription. If you have questions about the FlasCC SDK check out the FlasCC community forums. Release Notes &#8230; <a href="http://blogs.adobe.com/flascc/2013/02/07/flascc-1-0-1-released/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>FlasCC 1.0.1 has been released containing fixes for some commonly experienced bugs.<br />
<span id="more-592"></span></p>
<p><a href="http://gaming.adobe.com/getstarted/" target="_blank">Download the latest FlasCC SDK</a> as part of a Creative Cloud subscription.</p>
<p>If you have questions about the FlasCC SDK check out the <a href="http://forums.adobe.com/community/game_developers/flascc" target="_blank">FlasCC community forums</a>.</p>
<p><a href="http://www.adobe.com/content/dam/Adobe/en/devnet/games/pdfs/release-notes-flascc.pdf" target="_blank">Release Notes</a> (PDF)</p>
<h2>Fixed Issues</h2>
<ul>
<li>Debug builds no longer fails at runtime with Reference Errors mentioning symbols with &#8220;THUNK&#8221; in their name</li>
<li>avm2_uithunk no longer fails when content was started using CModule.startAsync() due to incorrect assignment of thread ids</li>
<li>AS3_GoAsync() can now be used from main when started via CModule.startBackground()</li>
<li>Adding directories via the InMemoryBackingStore AS3 API with trailing slashes now works</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blogs.adobe.com/flascc/2013/02/07/flascc-1-0-1-released/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Porting a C++/OpenGL game to run in the browser</title>
		<link>http://blogs.adobe.com/flascc/2013/01/18/porting-a-c-opengl-game-to-run-in-the-browser/</link>
		<comments>http://blogs.adobe.com/flascc/2013/01/18/porting-a-c-opengl-game-to-run-in-the-browser/#comments</comments>
		<pubDate>Fri, 18 Jan 2013 23:46:10 +0000</pubDate>
		<dc:creator>stshongr</dc:creator>
				<category><![CDATA[FlasCC]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[g++]]></category>
		<category><![CDATA[Neverball]]></category>
		<category><![CDATA[OpenGL]]></category>
		<category><![CDATA[Scout]]></category>

		<guid isPermaLink="false">http://blogs.adobe.com/flascc/?p=429</guid>
		<description><![CDATA[The Flash C++ Compiler (FlasCC) was designed to allow C/C++ developers to deliver existing C/C++ codebases via a web browser using the Flash Player. One common use case is to port an existing game written in C++ and OpenGL. The &#8230; <a href="http://blogs.adobe.com/flascc/2013/01/18/porting-a-c-opengl-game-to-run-in-the-browser/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>The Flash C++ Compiler (FlasCC) was designed to allow C/C++ developers to deliver existing C/C++ codebases via a web browser using the Flash Player.  One common use case is to port an existing game written in C++ and OpenGL.  The FlasCC engineering team has taken a popular C++/OpenGL game called Neverball and ported it to the web.  This post demonstrates the game running in multiple web browsers and provides links to resources that will help you learn how to port your C++/OpenGL game to the web.<br />
<span id="more-429"></span></p>
<h2>Neverball</h2>
<p>The <a href="http://neverball.org/" target="_blank">Neverball</a> project is an open source computer game written in C++ using OpenGL.  The goal is to tilt the floor to roll a ball around picking up coins and getting to the exit.  You can download the native executable to try the game yourself from the <a href="http://neverball.org/download.php" target="_blank">Neverball Downloads</a> page.</p>
<p>The Neverball Downloads page also allows you to download the source code for the game.   You can try downloading the source code and using a native g++ toolchain to build a native executable.</p>
<p>Learn how to port this game to run in the browser by reading the extensive article on the Adobe Developer Center that describes <a href="http://www.adobe.com/devnet/games/articles/compiling-opengl-games.html" target="_blank">how to compile OpenGL games with the Flash C++ Compiler (FlasCC)</a>.</p>
<h2>Live Demo</h2>
<p>The FlasCC engineering team has already built a version of the game and hosted it online for you to try yourself.</p>
<p><a href="http://cmodule.org/neverball" target="_blank">Neverball Live Demo</a></p>
<h2>Screencast</h2>
<p>This screencast demonstrates the game in action across various web browsers:</p>
<p><iframe width="640" height="480" src="http://www.youtube.com/embed/C9t4TwMQRt0" frameborder="0" allowfullscreen></iframe></p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.adobe.com/flascc/2013/01/18/porting-a-c-opengl-game-to-run-in-the-browser/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Using printf within a SWC</title>
		<link>http://blogs.adobe.com/flascc/2013/01/18/using-printf-within-a-swc/</link>
		<comments>http://blogs.adobe.com/flascc/2013/01/18/using-printf-within-a-swc/#comments</comments>
		<pubDate>Fri, 18 Jan 2013 21:54:49 +0000</pubDate>
		<dc:creator>stshongr</dc:creator>
				<category><![CDATA[FlasCC]]></category>
		<category><![CDATA[printf]]></category>
		<category><![CDATA[SWC]]></category>

		<guid isPermaLink="false">http://blogs.adobe.com/flascc/?p=335</guid>
		<description><![CDATA[A SWF built with gcc/g++ using the -emit-swf option has a default Console that prints stdout into a TextField on the screen (and to the Flash log file). However when you build a C/C++ library into a SWC using the &#8230; <a href="http://blogs.adobe.com/flascc/2013/01/18/using-printf-within-a-swc/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>A SWF built with gcc/g++ using the <code>-emit-swf</code> option has a default <a href="http://www.adobe.com/devnet-docs/flascc/docs/Reference.html#section_console" target="_blank">Console</a> that prints stdout into a TextField on the screen (and to the <a href="http://livedocs.adobe.com/flex/3/html/help.html?content=logging_04.html" target="_blank">Flash log file</a>).  However when you build a C/C++ library into a SWC using the <code>-emit-swc</code> flag there is no default Console.  This means that if code in your library calls <code>printf()</code> no output will be shown.  This post demonstrates how to use a custom Console to show the output of <code>printf()</code> calls from within a SWC.<br />
<span id="more-335"></span></p>
<p>This post assumes you already know how to compile a SWC in FlasCC. If you do not know how see the <a href="http://www.adobe.com/devnet-docs/flascc/docs/samples.html#T5" target="_blank">samples/05_SWC</a> sample application that ships with the FlasCC SDK.</p>
<p>Let&#8217;s start with a very simple C library that will be compiled into a SWC:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#include &lt;stdio.h&gt;</span>
<span style="color: #339933;">#include &quot;AS3/AS3.h&quot;</span>
&nbsp;
<span style="color: #993333;">void</span> doSomething<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> __attribute__<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>used<span style="color: #339933;">,</span>
    annotate<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;as3sig:public function doSomething():void&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
    annotate<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;as3package:MyLibrary&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #993333;">void</span> doSomething<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;SUCCESS<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">int</span> main<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// The SWC still needs a main() function.  </span>
    <span style="color: #666666; font-style: italic;">// See the code comments in samples/05_SWC for more details.</span>
    AS3_GoAsync<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>This library exposes a single function called <code>doSomething()</code> that simply uses <code>printf()</code> to write the string &#8220;SUCCESS&#8221;.  First let&#8217;s compile this library into a SWC using the following command:</p>
<p><code>/path/to/flascc/usr/bin/gcc MyLibrary.c -emit-swc=MyLibrary -o MyLibrary.swc</code></p>
<p>Now this SWC is ready to be dropped into an ActionScript project in <a href="http://www.adobe.com/products/flash-builder.html" target="_blank">Flash Builder</a>.  If you were to then call that function from the ActionScript application you would notice that no output was written to the screen or traced out.  In order to see this output we need to tell the library which object is available to receive the data.  This is done by setting the <code><a href="http://www.adobe.com/devnet-docs/flascc/docs/apidocs/com/adobe/flascc/CModule.html#vfs" target="_blank">CModule.vfs.console</a></code> property to an Object that implements the <code><a href="http://www.adobe.com/devnet-docs/flascc/docs/apidocs/com/adobe/flascc/vfs/ISpecialFile.html" target="_blank">ISpecialFile</a></code> interface.</p>
<p>Here is a sample ActionScript application which itself implements <code><a href="http://www.adobe.com/devnet-docs/flascc/docs/apidocs/com/adobe/flascc/vfs/ISpecialFile.html" target="_blank">ISpecialFile</a></code>:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="actionscript" style="font-family:monospace;">package <span style="color: #66cc66;">&#123;</span>
&nbsp;
    <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">Sprite</span>;
    <span style="color: #0066CC;">import</span> flash.<span style="color: #0066CC;">text</span>.<span style="color: #0066CC;">TextField</span>;
    <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">Event</span>;
&nbsp;
    <span style="color: #0066CC;">import</span> MyLibrary.<span style="color: #006600;">CModule</span>;
    <span style="color: #0066CC;">import</span> MyLibrary.<span style="color: #006600;">vfs</span>.<span style="color: #006600;">ISpecialFile</span>;
&nbsp;
    <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> SampleApplication <span style="color: #0066CC;">extends</span> Sprite <span style="color: #0066CC;">implements</span> ISpecialFile <span style="color: #66cc66;">&#123;</span>
&nbsp;
        <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> tf:<span style="color: #0066CC;">TextField</span>;
&nbsp;
        <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> SampleApplication<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
            addEventListener<span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">ADDED_TO_STAGE</span>, initCode<span style="color: #66cc66;">&#41;</span>;
        <span style="color: #66cc66;">&#125;</span>
&nbsp;
        <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> initCode<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
            tf = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">TextField</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
            addChild<span style="color: #66cc66;">&#40;</span>tf<span style="color: #66cc66;">&#41;</span>;
            tf.<span style="color: #006600;">appendText</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;SWC Output:<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
            <span style="color: #808080; font-style: italic;">// set the console before starting</span>
            MyLibrary.<span style="color: #006600;">CModule</span>.<span style="color: #006600;">vfs</span>.<span style="color: #006600;">console</span> = <span style="color: #0066CC;">this</span>;
&nbsp;
            <span style="color: #808080; font-style: italic;">// start the FlasCC library</span>
            MyLibrary.<span style="color: #006600;">CModule</span>.<span style="color: #006600;">startAsync</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
            <span style="color: #808080; font-style: italic;">// call a C++ function that calls printf</span>
            MyLibrary.<span style="color: #006600;">doSomething</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #66cc66;">&#125;</span>
&nbsp;
        <span style="color: #808080; font-style: italic;">/**
         * The PlayerKernel implementation will use this function to handle
         * C IO write requests to the file &quot;/dev/tty&quot; (e.g. output from
         * printf will pass through this function). See the ISpecialFile
         * documentation for more information about the arguments and return value.
         */</span>
        <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> write<span style="color: #66cc66;">&#40;</span>fd:<span style="color: #0066CC;">int</span>, bufPtr:<span style="color: #0066CC;">int</span>, nbyte:<span style="color: #0066CC;">int</span>, errnoPtr:<span style="color: #0066CC;">int</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">int</span>
        <span style="color: #66cc66;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">var</span> str:<span style="color: #0066CC;">String</span> = CModule.<span style="color: #006600;">readString</span><span style="color: #66cc66;">&#40;</span>bufPtr, nbyte<span style="color: #66cc66;">&#41;</span>;
            tf.<span style="color: #006600;">appendText</span><span style="color: #66cc66;">&#40;</span>str<span style="color: #66cc66;">&#41;</span>;
            <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span>str<span style="color: #66cc66;">&#41;</span>;
            <span style="color: #b1b100;">return</span> nbyte;
        <span style="color: #66cc66;">&#125;</span>
&nbsp;
        <span style="color: #808080; font-style: italic;">/** See ISpecialFile */</span>
        <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> read<span style="color: #66cc66;">&#40;</span>fd:<span style="color: #0066CC;">int</span>, bufPtr:<span style="color: #0066CC;">int</span>, nbyte:<span style="color: #0066CC;">int</span>, errnoPtr:<span style="color: #0066CC;">int</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">int</span> <span style="color: #66cc66;">&#123;</span> <span style="color: #b1b100;">return</span> <span style="color: #cc66cc;">0</span>; <span style="color: #66cc66;">&#125;</span>
        <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> fcntl<span style="color: #66cc66;">&#40;</span>fd:<span style="color: #0066CC;">int</span>, com:<span style="color: #0066CC;">int</span>, <span style="color: #0066CC;">data</span>:<span style="color: #0066CC;">int</span>, errnoPtr:<span style="color: #0066CC;">int</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">int</span> <span style="color: #66cc66;">&#123;</span> <span style="color: #b1b100;">return</span> <span style="color: #cc66cc;">0</span>; <span style="color: #66cc66;">&#125;</span>
        <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> ioctl<span style="color: #66cc66;">&#40;</span>fd:<span style="color: #0066CC;">int</span>, com:<span style="color: #0066CC;">int</span>, <span style="color: #0066CC;">data</span>:<span style="color: #0066CC;">int</span>, errnoPtr:<span style="color: #0066CC;">int</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">int</span> <span style="color: #66cc66;">&#123;</span> <span style="color: #b1b100;">return</span> <span style="color: #cc66cc;">0</span>; <span style="color: #66cc66;">&#125;</span>
    <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>The other <code><a href="http://www.adobe.com/devnet-docs/flascc/docs/apidocs/com/adobe/flascc/vfs/ISpecialFile.html" target="_blank">ISpecialFile</a></code> methods are not fully implemented and left as an exercise to the reader.  See the documentation of <code><a href="http://www.adobe.com/devnet-docs/flascc/docs/apidocs/com/adobe/flascc/vfs/ISpecialFile.html" target="_blank">ISpecialFile</a></code> and the <a href="http://www.adobe.com/devnet-docs/flascc/docs/Reference.html#section_console" target="_blank">FlasCC reference guide</a> for more information on working with a custom Console.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.adobe.com/flascc/2013/01/18/using-printf-within-a-swc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Troubleshooting Error #1065</title>
		<link>http://blogs.adobe.com/flascc/2013/01/11/troubleshooting-error-1065/</link>
		<comments>http://blogs.adobe.com/flascc/2013/01/11/troubleshooting-error-1065/#comments</comments>
		<pubDate>Fri, 11 Jan 2013 23:51:59 +0000</pubDate>
		<dc:creator>stshongr</dc:creator>
				<category><![CDATA[FlasCC]]></category>
		<category><![CDATA[pthread]]></category>

		<guid isPermaLink="false">http://blogs.adobe.com/flascc/?p=313</guid>
		<description><![CDATA[This post explains why you might see error #1065 when creating a SWF or SWC in FlasCC. The full text of the runtime error is: Error #1065: Variable avm2.intrinsics.memory::casi32 is not defined. Typically this error is experienced when you have &#8230; <a href="http://blogs.adobe.com/flascc/2013/01/11/troubleshooting-error-1065/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>This post explains why you might see error #1065 when creating a SWF or SWC in FlasCC.<br />
<span id="more-313"></span></p>
<p>The full text of the runtime error is:</p>
<p><code>Error #1065: Variable avm2.intrinsics.memory::casi32 is not defined.</code></p>
<p>Typically this error is experienced when you have built a FlasCC SWF that uses multi-threading, but the version of the Flash Player that is running the SWF does not support multi-threading.  Multi-threading in FlasCC requires at least Flash Player 11.5.</p>
<p>To fix this error you will need to upgrade your <a href="http://www.adobe.com/support/flashplayer/downloads.html" target="_blank">Flash Player</a> to at least version 11.5.</p>
<p>If your application does not use any multi-threading features, but you are still experiencing this error check to make sure that you aren&#8217;t compiling with the <code>-pthread</code> flag.  When you compile with <code>-pthread</code> you link in some thread-safe variants of parts of the standard library that require threading to actually be supported.</p>
<p>Note that multi-threaded code is not yet supported by Flash Player in Google Chrome (PPAPI). Google<br />
and Adobe are working to provide support in a future version of Chrome.</p>
<p>Learn more about multi-threading in FlasCC by reading the <a href="http://www.adobe.com/devnet-docs/flascc/docs/Reference.html#section_concurrency" target="_blank">concurrency section of the reference guide</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.adobe.com/flascc/2013/01/11/troubleshooting-error-1065/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sample C++ libraries running in the browser via Flash Player</title>
		<link>http://blogs.adobe.com/flascc/2013/01/04/sample-c-libraries-running-in-the-browser-via-flash-player/</link>
		<comments>http://blogs.adobe.com/flascc/2013/01/04/sample-c-libraries-running-in-the-browser-via-flash-player/#comments</comments>
		<pubDate>Fri, 04 Jan 2013 23:26:31 +0000</pubDate>
		<dc:creator>alexmac</dc:creator>
				<category><![CDATA[FlasCC]]></category>
		<category><![CDATA[Box2D]]></category>
		<category><![CDATA[Bullet]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[Lua]]></category>
		<category><![CDATA[Quake]]></category>

		<guid isPermaLink="false">http://blogs.adobe.com/flascc/?p=367</guid>
		<description><![CDATA[Learning by example is always the best way to understand a new tool. So with the FlasCC SDK we ship a number of fully working examples of open source libraries being compiled and used within SWFs. By reading the documentation &#8230; <a href="http://blogs.adobe.com/flascc/2013/01/04/sample-c-libraries-running-in-the-browser-via-flash-player/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Learning by example is always the best way to understand a new tool. So with the FlasCC SDK we ship a number of fully working examples of open source libraries being compiled and used within SWFs. By reading the <a href="http://www.adobe.com/devnet-docs/flascc/docs/Reference.html" target="_blank">documentation</a> and investigating these examples you should be able to get a good understanding of how best to use FlasCC.<br />
<span id="more-367"></span></p>
<p>These projects can be found in the /samples/ folder of the FlasCC SDK which can be downloaded from the <a href="http://gaming.adobe.com/getstarted/" target="_blank">Adobe Gaming Tools</a> page.</p>
<h2>Box2D</h2>
<p>The Box2D example creates a SWC from the C++ <a href="http://box2d.org/" target="_blank">Box2D</a> library. SWIG is used to automate the process of generating all of the wrapper code which is incredibly helpful as it avoids you writing lots of tedious and bug-prone wrapper code by hand. Having the ActionScript API auto-generated like this can be an important timesaver if you need to update the underlying C++ code.</p>
<h2>Bullet Physics</h2>
<p><a href="http://bulletphysics.org/wordpress/" target="_blank">Bullet</a> is a large C++ library with roughly 130 thousand lines of code. It is used throughout the industry for both offline and real-time physics simulations.  It not only supports basic rigid-body physics, but also more advanced soft-body physics for simulating deformable objects such as cloth. Creating a SWC with an ActionScript API for Bullet is a trivial process and allows ActionScript developers high-performance access to this great library. The demo we ship with the FlasCC SDK shows how to create a simple 3D scene using the Away3D library and how Bullet can be used to provide physical simulation for the objects in the Away3D scenegraph. </p>
<p>Live Demo: <a href="http://www.cmodule.org/Away3DBulletPhysics/" target="_blank">http://www.cmodule.org/Away3DBulletPhysics/</a></p>
<h2>Lua</h2>
<p>Due to its small size and how easy it is to embed within other environments a lot of people are choosing <a href="http://www.lua.org/" target="_blank">Lua</a> as their scripting language of choice. The reference implementation of the Lua interpreter is written in C and is designed to be compiled as a library and linked into other projects. As with the other examples we used SWIG here to automatically generate the AS3 bindings. We also write some interop code by hand that reflects the AS3 API into Lua so that Lua programs can be run within the Flash Player and can interoperate with the Flash API set. We wrote a simple real-world example that shows a Starling-based AS3 application that is controlled by a Lua script that can be updated while the SWF is executing.</p>
<p>Live Demo: <a href="http://www.cmodule.org/lua/" target="_blank">http://www.cmodule.org/lua/</a></p>
<p>Click &#8220;Run Script&#8221; to execute the Lua script.  Note that you can edit the script live and click &#8220;Run Script&#8221; again to execute your latest changes.  For example try changing the line &#8220;gravity = 5&#8243; to &#8220;gravity = 0.01&#8243; and click Run Script again to see your changes.</p>
<h2>Quake 1</h2>
<p>This was the killer demo for the original Alchemy prototype and showed that complex C code could be compiled correctly into a SWF with excellent runtime performance. The game might be old, but it still looks surprisingly good and performs better when compiled with FlasCC than it did with the old Alchemy prototype. </p>
<p>For a more modern killer demo take a look at the FlasCC-compiled <a href="http://www.unrealengine.com/flash" target="_blank">Unreal Engine live demo</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.adobe.com/flascc/2013/01/04/sample-c-libraries-running-in-the-browser-via-flash-player/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Troubleshooting the &#8220;Could not create the Java Virtual Machine&#8221; error</title>
		<link>http://blogs.adobe.com/flascc/2012/12/20/troubleshooting-the-could-not-create-the-java-virtual-machine-error/</link>
		<comments>http://blogs.adobe.com/flascc/2012/12/20/troubleshooting-the-could-not-create-the-java-virtual-machine-error/#comments</comments>
		<pubDate>Thu, 20 Dec 2012 00:32:32 +0000</pubDate>
		<dc:creator>gauravj</dc:creator>
				<category><![CDATA[FlasCC]]></category>
		<category><![CDATA[g++]]></category>
		<category><![CDATA[gcc]]></category>
		<category><![CDATA[JVM]]></category>

		<guid isPermaLink="false">http://blogs.adobe.com/flascc/?p=389</guid>
		<description><![CDATA[This post explains why you might see the &#8220;Could not create the Java Virtual Machine&#8221; error when creating a SWF or SWC in FlasCC. When the FlasCC binaries invoke the JVM, the default heap size is set to 2GB. If &#8230; <a href="http://blogs.adobe.com/flascc/2012/12/20/troubleshooting-the-could-not-create-the-java-virtual-machine-error/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>This post explains why you might see the &#8220;Could not create the Java Virtual Machine&#8221; error when creating a SWF or SWC in FlasCC.<br />
<span id="more-389"></span></p>
<p>When the FlasCC binaries invoke the JVM, the default heap size is set to 2GB. If you are using FlasCC on a machine that does not have sufficient memory, you may see errors like:<br />
<code><br />
Error: Failed to execute compiler: Error occurred during initialization of VM<br />
Could not reserve enough space for object heap<br />
Error: Could not create the Java Virtual Machine.<br />
Error: A fatal exception has occurred. Program will exit.<br />
</code></p>
<p>If you run into these errors, you can tweak the JVM heap size by adding the <code>-jvmopt</code> option to the command line options, for example:<br />
<code><br />
gcc <strong>-jvmopt="-Xmx1024M"</strong> hello.c -o -emit-swf -o hello.swf<br />
</code></p>
<p>Also if you are running on a machine that has spare memory, then you can use the same <code>-jvmopt</code> option to bump up the heap size from its default size. </p>
<p>If you run into issues please ask questions in the <a href="http://forums.adobe.com/community/game_developers/flascc" target="_blank">FlasCC forums</a>. </p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.adobe.com/flascc/2012/12/20/troubleshooting-the-could-not-create-the-java-virtual-machine-error/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Bringing OpenGL C/C++ code to the web with FlasCC</title>
		<link>http://blogs.adobe.com/flascc/2012/12/14/bringing-opengl-cc-code-to-the-web-with-flascc/</link>
		<comments>http://blogs.adobe.com/flascc/2012/12/14/bringing-opengl-cc-code-to-the-web-with-flascc/#comments</comments>
		<pubDate>Fri, 14 Dec 2012 23:38:57 +0000</pubDate>
		<dc:creator>alexmac</dc:creator>
				<category><![CDATA[FlasCC]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[OpenGL]]></category>

		<guid isPermaLink="false">http://blogs.adobe.com/flascc/?p=372</guid>
		<description><![CDATA[Stage3D allows GPU accelerated 3D content to run in the Flash Player accross operating systems and browsers. We have a number of interesting libraries that will help you bring your OpenGL C/C++ code to the web with FlasCC. GLS3D The &#8230; <a href="http://blogs.adobe.com/flascc/2012/12/14/bringing-opengl-cc-code-to-the-web-with-flascc/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p><a href="http://www.adobe.com/devnet/flashplayer/stage3d.html" target="_blank">Stage3D</a> allows GPU accelerated 3D content to run in the Flash Player accross operating systems and browsers. We have a number of interesting libraries that will help you bring your OpenGL C/C++ code to the web with FlasCC.<br />
<span id="more-372"></span></p>
<h2>GLS3D</h2>
<p>The GLS3D library is an open source project we started to provide a basic OpenGL implementation for FlasCC users targeting Stage3D. </p>
<p>Source Code: <a href="https://github.com/adobe/gls3d" target="_blank">https://github.com/adobe/gls3d</a><br />
Live Demo: <a href="http://cmodule.org/neverball" target="_blank">http://cmodule.org/neverball</a></p>
<h2>FreeGLUT</h2>
<p>The GLUT library was created to make it easier to write cross-platform OpenGL based apps. I&#8217;ve implemented a Stage3D backend for the FreeGLUT library and used it in conjunction with the GLS3D project to compile some of the popular <a href="http://nehe.gamedev.net/" target="_blank">NeHe OpenGL tutorials</a>.</p>
<p>Source Code: <a href="https://github.com/alexmac/alcfreeglut" target="_blank">https://github.com/alexmac/alcfreeglut</a><br />
Live Demo: <a href="http://www.cmodule.org/nehe/" target="_blank">http://www.cmodule.org/nehe/</a></p>
<h2>GLSL To AGAL</h2>
<p>If you&#8217;ve investigated the Stage3D API you&#8217;ll know that the shader format is a custom bytecode format designed to be easily compiled down to DirectX bytecode or GLSL depending on the platform the Flash Player is running on. Sadly this makes it hard for humans to write. This project is based on the open-source Mesa codebase and contains a full GLSL parser and optimizer hooked up to a custom AGAL backend so that GLSL shaders can be compiled and optimized down to AGAL bytecode. It can be used offline as a pre-processing step within your applications asset creation workflow or at runtime by compiling the library to a SWC with FlasCC and using it in your SWF.  </p>
<p>The repository also includes a precompiled SWC so that you can get started with it immediately. </p>
<p>Source Code: <a href="https://github.com/adobe/glsl2agal" target="_blank">https://github.com/adobe/glsl2agal</a><br />
Live Demo: <a href="http://adobe.github.com/glsl2agal/" target="_blank">http://adobe.github.com/glsl2agal/</a></p>
<h2>Starling Filter Playground</h2>
<p>Starling 1.2 supports AGAL based filters that can be applied to any Sprite to alter the way they render. Rather than writing the filter by hand with AGAL asm its possible to hook up the GLSL2AGAL project to Starling so that these Filters can be written using GLSL. Modifying the shader in the UI causes the filter to update in realtime. </p>
<p>Source Code: <a href="https://github.com/alexmac/StarlingFilterPlayground" target="_blank">https://github.com/alexmac/StarlingFilterPlayground</a><br />
Live Demo: <a href="http://alexmac.github.com/StarlingFilterPlayground/" target="_blank">http://alexmac.github.com/StarlingFilterPlayground/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.adobe.com/flascc/2012/12/14/bringing-opengl-cc-code-to-the-web-with-flascc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Operating on ActionScript objects in C++</title>
		<link>http://blogs.adobe.com/flascc/2012/12/08/operating-on-actionscript-objects-in-c/</link>
		<comments>http://blogs.adobe.com/flascc/2012/12/08/operating-on-actionscript-objects-in-c/#comments</comments>
		<pubDate>Sat, 08 Dec 2012 01:33:49 +0000</pubDate>
		<dc:creator>stshongr</dc:creator>
				<category><![CDATA[FlasCC]]></category>
		<category><![CDATA[SWC]]></category>

		<guid isPermaLink="false">http://blogs.adobe.com/flascc/?p=176</guid>
		<description><![CDATA[FlasCC allows you to create a SWC file from a C++ library. This is useful if you have an existing ActionScript project and want to add some logic that is already written in C++. This post demonstrates how you can &#8230; <a href="http://blogs.adobe.com/flascc/2012/12/08/operating-on-actionscript-objects-in-c/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>FlasCC allows you to create a SWC file from a C++ library. This is useful if you have an existing ActionScript project and want to add some logic that is already written in C++.  This post demonstrates how you can operate on ActionScript objects that were passed as parameters into functions of a C++ library.<br />
<span id="more-176"></span></p>
<p>This post assumes you already know how to compile a SWC in FlasCC.  If you do not know how see the <a href="http://www.adobe.com/devnet-docs/flascc/docs/samples.html#T5" target="_blank">samples/05_SWC</a> sample application that ships with the FlasCC SDK.</p>
<p>The <code><a href="http://www.adobe.com/devnet-docs/flascc/docs/capidocs/as3plusplus.html" target="_blank">AS3++.h</a></code> library exposes some functions to make it easier to operate on ActionScript objects within C++. </p>
<h2>Getting a property</h2>
<p>Getting the value of a property of an ActionScript object is pretty straightforward by using the <code><a href="http://www.adobe.com/devnet-docs/flascc/docs/capidocs/as3plusplus.html#getproperty" target="_blank">getproperty()</a></code> function.</p>
<p>In the sample code below the <code>getDelta()</code> C++ function demonstrates this.</p>
<h2>Setting a property</h2>
<p>Setting the value of a property is also straightforward by using the <code><a href="http://www.adobe.com/devnet-docs/flascc/docs/capidocs/as3plusplus.html#setproperty" target="_blank">setproperty()</a></code> function.</p>
<p>In the sample code below the <code>setDelta()</code> C++ function demonstrates this.</p>
<h2>Calling a method</h2>
<p>Calling a method is slightly more involved as you need to first use <code>getproperty()</code> on the name of the method to get a Function var that represents that method.  Then pass that object into the <code><a href="http://www.adobe.com/devnet-docs/flascc/docs/capidocs/as3plusplus.html#call" target="_blank">call()</a></code> or <code><a href="http://www.adobe.com/devnet-docs/flascc/docs/capidocs/as3plusplus.html#call_v" target="_blank">call_v()</a></code> functions.</p>
<p>In the sample code below the <code>getString()</code> C++ function demonstrates this.</p>
<h2>Sample Code</h2>
<p>Here is a sample C++ library that demonstrates how to do each of these operations.</p>
<p>When compiling this library using g++ remember to set the <code>-lAS3++</code> flag as described in the <a href="http://www.adobe.com/devnet-docs/flascc/docs/capidocs/as3plusplus.html" target="_blank">AS3++ documentation</a>.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#include &lt;stdio.h&gt;</span>
<span style="color: #339933;">#include &quot;AS3/AS3.h&quot;</span>
<span style="color: #339933;">#include &quot;AS3/AS3++.h&quot;</span>
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;">////</span>
<span style="color: #666666; font-style: italic;">//</span>
<span style="color: #666666; font-style: italic;">// Get a property of an ActionScript object in C++</span>
<span style="color: #666666; font-style: italic;">//</span>
<span style="color: #666666; font-style: italic;">////</span>
&nbsp;
<span style="color: #993333;">void</span> getDelta<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> __attribute__<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>used<span style="color: #339933;">,</span>
    annotate<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;as3import:flash.events.MouseEvent&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
    annotate<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;as3sig:public function getDelta(m:MouseEvent):int&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
    annotate<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;as3package:MyLibrary&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #993333;">void</span> getDelta<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// marshall the AS3 parameter into a C++ variable</span>
    AS3<span style="color: #339933;">::</span><span style="color: #202020;">local</span><span style="color: #339933;">::</span><span style="color: #202020;">var</span> mouseEvent<span style="color: #339933;">;</span>
    AS3_GetVarxxFromVar<span style="color: #009900;">&#40;</span>mouseEvent<span style="color: #339933;">,</span> m<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// now that we have it in C++ let's get a property on that object</span>
    AS3<span style="color: #339933;">::</span><span style="color: #202020;">local</span><span style="color: #339933;">::</span><span style="color: #202020;">var</span> propertyName <span style="color: #339933;">=</span> AS3<span style="color: #339933;">::</span><span style="color: #202020;">local</span><span style="color: #339933;">::</span><span style="color: #202020;">internal</span><span style="color: #339933;">::</span><span style="color: #202020;">new_String</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;delta&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    AS3<span style="color: #339933;">::</span><span style="color: #202020;">local</span><span style="color: #339933;">::</span><span style="color: #202020;">var</span> outputValue <span style="color: #339933;">=</span> AS3<span style="color: #339933;">::</span><span style="color: #202020;">local</span><span style="color: #339933;">::</span><span style="color: #202020;">internal</span><span style="color: #339933;">::</span><span style="color: #202020;">getproperty</span><span style="color: #009900;">&#40;</span>mouseEvent<span style="color: #339933;">,</span> propertyName<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// convert the var to a scalar</span>
    <span style="color: #993333;">int</span> output <span style="color: #339933;">=</span> AS3<span style="color: #339933;">::</span><span style="color: #202020;">local</span><span style="color: #339933;">::</span><span style="color: #202020;">internal</span><span style="color: #339933;">::</span><span style="color: #202020;">int_valueOf</span><span style="color: #009900;">&#40;</span>outputValue<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// return that scalar value</span>
    AS3_Return<span style="color: #009900;">&#40;</span>output<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;">////</span>
<span style="color: #666666; font-style: italic;">//</span>
<span style="color: #666666; font-style: italic;">// Set a property on an ActionScript object in C++</span>
<span style="color: #666666; font-style: italic;">//</span>
<span style="color: #666666; font-style: italic;">////</span>
&nbsp;
<span style="color: #993333;">void</span> setDelta<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> __attribute__<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>used<span style="color: #339933;">,</span>
    annotate<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;as3import:flash.events.MouseEvent&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
    annotate<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;as3sig:public function setDelta(m:MouseEvent):void&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
    annotate<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;as3package:MyLibrary&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #993333;">void</span> setDelta<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// marshall the AS3 parameter into a C++ variable</span>
    AS3<span style="color: #339933;">::</span><span style="color: #202020;">local</span><span style="color: #339933;">::</span><span style="color: #202020;">var</span> mouseEvent<span style="color: #339933;">;</span>
    AS3_GetVarxxFromVar<span style="color: #009900;">&#40;</span>mouseEvent<span style="color: #339933;">,</span> m<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// now that we have it in C++ let's set a property on that object</span>
    AS3<span style="color: #339933;">::</span><span style="color: #202020;">local</span><span style="color: #339933;">::</span><span style="color: #202020;">var</span> propertyName <span style="color: #339933;">=</span> AS3<span style="color: #339933;">::</span><span style="color: #202020;">local</span><span style="color: #339933;">::</span><span style="color: #202020;">internal</span><span style="color: #339933;">::</span><span style="color: #202020;">new_String</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;delta&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    AS3<span style="color: #339933;">::</span><span style="color: #202020;">local</span><span style="color: #339933;">::</span><span style="color: #202020;">var</span> newValue <span style="color: #339933;">=</span> AS3<span style="color: #339933;">::</span><span style="color: #202020;">local</span><span style="color: #339933;">::</span><span style="color: #202020;">internal</span><span style="color: #339933;">::</span><span style="color: #202020;">new_int</span><span style="color: #009900;">&#40;</span><span style="color: #0000dd;">5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    AS3<span style="color: #339933;">::</span><span style="color: #202020;">local</span><span style="color: #339933;">::</span><span style="color: #202020;">internal</span><span style="color: #339933;">::</span><span style="color: #202020;">setproperty</span><span style="color: #009900;">&#40;</span>mouseEvent<span style="color: #339933;">,</span> propertyName<span style="color: #339933;">,</span> newValue<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;">////</span>
<span style="color: #666666; font-style: italic;">//</span>
<span style="color: #666666; font-style: italic;">// Call a method of an ActionScript object in C++</span>
<span style="color: #666666; font-style: italic;">//</span>
<span style="color: #666666; font-style: italic;">////</span>
&nbsp;
<span style="color: #993333;">void</span> getString<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> __attribute__<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>used<span style="color: #339933;">,</span>
    annotate<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;as3import:flash.events.MouseEvent&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
    annotate<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;as3sig:public function getString(m:MouseEvent):String&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
    annotate<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;as3package:MyLibrary&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #993333;">void</span> getString<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// marshall the AS3 parameter into a C++ variable</span>
    AS3<span style="color: #339933;">::</span><span style="color: #202020;">local</span><span style="color: #339933;">::</span><span style="color: #202020;">var</span> mouseEvent<span style="color: #339933;">;</span>
    AS3_GetVarxxFromVar<span style="color: #009900;">&#40;</span>mouseEvent<span style="color: #339933;">,</span> m<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// demonstrate how to call a function of that object from C++</span>
    AS3<span style="color: #339933;">::</span><span style="color: #202020;">local</span><span style="color: #339933;">::</span><span style="color: #202020;">var</span> functionName <span style="color: #339933;">=</span> AS3<span style="color: #339933;">::</span><span style="color: #202020;">local</span><span style="color: #339933;">::</span><span style="color: #202020;">internal</span><span style="color: #339933;">::</span><span style="color: #202020;">new_String</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;toString&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">// first get the property of the object called &quot;toString&quot; which is a Function var</span>
    AS3<span style="color: #339933;">::</span><span style="color: #202020;">local</span><span style="color: #339933;">::</span><span style="color: #202020;">var</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #339933;">=</span> AS3<span style="color: #339933;">::</span><span style="color: #202020;">local</span><span style="color: #339933;">::</span><span style="color: #202020;">internal</span><span style="color: #339933;">::</span><span style="color: #202020;">getproperty</span><span style="color: #009900;">&#40;</span>mouseEvent<span style="color: #339933;">,</span> functionName<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// then call that Function object (in this case it takes no parameters)</span>
    AS3<span style="color: #339933;">::</span><span style="color: #202020;">local</span><span style="color: #339933;">::</span><span style="color: #202020;">var</span> output <span style="color: #339933;">=</span> AS3<span style="color: #339933;">::</span><span style="color: #202020;">local</span><span style="color: #339933;">::</span><span style="color: #202020;">internal</span><span style="color: #339933;">::</span><span style="color: #202020;">call</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">function</span><span style="color: #339933;">,</span> AS3<span style="color: #339933;">::</span><span style="color: #202020;">local</span><span style="color: #339933;">::</span><span style="color: #202020;">internal</span><span style="color: #339933;">::</span>_null<span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> NULL<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Since AS3_Return (as shown in getDelta()) can only accept a scalar value we need</span>
    <span style="color: #666666; font-style: italic;">// to marshall this C++ object into an ActionScript String and return it using AS3_ReturnVar</span>
    AS3_DeclareVar<span style="color: #009900;">&#40;</span>asOutputString<span style="color: #339933;">,</span> String<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    AS3_CopyVarxxToVar<span style="color: #009900;">&#40;</span>asOutputString<span style="color: #339933;">,</span> output<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    AS3_ReturnAS3Var<span style="color: #009900;">&#40;</span>asOutputString<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">int</span> main<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// The SWC still needs a main() function.  </span>
    <span style="color: #666666; font-style: italic;">// See the code comments in samples/05_SWC for more details.</span>
    AS3_GoAsync<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>And here is a sample ActionScript application that demonstrates how to call the methods in the SWC generated from that C++ library:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="actionscript" style="font-family:monospace;">package <span style="color: #66cc66;">&#123;</span>
    <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">Sprite</span>;
    <span style="color: #0066CC;">import</span> flash.<span style="color: #0066CC;">text</span>.<span style="color: #0066CC;">TextField</span>;
    <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">Event</span>;
    <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">MouseEvent</span>;
    <span style="color: #0066CC;">import</span> MyLibrary.<span style="color: #006600;">CModule</span>;
&nbsp;
    <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> demo <span style="color: #0066CC;">extends</span> Sprite <span style="color: #66cc66;">&#123;</span>
        <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> demo<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
            addEventListener<span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">ADDED_TO_STAGE</span>, initCode<span style="color: #66cc66;">&#41;</span>;
        <span style="color: #66cc66;">&#125;</span>
&nbsp;
        <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> initCode<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">var</span> tf:<span style="color: #0066CC;">TextField</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">TextField</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
            addChild<span style="color: #66cc66;">&#40;</span>tf<span style="color: #66cc66;">&#41;</span>;
&nbsp;
            <span style="color: #808080; font-style: italic;">// start the FlasCC library</span>
            MyLibrary.<span style="color: #006600;">CModule</span>.<span style="color: #006600;">startAsync</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
            <span style="color: #808080; font-style: italic;">// a sample ActionScript object</span>
            <span style="color: #000000; font-weight: bold;">var</span> me:MouseEvent = <span style="color: #000000; font-weight: bold;">new</span> MouseEvent<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;click&quot;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
            <span style="color: #808080; font-style: italic;">//</span>
            <span style="color: #808080; font-style: italic;">// Get a property</span>
            <span style="color: #808080; font-style: italic;">//</span>
            tf.<span style="color: #006600;">appendText</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;delta=&quot;</span> + MyLibrary.<span style="color: #006600;">getDelta</span><span style="color: #66cc66;">&#40;</span>me<span style="color: #66cc66;">&#41;</span> + <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
            <span style="color: #808080; font-style: italic;">//</span>
            <span style="color: #808080; font-style: italic;">// Set a property</span>
            <span style="color: #808080; font-style: italic;">//</span>
            MyLibrary.<span style="color: #006600;">setDelta</span><span style="color: #66cc66;">&#40;</span>me<span style="color: #66cc66;">&#41;</span>;
            tf.<span style="color: #006600;">appendText</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;delta=&quot;</span> + me.<span style="color: #006600;">delta</span> + <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
            <span style="color: #808080; font-style: italic;">//</span>
            <span style="color: #808080; font-style: italic;">// Call a method</span>
            <span style="color: #808080; font-style: italic;">//</span>
            tf.<span style="color: #006600;">appendText</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;toString=&quot;</span> + MyLibrary.<span style="color: #006600;">getString</span><span style="color: #66cc66;">&#40;</span>me<span style="color: #66cc66;">&#41;</span> + <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
        <span style="color: #66cc66;">&#125;</span>
    <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://blogs.adobe.com/flascc/2012/12/08/operating-on-actionscript-objects-in-c/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>FlasCC 1.0 Released</title>
		<link>http://blogs.adobe.com/flascc/2012/12/04/flascc-1-0-released/</link>
		<comments>http://blogs.adobe.com/flascc/2012/12/04/flascc-1-0-released/#comments</comments>
		<pubDate>Tue, 04 Dec 2012 23:39:51 +0000</pubDate>
		<dc:creator>stshongr</dc:creator>
				<category><![CDATA[FlasCC]]></category>

		<guid isPermaLink="false">http://blogs.adobe.com/flascc/?p=288</guid>
		<description><![CDATA[The Adobe Flash C++ Compiler (FlasCC) is a new tool chain that allows game developers to take native games and game engines for PCs, Xbox 360, PlayStation 3, and iOS and compile them to run directly on the web across &#8230; <a href="http://blogs.adobe.com/flascc/2012/12/04/flascc-1-0-released/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>The Adobe Flash C++ Compiler (FlasCC) is a new tool chain that allows game developers to take native games and game engines for PCs, Xbox 360, PlayStation 3, and iOS and compile them to run directly on the web across browsers on over 1.3 billion connected PCs using Adobe Flash Player.<br />
<span id="more-288"></span><br />
FlasCC 1.0 was <a href="http://blogs.adobe.com/digitalmedia/2012/12/adobe-delivers-new-game-developer-tools-in-creative-cloud/" target="_blank">officially released</a> today as part of the Game Developer tools in the Adobe Creative Cloud.</p>
<p><a href="http://gaming.adobe.com/getstarted/" target="_blank">Download the FlasCC SDK</a> as part of a Creative Cloud subscription.</p>
<p>If you have questions about the FlasCC SDK check out the <a href="http://forums.adobe.com/community/game_developers/flascc" target="_blank">FlasCC community forums</a>.</p>
<p>Also check out these other game developer tools that shipped today:</p>
<p><strong><a href="http://gaming.adobe.com/technologies/scout/" target="_blank">Adobe Scout</a></strong> &#8211; an advanced profiling tool designed to help you optimize performance of your SWF content.</p>
<p><strong><a href="http://gaming.adobe.com/technologies/gamingsdk/" target="_blank">The Adobe Gaming SDK</a></strong> &#8211; a simple starting point for creating ActionScript-based games using  popular open source 2D and 3D frameworks (Starling, Feathers, and Away3D).</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.adobe.com/flascc/2012/12/04/flascc-1-0-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
