简体   繁体   English

在另一层中调用函数

[英]Calling a function in another layer

I have a layer named "splash" and a layer named "home". 我有一个名为“splash”的图层和一个名为“home”的图层。 On the splash layer I want to call a function which is stored on a layer named "navigation" inside a MovieClip called "page" on the home layer. 在启动层上,我想调用一个函数,该函数存储在主层上名为“page”的MovieClip内的名为“navigation”的层上。

How can I do this? 我怎样才能做到这一点?

Thanks. 谢谢。

As far as I understand, layers are strictly for a convenience factor while editing as well as setting the initial Z order of objects on the stage. 据我所知,在编辑时以及在舞台上设置对象的初始Z顺序时,图层是严格的便利因素。 When the swf is actually run layers no longer exist. 当swf实际运行时,层不再存在。

If they are on the same frame number I would assume you could just call the function itself. 如果它们在相同的帧编号上,我认为你可以直接调用该函数。

Personally I would store ALL the code at the same frame on one layer. 我个人会将所有代码存储在一层的同一帧上。 It is easier to maintain as you do not have to go hunting down code. 它更容易维护,因为您不必去寻找代码。 I hope that helps. 我希望有所帮助。

Try using this from splash: 尝试使用splash:

//Look at my parent, look into home, look into page, look into navigation, call myFunction() Object(parent.getChildByName("home")).getChildByName("page").getChildByName("navigation").myFunction() //查看我的父母,查看主页,查看页面,查看导航,调用myFunction()对象(parent.getChildByName(“home”))。getChildByName(“page”)。getChildByName(“navigation”)。myFunction ()

The Object casting is to allow chaining all the children queries without additional casting. 对象转换允许链接所有子查询而无需额外的转换。 This is because getChildByName returns a DisplayObject which does not have the method for child searching. 这是因为getChildByName返回一个没有子搜索方法的DisplayObject。

You should just do this: 你应该这样做:

page.whateverYourFunctionIsCalled();

because as ToddBFisher already said, layers are only present in Flash while editing, an exported SWF doesn't have them anymore. 因为正如ToddBFisher所说,图层只在编辑时存在于Flash中,导出的SWF不再具有它们。 You didn't tell what the function is you want to call inside the page MovieClip so I can't be more specific here. 你没有告诉你要在page MovieClip中调用什么函数,所以我不能在这里更具体。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM