0
votes

i'm trying to load a module and add it to a mx:box object called "mod". Here my Code:

var m:IModuleInfo = ModuleManager.getModule("modules/Module_Category.swf");
m.addEventListener(ModuleEvent.READY, function(e:Event):void 
{
     this.mod.addChild(m.factory.create() as DisplayObject);
});
m.load();

the Problem is that when i try to add it to mod using addChild Flex tells me that in the line using addChild

TypeError: Error #1010: A statement is not defined and has no propeties.

What does it mean?

1
Is this a compile time error or a runtime error? What is "this.mod"? It isn't defined in your code sample. - JeffryHouser
realy coder, only looking for code :D like i said above, "mod" is simply a mx:box object. Its a runtime error. compiler is fine with it. - omni
btw, i think using a <s:group> and a <s:module> instead of a <mx:box> and a <mx:module> would fix it, but i'm using flex 4.1 framework which dosn't seem to have the <s:module> (looks like its part of 4.5) so i have to use the old mx components. - omni

1 Answers

3
votes

Your 'this' scope is incorrect. You are using 'this' inside an anonymous function. Inside that function, 'this' refers to the function itself, not the class that you were probably aiming for. I can't see the rest of your class, but I can see that the 'this' scope does not have a property 'mod', hence your code will fail there. That's why you get that 'not defined' error: 'this.mod' doesn't exist.

I can see 3 solutions (it depends on what the rest of your code looks like, but one of them should fit your needs):

  1. Just remove 'this.'. Your class member 'mod' will then correctly be referenced.
  2. Convert that anonymous function into a class level function. 'this' will then point to that class, not to the function.
  3. Create an alias for 'this' outside of the anonymous function.

Some code will explain that last one better:

var myClass:MyClass = this;
m.addEventListener(ModuleEvent.READY, function(e:Event):void 
{
    myClass.mod.addChild(m.factory.create() as DisplayObject);
});