Quick Tip: AIR 2.5 & Security.loadPolicyFile()

After switching my AIR application into new AIR 2.5 SDK, boom! Every single URLRequest threw an IOErrorEvent. No other exception thrown. So I started digging in in order to find the cause and it appeared to be Security.loadPolicyFile() execution (I am reusing some libs containing these lines) that blocked it all quietly. First I tried to do try-catch block over it, but with no success. Than I just removed the lines for AIR project and voilà, everything back to normal again. URLRequests works again. It seems like AIR does not need loadPolicyFile() for URLRequests at all. Interesting that these loadPolicyFile() were targeting total different domain and were able to break any other requests.

URLRequestBuffer – Buffer Your URLRequests

Let’s suppose your app makes a lot of http requests at once, and you need a good administration for that. Based on used browser your app is running on, you are only allowed to limited request count – mostly its 2 requests per domain, the remaining ones are sitting in browser buffer waiting to finish those actual. URLRequestBuffer is handy class that lets you manage URLRequest-s. E.g. you are creating image gallery and request hundreds of images in gallery at a time, now when user navigates throug the images you need to make some request more prioritized before others, some to be canceled, some may timeout etc. Here comes URLRequestBuffer in scene.

Read the rest of this entry »

How to communicate between loader and child

This post is about communication between loader (Parent.as) flash object (.swf) and loaded (Child.as) flash object. While flash is event based, I find it correct to use events to communicate, although different methods exist (direct function call etc.)

Read the rest of this entry »

URLShorten Class (update)

URL shortening is a technique where a provider makes a web page available under a very short URL in addition to the original address. There are hundreds of provider out there, but only a few of them provides public api and crossdomain.xml. I put toghether some of those that work and URLShorten class was created 🙂 feel free to use it and enjoy

Update: jdem.cz, tinyurl.com, bit.ly, tr.im, is.gd providers implemented.

Read the rest of this entry »

Facebook Extended Permissions With Authorization by Overriding Class in swc

It may be not popular, but it is possible to substitute / override whole class from .swc file. Lets say you are using some public api, in our case Facebook actionscript api. I admire work of developer team, but I would like to have some things different. My facebook application requires publish_stream extended permission right after user login (authorize) my application. Even if official facebook api documentation says it is possible to ask for extended permission with login.php call (req_perms parameter), our facebook actionscript api does not offer setting this parameter.

Read the rest of this entry »

Flex Error #1034: Type Coercion Failed: Cannot Convert *** to mx.core.IFlexDisplayObject

When you keep getting:

Flex Error #1034: Type Coercion Failed: Cannot Convert *** to mx.core.IFlexDisplayObject

… after using getDefinition() method, in my case:

// url = "../some.swf"
var request:URLRequest = new URLRequest(url);
var context:LoaderContext = new LoaderContext();
context.applicationDomain = new ApplicationDomain(ApplicationDomain.currentDomain);
loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, assetsComplete);
loader.load(request, context);
// assetsComplete()
var applicationDomain:ApplicationDomain = assetsLoader.contentLoaderInfo.applicationDomain;
var assetsClass:Class = applicationDomain.getDefinition("Assets") as Class;

The problem is, in fact, the security not coercion! Try move your .swf (the one that is beeing loaded) into the same directory where master .swf file is located.

Bitmap, BitmapData, ByteArray…


Lets see how to convert between Bitmap, BitmapData and ByteArray in few examples:

  • DisplayObject to BitmapData
  • BitmapData to Bitmap
  • BitmapData to ByteArray
  • URL (image) to ByteArray (asynchronous)
  • URL (image) to BitmapData (asynchronous)
  • ByteArray to BitmapData (asynchronous)

Read the rest of this entry »