Flash/AS3:访问中间时间线帧上的 DisplayObject 实例
我的动态文本字段在 Flash CS4 的中间时间线帧上有一个实例名称。
我有一个继承自 Sprite 的类,并且它总是在实例化时添加到舞台中。如何从此类获取对动态文本实例的引用?
谢谢!
编辑:示例:
我的主类(在 Flash 的发布设置中链接)如下所示:
protected function beginGame(e:MouseEvent){
gotoAndStop(8);
var game:GameContainer = new GameContainer(41,8);
addChild(game);
game.x=36;
game.y=128;
}
游戏容器扩展了 MovieClip,并绘制了一些漂亮的 gfx。
在第 8 帧上,在 Flash IDE 中,有一个名为“scoreText”的动态文本元素实例。
我想从 GameContainer 类访问它。
可能的?
I have the Dynamic Text field that has an instance name on a mid-timeline frame in Flash CS4.
I have a class that inherits from Sprite, and which is always added to the stage on instantiation. How can I get a reference to my Dynamic Text instance from this class?
Thanks!
EDIT: example:
My Main class (linked in Flash's publish settings) goes like this:
protected function beginGame(e:MouseEvent){
gotoAndStop(8);
var game:GameContainer = new GameContainer(41,8);
addChild(game);
game.x=36;
game.y=128;
}
Game Container extends MovieClip, and draws some pretty gfx.
On Frame 8, in the Flash IDE, there is a Dynamic Text element instance named "scoreText".
I want to access this from the GameContainer class.
Possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只要 GameContainer 位于舞台上,您就可以执行以下操作:
如果它不在舞台上,则它不会具有 root 属性。
As long as GameContainer is on the stage you can do:
If it's not on the stage it won't have a root property.
我认为你应该将文本字段分配给一个变量。请注意,您无法访问另一个框架上的对象,只有在该框架上时才能访问它。
但是..您可以尝试使用 addFrameScript() 。
我没有测试代码,但它应该是这样的。如果您使用 Flex SDK 进行编译,则不需要此分配,因为它已经理解它(顺便说一句,奇怪的是不同)
I think you should assign the textfield to a variable. Note you cannot access an object that is on another frame, you can only access it when you are on the frame.
But.. you could try to use addFrameScript() for that.
I did not test the code but it should be something like this. If you are compiling with the Flex SDK this assignment is not needed, since it understands it already (strange different btw)