Quick Tip: Constructor Of Property With Namespace

Some of you may not like the solution (including me) but sometimes you need a little hack to make things work for you. In my case I required a constructor of property declared under custom namespace but not defined (null). Normally, you would go for describeType(), but guess what, yeah it just does not describes properties with namespace other than public. While there was nothing better in my mind than passing some unexpected value and expect what happend I decided to go for it. Luckily an exception was thrown with correct constructor name.

Error message looks something like this:

TypeError: Error #1034: Type Coercion failed: cannot convert true to valueObject.SomeObject.

lets parse it:

import com.adobe.fiber.core.model_internal;

var item:SomeUltraCleverObjectWithNamespacedProperty
var className:String;
var constructor:Class;
    item.model_internal::["_internal_" + name + "_leaf"] = true;
    className = error.message.toString().match("([^\\s]+)\.$")[1];

constructor = getDefinitionByName(className) as Class;

You should be careful about using it, because constructor is parsed from an error message that is localized (part of flash player). It may happen that in some translations the constructor name may appear in different part of the message (example parses at the end of sentence before dot “.” character).

Leave a comment

Please be polite and on topic. Your e-mail will never be published.