Flex 无法将模块添加为 DisplayObject
我正在尝试加载一个模块并将其添加到名为“mod”的 mx:box 对象中。这是我的代码:
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();
问题是,当我尝试使用 addChild 将其添加到 mod 时,Flex 告诉我在使用 addChild 的行中
TypeError:错误#1010:语句未定义且没有属性。
这是什么意思?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的“this”范围不正确。您在匿名函数中使用“this”。在该函数内部,“this”指的是函数本身,而不是您可能想要的类。我看不到你的类的其余部分,但我可以看到“this”范围没有属性“mod”,因此你的代码将在那里失败。这就是为什么您会收到“未定义”错误:“this.mod”不存在。
我可以看到 3 种解决方案(这取决于代码的其余部分,但其中之一应该满足您的需求):
一些代码可以更好地解释最后一个:
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):
Some code will explain that last one better: