I'm new to flex, hit casting recently.
this is the code i am running.
private function findBackgroundItem( relativeTime : Number ) : CSBackgroundItem
{
if( this.backgroundItems == null ) return null;
var result :CSBackgroundItem = null;
var relative:Date = new Date(relativeTime);
for( var i : Number = 0; i < this.backgroundItems.length; i++ )
{
var colourItem : CSBackgroundItem = CSBackgroundItem( this.backgroundItems.getItemAt( i ) );
}
return result;
}
The problem occurs when the result of IList.getItemsAt () is passed to the colourItem variable CSBackgroundItem. The following error is raised:
TypeError: Error #1034: Type Coercion failed: cannot convert com.mystuff::CSBackgroundItem@650e8dd1 to com.mystuff.CSBackgroundItem.
If I use the keyword 'as', I get cast results colourItemequal to null. Using a debugger shows that the list is not empty and really filled with objects CSBackgroundItem.
Now this is a stupid bit .. this code works, the first time it is loaded into the module. Subsequent loads (after unloading) cause an exception.
Can anyone shed some light on why this might happen?
source
share