Problem with casting Flex 3.2

I'm new to flex, hit casting recently.

this is the code i am running.

/**
* return background definition depending on time
*/ 
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++ )
    {
        // backgroundItems is an Ilist of CSBackgroundItem.
        var colourItem : CSBackgroundItem = CSBackgroundItem( this.backgroundItems.getItemAt( i ) );

        // other stuff here
    }           
    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?

+3
source share
3 answers

FYI, , ApplicationDomain, ( /) ApplicationDomain.

Eg.

loader.applicationDomain = ApplicationDomain.currentDomain; // parent domain
loader.applicationDomain = new ApplicationDomain(ApplicationDomain.currentDomain); // child domain
loader.applicationDomain = new ApplicationDomain(); // new domain
+1

, , , .

, ApplicationDomain.., , .

, Java ClassLoaders, .

,

+1

Yup .. it works ..

here is the fix i used in MXML style.

<mx:ModuleLoader id="loader" x="10" y="10" width="100%" height="100%" applicationDomain="{ApplicationDomain.currentDomain}"/>

equivalent actionScript will

loader.applicationDomain = ApplicationDomain.currentDomain;
+1
source

Source: https://habr.com/ru/post/1708714/


All Articles