<?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>GhostWire Studios &#187; FlashDevelop</title>
	<atom:link href="http://www.ghostwire.com/blog/archives/tag/flashdevelop/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ghostwire.com/blog</link>
	<description>Flash UI Components</description>
	<lastBuildDate>Thu, 22 Apr 2010 03:33:15 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>[AS3] Hiding Assets And Code By Embedding SWF Within Another SWF</title>
		<link>http://www.ghostwire.com/blog/archives/as3-hiding-assets-and-code-by-embedding-swf-within-another-swf/</link>
		<comments>http://www.ghostwire.com/blog/archives/as3-hiding-assets-and-code-by-embedding-swf-within-another-swf/#comments</comments>
		<pubDate>Fri, 21 Aug 2009 03:11:59 +0000</pubDate>
		<dc:creator>sunny</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flash AS3]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Copy Protection]]></category>
		<category><![CDATA[Encryption]]></category>
		<category><![CDATA[FlashDevelop]]></category>
		<category><![CDATA[Loader]]></category>

		<guid isPermaLink="false">http://ghostwire.com/blog/?p=709</guid>
		<description><![CDATA[The technique discussed below is fairly easy to implement and will cost nothing other than a few minutes of your time.  You can use this method in conjunction with code obfuscation, encryption or whatever other protection methods &#8211; this just adds another layer of protection.  While this isn&#8217;t going to be a 100% [...]]]></description>
			<content:encoded><![CDATA[<p>The technique discussed below is fairly easy to implement and will cost nothing other than a few minutes of your time.  You can use this method in conjunction with code obfuscation, encryption or whatever other protection methods &#8211; this just adds another layer of protection.  While this isn&#8217;t going to be a 100% foolproof protection, it is nevertheless better than no protection at all, and should help to deter most if not all casual decompiling.</p>
<p><span id="more-709"></span>As indicated in the title of this post, the basic idea here is simply to embed your actual SWF within another &#8220;shell&#8221; SWF.  It is this &#8220;shell&#8221; SWF that you will then deploy/distribute.</p>
<p><!-- --><br />
<strong>MainShell Class</strong><br />
To embed a SWF within another SWF, you can use a document class like the one below:</p>

<div class="wp_syntax"><div 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;">Loader</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">Sprite</span>;
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MainShell <span style="color: #0066CC;">extends</span> Sprite 
	<span style="color: #66cc66;">&#123;</span>		
		<span style="color: #66cc66;">&#91;</span>Embed<span style="color: #66cc66;">&#40;</span>source=<span style="color: #ff0000;">&quot;ActualSWF.swf&quot;</span>, mimeType=<span style="color: #ff0000;">&quot;application/octet-stream&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
		<span style="color: #0066CC;">private</span> <span style="color: #0066CC;">static</span> const bytes:<span style="color: #000000; font-weight: bold;">Class</span>;
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> MainShell<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
			Loader<span style="color: #66cc66;">&#40;</span>addChild<span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Loader<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">loadBytes</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> bytes<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>When this &#8220;shell&#8221; SWF is run, it will<br />
(i) create an instance of <code>flash.display.Loader</code>;<br />
(ii) add that <code>Loader</code> instance to the display list;<br />
(iii) instantiate an instance of the embedded SWF as a <code>ByteArray</code>; and<br />
(iv) load that <code>ByteArray</code> into the <code>Loader</code> instance.</p>
<p>This will work in the same way as loading an external module SWF into a host SWF, but in this case the module SWF is embedded inside the host SWF.  This is different from loading external SWFs because any external SWF can still be easily obtained from the browser&#8217;s cache and decompiled separately.</p>
<p>This set up will be completely transparent to the end-users &#8211; it will look as if the actual SWF has been run.</p>
<p><!-- --><br />
<strong>How This Works Against Decompilers</strong><br />
This protection method assumes that decompilers cannot <em>automatically</em> identify, extract and decompile the embedded binary object as a SWF.  Therefore, the assets (classes and symbols) in the &#8220;ActualSWF.swf&#8221; will no longer be directly accessible by decompilers.</p>
<p>I tried this embedding technique against the trial versions of a couple of decompilers (Sothink and Trillix) and the assets of the embedded SWF (ActionScript classes, artwork, movieclip symbols, etc.) are safely hidden from view.</p>
<p>Since this cost nothing and is so easy to implement, I would suggest you try it out and decide on your own the effectiveness of this.  Wrap one of your SWFs in a &#8220;shell&#8221; SWF as described above, and try to decompile it using one of the decompilers out there. Perhaps the non-trial versions and/or other decompilers I have not tried may be able to defeat this simple layer of protection, but even if they do&#8230;</p>
<p><!-- --><br />
<strong>Taking Things Further</strong><br />
While it is possible that makers of decompilers could eventually implement a feature to properly identify, extract and decompile embedded SWFs, you can take things further and make the protection more difficult to overcome.</p>
<p>Instead of embedding the SWF directly, you could run it through some encryption and embed the encrypted SWF &#8211; it is mime type &#8220;application/octet-stream&#8221;, so you can really embed any binary file (even invalid file types).  Subsequently, the &#8220;shell&#8221; SWF will decrypt the <code>ByteArray</code> before feeding it to the <code>loadBytes()</code> method of the <code>Loader</code> instance.</p>
<p>To be very clear though, the intention here is not exactly encryption.  The real objective here is to intentionally &#8220;corrupt&#8221; the embedded SWF, so that even if extracted, decompilers cannot easily identify and run/decompile it as a SWF standalone.</p>
<p>For the purpose of corrupting the SWF, there are countless ways &#8211; using simple encryption, bytes transpositions, append/prepend useless bytes, etc. well, you get the idea&#8230; basically anything that make the SWF file invalid, no longer executable as a SWF.  You can even split the SWF into two or more binary blobs and join them back during run-time.</p>
<p>Since there are so many different possible algorithms to corrupt the SWF, it is then practically impossible for decompilers to <em>automatically</em> identify the way to reconstruct the corrupted embedded SWF.</p>
<p><!-- --><br />
<strong>Disclaimer</strong><br />
Needless to say, if you decide to corrupt/encrypt the SWF, you must be able to reconstruct, in the &#8220;shell&#8221; SWF, the embedded binary object into a working SWF.  As a result, while we may be able to prevent automated decryption (primary objective here), do take note that this provides no protection against determined hacking (decompiling the &#8220;shell&#8221; SWF, getting the decryption logic, extracting the embedded SWF manually, decrypting it and then running the reconstructed SWF through the decompiler).</p>
<p><!-- --><br />
<strong>FlashDevelop</strong><br />
For users of the <a href="http://www.flashdevelop.org">FlashDevelop</a> IDE, you are probably aware of its SWF assets browser (unlike decompilers, SWF sniffing is used here ethically, and beautifully, for the purpose of implementing code completion, etc.).  If you attempt to browse the &#8220;shell&#8221; SWF within the FlashDevelop&#8217;s Project Manager panel, you will not see the assets (classes and symbols) in the embedded SWF.  This can be used as a way to quickly verify if a SWF is protected using the &#8220;embedding technique&#8221; discussed above.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ghostwire.com/blog/archives/as3-hiding-assets-and-code-by-embedding-swf-within-another-swf/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>[AS3] Hiding the Built-In ContextMenu Items</title>
		<link>http://www.ghostwire.com/blog/archives/as3-hiding-the-built-in-contextmenu-items/</link>
		<comments>http://www.ghostwire.com/blog/archives/as3-hiding-the-built-in-contextmenu-items/#comments</comments>
		<pubDate>Tue, 04 Aug 2009 07:15:23 +0000</pubDate>
		<dc:creator>sunny</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flash AS3]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[ContextMenu]]></category>
		<category><![CDATA[FlashDevelop]]></category>
		<category><![CDATA[Menu]]></category>
		<category><![CDATA[User Experience]]></category>
		<category><![CDATA[UX]]></category>

		<guid isPermaLink="false">http://ghostwire.com/blog/?p=578</guid>
		<description><![CDATA[UPDATE: You may also refer to Hiding the Built-In Native MenuBar (And ContextMenu Items).
In my opinion, the native right-click context menu is an odd legacy from the Flash Movies days.  It may be useful when Flash is used as a video player, for animations and cartoons, in the absence of any proper custom UI.
If [...]]]></description>
			<content:encoded><![CDATA[<p><strong>UPDATE: You may also refer to <a href="http://www.ghostwire.com/blog/archives/as3-hiding-the-built-in-native-menubar-and-contextmenu-items/">Hiding the Built-In Native MenuBar (And ContextMenu Items)</a>.</strong></p>
<p>In my opinion, the native right-click context menu is an odd legacy from the Flash Movies days.  It may be useful when Flash is used as a video player, for animations and cartoons, in the absence of any proper custom UI.</p>
<p>If you are developing Flash applications, you should consider always hiding the native right-click Flash Player context menu&#8217;s built-in items.  Sure, you cannot get rid of the context menu completely, but you should at least hide the built-in items.  It makes the application look a lot more professional because the long list of built-in items are mostly irrelevant.</p>
<p><span id="more-578"></span>If you don&#8217;t do anything about it, when end-users right-click on your Flash application, the pop-up context menu will show &#8220;Zoom In&#8221;, &#8220;Zoom Out&#8221;, &#8220;Show All&#8221;, &#8220;Quality&#8221; (and sub menu), and &#8220;Print&#8230;&#8221; &#8211; all of these should be done in-application via properly designed user interface if the application allows these features to begin with.</p>
<p>For example, allowing end-users to zoom in/out without designing the application to handle these adjustments properly can be detrimental to the user experience. And if your application handles zooming in/out, it should have the proper UI to convey the feature to end-users rather than depending on the right-click menu.</p>
<p>Likewise, &#8220;Quality&#8221; adjustment is something that should be done in-application via a proper Options dialog where graphics, sounds, and perhaps other application-specific options are made available.</p>
<p>For multiple-frame SWFs (such as would be the case if you have a preloader frame), the built-in context menu items will also include, in addition to those mentioned above, &#8220;Play&#8221;, &#8220;Loop&#8221;, &#8220;Rewind&#8221;, &#8220;Forward&#8221; and &#8220;Back&#8221; &#8211; none of which should be of any relevance to RIAs. Letting the end-user activate any of these frame-manipulation actions can potentially mess up your application.</p>
<p><!-- --><br />
<strong>HTML</strong><br />
You can get rid of the built-in context menu items via the HTML container page, by defining the Flash object&#8217;s &#8220;menu&#8221; parameter as &#8220;false&#8221;.  If you are developing using the Adobe Flash IDE, you can generate the proper HTML page by unchecking the &#8220;Display Menu&#8221; option in the File -> Publish Settings dialog (HTML tab).  If you are developing using <a href="http://www.flashdevelop.org">FlashDevelop</a>, the &#8220;menu&#8221; parameter is already set to &#8220;false&#8221; by default.</p>
<p>However, using this method, you are depending on the HTML container page to tell the SWF to hide the context menu&#8217;s built-in items &#8211; if the SWF is run outside the HTML page, the menu items will no longer be hidden.  If you cannot guarantee that the SWF will be run within the HTML page you have generated, this method will not work well.  For example, if you are developing a Flash widget whereby only the SWF itself will be distributed, the menu items will not be hidden if the SWF is ultimately shown standalone, or within a HTML page where the &#8220;menu&#8221; parameter of the Flash object is not set to &#8220;false&#8221;.</p>
<p><!-- --><br />
<strong>ActionScript</strong><br />
You can hide the built-in items of the native context menu by inserting just two lines of code:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">contextMenu</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">ContextMenu</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #0066CC;">contextMenu</span>.<span style="color: #0066CC;">hideBuiltInItems</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>You would typically insert the code into your top-level AS3 class as follows:</p>

<div class="wp_syntax"><div 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: #006600;">ui</span>.<span style="color: #0066CC;">ContextMenu</span>;
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Main <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> Main<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #0066CC;">contextMenu</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">ContextMenu</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #0066CC;">contextMenu</span>.<span style="color: #0066CC;">hideBuiltInItems</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>	
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Note: the &#8220;contextMenu&#8221; property is implemented by the <code>flash.displayObject.InteractiveObject</code> class.<br />
<em>Main -> Sprite -> DisplayObjectContainer -> InteractiveObject</em></p>
<p>In the above code, you are setting the &#8220;contextMenu&#8221; property of the top-level <code>Main</code> class instance to a new <code>ContextMenu</code> instance (where the built-in items are hidden).</p>
<p>Using this method, the instructions are internal to the SWF itself.  Whether the SWF is distributed and run standalone, or run within a HTML page, the built-in items will be hidden.  Also, regardless of the value of the &#8220;menu&#8221; parameter of the containing HTML page, the built-in items are going to be hidden (ie setting the &#8220;menu&#8221; parameter to &#8220;true&#8221; in the HTML page will not override this).</p>
<p>With the built-in menu items hidden, when the end-user right-clicks on your Flash application, the pop-up context menu will show only two items &#8211; &#8220;Settings&#8230;&#8221; and &#8220;About Adobe Flash Player&#8230;&#8221; &#8211; concise, sleek, a lot more professional looking.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ghostwire.com/blog/archives/as3-hiding-the-built-in-contextmenu-items/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Compiling Module SWFs Using FlashDevelop</title>
		<link>http://www.ghostwire.com/blog/archives/compiling-module-swfs-using-flashdevelop/</link>
		<comments>http://www.ghostwire.com/blog/archives/compiling-module-swfs-using-flashdevelop/#comments</comments>
		<pubDate>Fri, 24 Jul 2009 07:28:28 +0000</pubDate>
		<dc:creator>sunny</dc:creator>
				<category><![CDATA[Aspire UI]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Flash Components]]></category>
		<category><![CDATA[FlashDevelop]]></category>
		<category><![CDATA[Module SWF]]></category>

		<guid isPermaLink="false">http://ghostwire.com/blog/?p=439</guid>
		<description><![CDATA[Breaking a large application down into modules allows the application to be loaded in more manageable chunks.  A &#8220;module&#8221; is simply a term borrowed from Flex to refer to a child SWF that is loaded into a main (host) SWF &#8211; in our context, a &#8220;module&#8221; is just like any other SWF.  But, [...]]]></description>
			<content:encoded><![CDATA[<p>Breaking a large application down into modules allows the application to be loaded in more manageable chunks.  A &#8220;module&#8221; is simply a term borrowed from Flex to refer to a child SWF that is loaded into a main (host) SWF &#8211; in our context, a &#8220;module&#8221; is just like any other SWF.  But, if built correctly, it should be a &#8220;stripped down&#8221; SWF &#8211; it will not contain classes that already exist in the host SWF that it is going to be loaded into.  This usually means that modules cannot run standalone (which is the desired outcome in most cases, considering that the modules are intended to be loaded into the main application).</p>
<p>When using <a href="http://flashdevelop.org">FlashDevelop</a>, building a Project (pressing F8 or CTRL-ENTER) compiles a single SWF using the AS class file that has been flagged as &#8220;Always Compile&#8221;.  If you are building an application that consists of a host SWF and multiple module SWFs, FlashDevelop does not automate the job for you.</p>
<p><span id="more-439"></span><br />
<strong>Use Multiple Projects</strong><br />
One way to build modules in FlashDevelop is to set up a different Project for each module, with each Project using the same assets but different build configurations (the module class in each Project is flagged as &#8220;Always Compile&#8221;).  The Project for a module class would be set up such that duplicate classes are excluded (via compiler options). However, this can get troublesome and difficult to manage/maintain.</p>
<p><!-- --><br />
<strong>Use Quick Build</strong><br />
What you can do is stick to a single Project &#8211; when building the Project, the resulting SWF will be the main (host) SWF.  Modules are built using the Quick Build command, accessed via the menu -> Tools -> Flash Tools -> Build Current File (CTRL-F8). This compiles the currently open class file, so you need to open the module class you want to compile and then press CTRL-F8.</p>
<p>The Quick Build command ignores your Project settings, so in order for this to work, you need to insert build options into each module class file. At the top of each module class, insert the following:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/**
* @mxmlc -o=bin/ClassName.swf -external-library-path=AspireUIStandard.swc
*/</span></pre></div></div>

<p>The above is only an example, you can also specify other MXMLC options (optimize, default-size, etc.).  In the above example, we exclude the classes in the AspireUIStandard.swc from being compiled into the module SWF.  If you are using other libraries that are going to exist in the host SWF, remember to exclude them too.</p>
<p>To make testing easy, you can do the following:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/**
* @mxmlc -o=bin/ClassName.swf -l=AspireUIStandard.swc
* //@mxmlc -o=bin/ClassName.swf -external-library-path=AspireUIStandard.swc
*/</span></pre></div></div>

<p>-l is alias for -compiler.library-path<br />
Use that when you want to compile the module for testing standalone.</p>
<p><!-- --><br />
<strong>&#8220;exclude.xml&#8221;</strong><br />
Instead of using the -external-library-path option, you can also use an &#8220;exclude.xml&#8221; file and the -load-externs option.</p>
<p>Generate an &#8220;exclude.xml&#8221; from the main Project &#8211; in the project settings, compiler options, under &#8220;Additional Compiler Options&#8221;, add the following:</p>
<p>-link-report exclude.xml</p>
<p>Now build your project (CTRL-ENTER).  Verify that the &#8220;exclude.xml&#8221; is generated and is in the root folder of your Project.</p>
<p>With the &#8220;exclude.xml&#8221; file generated, you can now use the -load-externs directive for your modules:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/**
* //@mxmlc -o=bin/ClassName.swf -l=AspireUIStandard.swc
* @mxmlc -o=bin/ClassName.swf -load-externs=exclude.xml
*/</span></pre></div></div>

<p>This is recommended if the host SWF may not include all the classes in the libraries the modules are using.</p>
<p><!-- --><br />
<strong>uiSWF</strong><br />
Once you have created the module SWFs, you can have your host SWF load them using the <a href="/aspireui/docs/usage/uiswf">uiSWF</a> component (<a href="/aspireui/">Aspire UI</a> Standard Edition v1.2+). This control is a subclass of uiPane, making it suitable to be plugged in as the content of a uiScrollPane instance (in which case the module should not implement its own wrapper scrollers).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ghostwire.com/blog/archives/compiling-module-swfs-using-flashdevelop/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
