Saturday, February 09, 2008

Restrict SharedObject Name

FluorineFx makes it extremely easy to get Remote SharedObjects up and running, but I found it difficult to intercept the requests made against the server. My main reason for needing to do this is security: you don't want clients to be able to create arbitrary shared objects all willy nilly, otherwise you're just asking to be smacked with a big, bad bandwidth stick. Unfortunately my calls for assistance were met with silence, but I don't expect much support from developers working under the alias "The Silent Group"! So I spent the last week digging deep into the source code and trying to unravel the mysteries behind the adapters, wrappers, brokers, contexts, connections, clients, and scopes.

Thankfully, today I solved the main part of the mystery and what this post is about. Let me tell you the secret, add this to your application handler class (the one that derives from ApplicationAdapter):

Intercept SharedObject Additions

new public bool AddChildScope(IBasicScope scope)
{
if ("SharedObject" == scope.Type &&
"expected_name" != scope.Name)
return false;
return base.AddChildScope(scope);
}
You'll want to change the if statement in order to make this work better for you, but otherwise this is how you wedge yourself in between the creation of shared objects on the server. You still can't have your own class be instantiated, but you can prevent rogue clients from utilizing arbitrary RO's. Also be aware that there is no way to distinguish whether the request is being made by a client or your server code, it's all or nothing: either an object is available and shared with everything or completely unavailable.

On the client-side in ActionScript you'll need to check the return result of the SharedObject class's connect() method which will give back false on failure or true on success (despite what the documentation may say).

Friday, February 01, 2008

flash.util:Timer not found?

Are you seeing this error?
Error: Definition flash.util:Timer could not be found.
Adobe renamed flash.util to flash.utils upon releasing the third beta of ActionScript 3 and it's been that way ever since. Unfortunately a lot of works like ActionScript 3 Cookbook were written prior to this and their Timer samples tend to break. I was surprised to have such trouble finding the solution, so I decided to write it here.

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!