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 »

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 »