ActionScript 将Child 从类添加到舞台
我正在尝试通过 addChild()
方法将对象添加到我的主舞台。通常,在 FLA 本身内工作时,使用 addChild(myObject) 效果很好。但是,它在外部 AS 类中不起作用。
我发现的所有其他教程都向我展示了如何做这样的事情,但这不是我需要的:
var myMovieClip:MovieClip = new MovieClip();
myMovieClip.addChild(myObject); // Works great, but not what I need
有人可以告诉我如何通过外部 AS 类将对象添加到我的主阶段 。
感谢您抽出时间。
I am trying to add an object to my main stage via the addChild()
method. Normally, when working within the FLA itself, using addChild(myObject)
works just fine. However, it does not work within an external AS class.
All of the other tutorials I have found showed me how to do something like this, which is not what I need:
var myMovieClip:MovieClip = new MovieClip();
myMovieClip.addChild(myObject); // Works great, but not what I need
Could someone please show me how to add an object to my main stage via an external AS class.
Thank you for your time.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果这是您的文档类或具有有效阶段引用的类,您可以使用:
编辑 - 添加示例。
下面是一个扩展 EventDispatcher 并传递“stage”参数的示例类。
首先,类:
以及用法(假设这是来自引用“stage”的类):
If this is your document class or a class that has a valid stage reference, you could use:
EDIT - Added example.
Here is an example class that extends EventDispatcher and passes a parameter of the 'stage'.
First, the class:
And the usage (assuming this is from a class that has reference to 'stage'):
您是否已经尝试过以下操作?
Did you already try the following?
科里的方法有效。您不需要像他在示例中那样扩展 EventDispatcher。
他的示例中重要的是:
注意他如何使用 _stage 变量来引用它。
Corey's method works. You don't need to extend EventDispatcher like he did in his example.
What is important in his example is:
Notice how he uses the _stage variable referencing it.