Thursday, January 31, 2008

Map SharedObject.getRemote() to .NET Class

Alright, time to start a blog entry. I'm trying to figure out in FluorineFx how to map SharedObject.getRemote() so that calling it from a client grabs an instance of a specific class rather than just a generic object. On the server this would mean a .NET class whilst on the client, I'd assume, would use registerClassAlias() to indicate an ActionScript class.

At this point I have no idea how, I'm just planting the seed.

Saturday, January 26, 2008

LCDS, fds.swc, [Managed]

Building a lot of FluorineFx samples from Adobe Flex Builder 2 yields the following error:
configuration variable 'compiler.library-path' value contains unknown token 'LCDS'
The IDE is utterly unhelpful as to where this is coming from (it says the error comes from line -1 if you view its properties), but you'll find it due to the following line in the .actionScriptProperties file:
<libraryPathEntry kind="3" path="${LCDS}\libs\fds.swc" linkType="1"/>
Within the GUI you'll find this entry listed under the project properties in the Flex Build Path section under the Library path tab. Deleting it is the easiest solution, but then another error might surface:
Interface IManaged was not found.
This is being caused by the [Managed] class attribute which, again, you can safely delete.

But what is IManaged, why isn't LCDS defined, and where the heck is fds.swc?

It turns out LCDS stands for LiveCycle Data Services which it turns out is part of some Adobe thing for Java. This supercedes Flex Data Services which is where the filename fds.swc comes from. You'd need to install Adobe LiveCycle Data Services in order to have that compiler identifier as well as the fds.swc file, but I don't know where to tell you to go, nor do I want to spend an hour finding out.

- -

Okay, I found Adobe LiveCycle Data Services ES which you can download for free (only 136 megabytes ... uh, yeah) if you register. I must warn you that working through their web forms is an arduous task, especially if someone else used your email address in the past because they don't like registering to download crap anymore than you do.

- -

Dammit, nothing like hitting a dead end. The fds.swc from the above thing is for ColdFusion 8 and isn't compatible with Flex Builder. The result is a broken SWF that throws weird exceptions like this:
VerifyError: Error #1053: Illegal override of subtopic in mx.messaging.Consumer.
at flash.display::MovieClip /nextFrame()
at mx.managers::SystemManager /::deferredNextFrame()
at mx.managers::SystemManager /::preloader_initProgressHandler()
at flash.events::EventDispatcher /flash.events:EventDispatcher::dispatchEventFunction()
at flash.events::EventDispatcher /dispatchEvent()
at mx.preloaders::Preloader /::timerHandler()
at flash.utils::Timer /flash.utils:Timer::_timerDispatch()
at flash.utils::Timer /flash.utils:Timer::tick()
- -

Ah ha! I didn't have these: Hotfix 2 and Hotfix 3. After installing those and rebuilding the above error went away.

Now if I could just figure out how to define the compiler symbol LCDS!

Thursday, January 24, 2008

Flash Chat Example

Unfortunately, I couldn't easily find any decent place to host FluorineFx for free (or indeed, any ASP.NET application) otherwise there'd be something here to simply click on and try. As it is, you'll need to grab my source code and build it yourself. Everything you need to do this is freely available.

Free Software Requirements

  • IIS: comes with Windows 2000, XP, Vista as long as you have Professional.
  • Visual C# Express 2008 from Microsoft: Web Edition is not required since you'll be running the ASP.NET code from IIS.
  • Flex 2 SDK from Adobe: Comes with MXMLC command-line compiler.
  • My Examples' Source Code: the FluorineFx DLL's are provided under the Bin directory.

