tags:

views:

47

answers:

1

I have a main application(app.swf) which loads a module(profiles.swf) and the profiles module loads another module(member_profile.swf). In member_profile I get member data from the server side where an object of type Member is returned. The object returned contains an array called Jobs holding objects of type MemberJob. In the member_profile module there's a function that takes a parameter of type MemberJob to display the job details. I have a loop that goes through the array returned and calls the function for each array item like this:

for(i = 0; i < member.Jobs.length; i++)
     addJob(member.Jobs[i]);

I am getting an error at the addJob line:

Type Coercion failed: cannot convert components.classes::MemberJob@19107d81 to components.classes.MemberJob.

And I receive this error always on the second loading of the member_profile module. I mean this module gets loaded when I click a member's name from the profiles module which passes this name as the parameter for the sub module to load the profile of that member including his jobs. So if I chose to see the profile of member "X" the profile is loaded without any errors but if I then click on member "Y" (which causes the sub module to be reloaded with the new parameter) then I get the type coercion error. And if I did the opposite click on "Y" first then "X" the same happens, error in the second load.

Can anyone help me on this?

A: 

Re-read the Flex Help section on Module Domains and make sure that you've imported the components.classes::MemberJob class into the correct domain.

EDIT:

Try putting the following somewhere in your main application file and see if it makes a difference:

import components.classes.MemberJob;
private var memberJob:MemberJob;
Ryan Lynch
I don't specify any application domain when loading the modules. So how would I make sure that the MemberJob class is imported into the correct domain?The first line in the Module Domains section says "By default, a module is loaded into a child domain of the current application domain" so since am not specifying an application domain it means that the module is loaded into the child domain of the current application, right? And there's only one module that uses this class so I understand that when it's loaded it owns the class definition of MemberJob. Or am I getting all this wrong?
Yasmine
I placed the import statement and the variable declaration in the main application and it did make a difference. Now there's no error.But I don't understand what happened? Is there any other way of solving this issue instead of creating this unused variable in the main application. The main app doesn't need the MemberJob class in anything.Thanks.
Yasmine
Would you please explain how did this solution solved the problem?Does it mean that whenever I have this problem I should put the import statement and a dummy variable in the main app?Thanks
Yasmine
It's a security feature. Each module acts like it's own application, with the top level being the most trusted. Classes imported into a modules domain exist in that domain, and if you try to send them to another domain, the runtime throws an error. If you want to use the class across module domains, you make sure it gets imported into the top level domain. Make sense?
Ryan Lynch
If my solution fixed your issue, you could show some thanks by accepting my answer...at the very least it would help your 58% accept rating.
Ryan Lynch