Archive for February, 2008

How to make an efficient image proxy

Thursday, February 21st, 2008 | actionscript, bugs, help | 5 Comments

So the work I’m currently doing is centered around loading data from different domains. I’ve got a proxy setup to get around pesky crossdomain issues but I’ve been trying to make it a bit dynamic for efficiency’s sake. I only want to proxy if I know for sure that the data isn’t coming from our servers or a server with a crossdomain file in place.

Creating a “smart” proxy with the URLLoader for text content is a piece of cake. Simply listen for the SecurityErrorEvent then run the url through the proxy. Beautifully simple.

For the Loader class its a different story. The Loader class’s contentLoaderInfo doesn’t have a security error event, just an ioError event. Your supposed to use the childAllowsParent property of the contentLoaderInfo to figure out whether you have bitmapData level access. The only problem is you can’t access that property until the Event.COMPLETE event is dispatched despite the livedocs LoaderContext page stating this property is available on ProgressEvent.PROGRESS which will throw a Error #2099: The loading object is not sufficiently loaded to provide this information. at flash.display::LoaderInfo/get childAllowsParent()

I can finagle with the LoaderContext and try/catches all I want but there doesn’t seam to be a creative solution to this problem. The result: I have to load every image that doesn’t have a policy file TWICE. Once to check childAllowsParent, the next to proxy the image. This doesn’t make any sense considering on the same livedocs LoaderContext page it states:

When you call the Loader.load() method with LoaderContext.checkPolicyFile set to true, Flash Player does not begin downloading the specified object in URLRequest.url until it has either successfully downloaded a relevant cross-domain policy file or discovered that no such policy file exists.

I can see the “Error: Request for resource at http://… by requestor from http://… is denied due to lack of policy file permissions.” errors being outputted to the trace window but I don’t seam to have a way to catch it in code. Is something as significant as this, really a bug? Can anyone give me a hand?

Tags: , ,

Using the “include” directive to update multiple classes

Wednesday, February 6th, 2008 | actionscript, flex | No Comments

I recently subclassed Flex’s Canvas to utilize my own custom scrollbars (what a pain!) and soon found I needed to do the same with the Box container (VBox, HBox). Due to the clean OOP nature of these components my overrides and implementation turned out exactly the same for my CustomScrollBarCanvas and CustomScrollBarBox. After a few refactoring sessions copying and pasting my changes to both subclasses I ended up moving all my code to a separate include file and its worked out beautifully with Flex still checking the code during incremental compile:

public class CustomScrollBarCanvas extends Canvas {
public function CustomScrollBarCanvas(){
super();
}
include “CustomScrollBarImplementation.as”
}

public class CustomScrollBarCanvas extends Box {
public function CustomScrollBarCanvas(){
super();
}
include “CustomScrollBarImplementation.as”
}

The Actionscript “include” directive is useful when you have a variable or several lines of code that are mirrored in several classes and you want to maintain that code in a central file. Flex and other frameworks use it commonly to write out framework version numbers on all their classes explicitly during compile time. Flex also uses it to write out groups of meta style tags by type (TextStyles.as, BorderStyles.as, etc) into the components that use them. Its really quite ingenious for upkeep but really simple to implement. (FYI in AS3 you no longer prepend the include statement with a “#”)

Tags: ,

Meta

Search