Installation

  1. Create an IIS Virtual Directory on your localhost called FluorineFx and point it to the base folder of my examples, wherever you put them on your machine.
  2. Build Chat.swf from Chat.mxml with MXMLC and/or Obrunski. This is as simple as bringing up a command prompt and typing mxmlc Chat.mxml; assuming you have the Flex SDK's Bin directory on your PATH.
  3. Build Chat.dll from Chat.csproj with Visual C#. It'll probably ask you to create a solution file called Chat.sln, just drop it in the same directory. The output is already set to go into the main Bin directory where the other assemblies already are.
  4. If you don't want/need to run Chat.swf directly (e.g. not embed from web page on localhost) then you're done. Otherwise create a plain text file called FluorineFx.cfg, put one line in it that is the full path to the SWF's base directory, and then copy that to C:\Documents and Settings\user.name\Application Data\Macromedia\Flash Player\#Security\FlashPlayerTrust\.

Running

Visit http://localhost/FluorineFx/Chat.aspx and you should get a nice big gray screen with a login prompt entitled "Connect". Go ahead and type anything in, I bet you'll see this:

Authentication failed: Requested access is not allowed

Don't be frightened, this is just due to the fact that this example doesn't have any real way to authenticate users so what it does is create a new one if it doesn't recognize what you typed in. So you might see this error more of a "Successfully created user" response. Click "OK", retype the password, and then click "Connect" again and voila (hopefully).

Problems and Solutions

You have a real problem if you see this:

Authentication failed: Send failed


This means that the FluorineFx service is not running in IIS and therefore not taking connections or receiving data. Take a look at the log\fluorine.log for clues and/or check the system event log. A couple common issues are:
  • Port 1939 is already in use. Change this in the services-config/channels/channel-definition/endpoint node of WEB-INF/flex/services-config.xml.
  • You launched Chat.swf directly rather than from IIS. The web page must be loaded at least once to start the FluorineFx service within IIS, otherwise there's nothing to connect to!

Credit

The Chat example is a slightly modified version of the one that comes with FluorineFx 1.0.0.5 and all credit should be deferred to its creators. I'm just trying to get a good grasp on this stuff!

Saturday, January 05, 2008

Security Sandbox Violation w/ localhost Connections

If you've ever developed a SWF locally which is only trying to access localhost, you've probably been frustrated by the sandbox violation errors that come up. I wondered how the Flex Builder IDE was able to run SWF's and have them create sockets to localhost without getting the same errors. I created a small test called SocketSandboxError.as that simply tries to make a socket connection to localhost and I launched it using Flash Player 9.

SocketSandboxError.as

package 
{
import flash.display.Sprite;
import flash.net.Socket;

public class SocketSandboxError extends Sprite
{
private var _connection:Socket;

public function SocketSandboxError()
{
_connection = new Socket();
_connection.connect("localhost", 8080);
}
}
}

Predictably the first result is the sandbox error you know and love:
Error #2044: Unhandled SecurityErrorEvent:. text=Error #2048: Security sandbox violation: file:///C|/Stuff/FlashTest/src/SocketSandboxError.swf cannot load data from localhost:8080.
at SocketSandboxError$iinit()
I then used FileMon to see what files were being touched and found C:\Documents and Settings\username\Application Data\Flash Player\#Security\FlashPlayerTrust\flexbuilder.cfg. Here you can add directories or specific SWF's that basically get full trust and can access network resources and such; obviously something you only want to utilize while developing locally. I added the directory containing SocketSandboxError.as: C:\Stuff\FlashTest\src.

After making this change and re-running the application I got this different error:
Error #2044: Unhandled IOErrorEvent:. text=Error #2031: Socket Error.
at SocketSandboxError$iinit()
Success! This means Flash is actually trying to make the connection, but unless you have something listening on that port (8080 in this example, which I don't) this error will occur.

References:

Update @ 24 JAN 2008: Any file you put in the C:\Documents and Settings\user.name\Application Data\Macromedia\Flash Player\#Security\FlashPlayerTrust\ folder seems to be parsed. I'm planning on using this fact as a "debug" feature of Obrunski, e.g. before launching the SWF it will create/overwrite obrunski.cfg with the current SWF's full path as the only entry.