Category Archives: General

XOR Cipher Encryption in ActionScript 3

I typically use an external XML file in all my applications to store configuration variables outside my compiled SWF file. This allows me to make changes to those variables without needing to recompile the SWF application. This is really helpful if you’re deploying an application to multiple environments (development, staging, production). You can deploy the same application and just have a different XML file in each environment with different values.

The values in the XML file are easily read by anyone using a proxy like Charles or Service Capture. Therefore, I decided to put a simple encryption on the values I didn’t want people to be able to easily read. XOR Cipher encryption is a simple form of two-way encryption using a known key. This key would be compiled into your SWF application. So the only way someone could decrypt your variables would be if they decompiled your SWF or guessed the key. Obviously this solution is not hack proof, but it provides a road block for anyone trying to get at these values.

The following is an ActionScript 3 class that performs this XOR encryption. This encodes/decodes the XOR encrypted value using the Base64Encoder in Flex, so if you want to use this without Flex you’ll need to remove that dependancy. The xor() method performs the XOR encryption against the key. If you run a string through this method it with return and encrypted string, and if you run that encrypted string through this method it will return your original string.

Continue reading

GZIP-Encoded HTTP Response in Adobe AIR

A common way to reduce the size of data returned over HTTP is to allow the web server to use a GZIP compression on the data. When making requests in a Flash/Flex application hosted in a web browser, the browser actually uncompresses the GZIP-encoded data before its delivered to Flash Player. Therefore, Flash/Flex developers don’t need to worry about GZIP-encoded data since its handled seemlessly behind the scenes. However, when writing an application in AIR, there is no browser to handle the GZIP compression and AIR 1.0 doesn’t have this built-in. (I assume they will add this in a dot release at some point.)

But there is a way to do it manually. The ByteArray in AS3 supports DEFLATE compression. However, you must first remove the header in the GZIP data for this to work properly. In my case, I was making a web service call using the WebService class in Flex. Since I actually needed to get at the raw binary GZIP data returned by the server, I had to change my code to use the low-level URLLoader class that is built-in to Flash Player.

Continue reading

Making Flex Web Service calls in ActionScript

I was using Flex the other day to consume some SOAP web services. However, I needed a way to modify the SOAP header in the request. This is exposed by calling the addHeader method on the service. That was easy enough, but I was finding my code difficult to manage when the service was defined using MXML and I had to add the header in ActionScript. I never really liked using MXML to define non-ui elements, so I decided to just use ActionScript to define the entire service. I found that it wasn’t as straight forward as I thought it would be so I thought I’d post my code here for the benefit of the community.

Continue reading

Adding Multiple Children in a Flex State

Many times I’ve had to add multiple children in a Flex state. Take the following simple example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
< ?xml version="1.0" encoding="utf-8"?>
<mx:application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">
	<mx:label id="topLabel" text="Top"></mx:label>
	<mx:button label="showChildren" click="currentState='children';"></mx:button>
	<mx:states>
		<mx:state name="children">
			<mx:addchild relativeTo="{topLabel}" position="after">
				<mx:label text="third"></mx:label>
			</mx:addchild>
			<mx:addchild relativeTo="{topLabel}" position="after">
				<mx:label text="second"></mx:label>
			</mx:addchild>
			<mx:addchild relativeTo="{topLabel}" position="after">
				<mx:label text="first"></mx:label>
			</mx:addchild>
		</mx:state>
	</mx:states>
</mx:application>

Continue reading

Adobe to Open-Source Remoting Code

Adobe just anounced its plans to open-source the remoting and messaging code found in Live-cycle Data Services.  The new project is called BlazeDS and is deployed as a J2EE application.  This is really huge.  There are many non-adobe or open-source projects to handle AMF remoting including classics like OpenAMF, but most don’t support AMF3 yet or are still in beta stages.

Along with this open-source project, Adobe also released its AMF3 specification.  This should allow the community to develop AMF3 solutions for other languages and platforms.  This is really great news for everyone and helps to move the AMF3 specification closer to mainstream.

http://labs.adobe.com/technologies/blazeds/

Flash Player 9 Update 3 Beta supports H.264 Video!

Flash Player now supports H.264 (mpeg4)!  Flash video just got a major kick in the pants. You can actually load .mp4, .m4v, .m4a, .mov and .3gp files using the same ActionScript API that you currently use to load FLV files.  All existing code should now work with these new files formats.  If your video player is run off dunamic data you should be able to just start dropping in quicktime and mpeg-4 files.  Crazy!

A new version of FMS is coming out soon with streaming support for these file formats.

Check out this post by Tinic for a very detailed explination of what the update includes.  I guess it was planned for Flash Player 10, but they got it in this newer version because customers really wanted it.

http://www.kaourantin.net/2007/08/what-just-happened-to-video-on-web_20.html

Flex 3 Beta 1 Released on Labs

Less than a year after Flex 2 was released Adobe hits us with the Flex 3 beta.  Flex 3 has a number of improvements including framework caching and profiling.  Framework caching will allow us to deploy SWFs that don’t include the Flex 3 framework code.  This code can instead be cached by Flash player.  Profiling is something that Flash Player that needed for years.  This allows us to see what our application is doing under the covers and help us debug performance and memory problems.

Adobe has also announced a Beta update to Flash Player 9.  Tinic Uro has a nice post on the details of this upgrade.