从主影片剪辑类访问嵌套影片剪辑
你好 我有一个 MovieClip,我将在运行时将其与我的文档类一起添加到显示列表中,因为会有很多它的实例。 MoviClip“盒子”内部还有 3 个 MovieClip 实例,这三个实例中的每一个实例又多了两个。它看起来像这样:
box
circle 0
oval0
oval1
circle 1
oval0
oval1
circle 2
oval0
oval1
这是我现在拥有的代码:
package
{
import flash.display.MovieClip;
public class BoxSet extends MovieClip
{
private var theArr:Array;
public function BoxSet()
{
run();
}
private function run():void
{
theArr = new Array();
for (var i:uint = 0; i<this.numChildren; i++)
{
var mc:MovieClip = this["n" + i] as MovieClip;
addChild(mc);
theArr[i] = mc;
mc.alpha = 0;
}
}
public function setAlpha(num:uint):void
{
theArr[num].alpha = 1;
}
}
}
它正在工作,但我想知道是否有更有效的方法来执行此操作,或者我所拥有的是否是执行此操作的好方法?任何帮助将不胜感激。
hi
I have a MovieClip, that I'm going to add to the display list with my document class at runtime beacuase there will be many instances of it. The MoviClip "box" has 3 more MovieClip instances inside it, and each of those three have two more. It looks like this:
box
circle 0
oval0
oval1
circle 1
oval0
oval1
circle 2
oval0
oval1
Here is the code I have right now:
package
{
import flash.display.MovieClip;
public class BoxSet extends MovieClip
{
private var theArr:Array;
public function BoxSet()
{
run();
}
private function run():void
{
theArr = new Array();
for (var i:uint = 0; i<this.numChildren; i++)
{
var mc:MovieClip = this["n" + i] as MovieClip;
addChild(mc);
theArr[i] = mc;
mc.alpha = 0;
}
}
public function setAlpha(num:uint):void
{
theArr[num].alpha = 1;
}
}
}
It's working but I want to know if there is a more efficient way of doing this, or if what I have is a good way of doing it? Any help will be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只要您只想按编号而不是名称引用 MovieClip 实例,您所拥有的看起来就非常高效。
What you have looks perfectly efficient as long as you just want to reference the MovieClip instances by number and not by name.
在 as3.0 中有两种使用嵌套 mc 的方法
1.绝对引用(刚性) 2.相对引用(灵活)。
在结构上,像mc3->这样的嵌套mcs嵌套在 mc2-> 嵌套在 mc1
绝对引用将类似于 root.mc1.mc2.mc3,以便从主时间线访问 mc3
相对引用 - 在任何阶段,您都可以使用
this.parent
或任何其他方式引用 mc 的父级通过扩展 abv 结构来实现其他 mcs。
抱歉,有 4 个错别字,我有点着急
There are 2 ways for working with nested mcs in as3.0
1.absolute referencing (Rigid) 2. Relative referencing(Flexible).
In the structure, of nested mcs like mc3-> nested in mc2->nested in mc1
absolute refrcing will look like e.g. root.mc1.mc2.mc3 to access mc3 frm the main timeline
Relative referencing - at any stage you can refere to the parent of the mc using
this.parent
or any other mcs by extentending the abv structure.
sry 4 typos i m in a bit hurry