Actionscript 3 addChild 问题
这是对 XML 图像菜单的测试。在我创建容器的代码中,舞台中有一个影片剪辑 (menu_mc
)。
代码:
import flash.display.MovieClip;
import fl.text.TLFTextField;
import flashx.textLayout.formats.TextLayoutFormat;
import flashx.textLayout.elements.TextFlow;
import flashx.textLayout.formats.TextAlign;
import flash.display.Sprite;
var title_mc:TLFTextField;
var img_mc:MovieClip;
var bg_mc:MovieClip;
var myFormat:TextLayoutFormat;
var myTextFlow:TextFlow;
createContainers();
function createContainers():void {
//CREATE IMAGE CONTAINER
img_mc = new MovieClip();
menu_mc.addChild(img_mc);
img_mc.x = -50;
img_mc.y = -60,10;
//CREATE TEXTFIELD
title_mc = new TLFTextField();
addChild(title_mc);
title_mc.x = 0;
title_mc.y = 20;
title_mc.width = 120;
title_mc.height = 50,70;
title_mc.multiline = true;
title_mc.embedFonts = true;
title_mc.antiAliasType = AntiAliasType.ADVANCED;
title_mc.wordWrap = true;
title_mc.text = "text text text text text text text";
myFormat = new TextLayoutFormat();
myFormat.textIndent = 0;
myFormat.color = 0x0000FF;
myFormat.fontFamily = "Arial";
myFormat.fontSize = 20;
myFormat.textAlign = TextAlign.CENTER;
myFormat.textAlignLast = TextAlign.CENTER;
myTextFlow = title_mc.textFlow;
myTextFlow.hostFormat = myFormat;
myTextFlow.flowComposer.updateAllControllers();
//CREATE BACKGROUND CONTAINER
bg_mc = new MovieClip();
menu_mc.addChild(bg_mc);
bg_mc.x = 0;
bg_mc.y = 70;
bg_mc.width = 120;
bg_mc.height = 50;
//CRETAE SPRITE
var square:Sprite = new Sprite();
square.graphics.lineStyle(1,0x000000);
square.graphics.beginFill(0x000000);
square.graphics.drawRect(0,0,300,300);
square.graphics.endFill();
menu_mc.addChild(square);
}
我的问题是我想要,例如,menu_mc
内的bg_mc
和bg_mc内的
。square
例如,如果我尝试:
menu_mc.bg_mc.addChild(square); //error
或
menu_mc.addChild(title_mc); //textfield disapears
Flash 给我这个错误:
TypeError: Error #1010: A term is undefined and has no properties
为什么?
This is a test for a XML image menu. In the code I create my containers, I have a movie clip in the stage (menu_mc
).
CODE:
import flash.display.MovieClip;
import fl.text.TLFTextField;
import flashx.textLayout.formats.TextLayoutFormat;
import flashx.textLayout.elements.TextFlow;
import flashx.textLayout.formats.TextAlign;
import flash.display.Sprite;
var title_mc:TLFTextField;
var img_mc:MovieClip;
var bg_mc:MovieClip;
var myFormat:TextLayoutFormat;
var myTextFlow:TextFlow;
createContainers();
function createContainers():void {
//CREATE IMAGE CONTAINER
img_mc = new MovieClip();
menu_mc.addChild(img_mc);
img_mc.x = -50;
img_mc.y = -60,10;
//CREATE TEXTFIELD
title_mc = new TLFTextField();
addChild(title_mc);
title_mc.x = 0;
title_mc.y = 20;
title_mc.width = 120;
title_mc.height = 50,70;
title_mc.multiline = true;
title_mc.embedFonts = true;
title_mc.antiAliasType = AntiAliasType.ADVANCED;
title_mc.wordWrap = true;
title_mc.text = "text text text text text text text";
myFormat = new TextLayoutFormat();
myFormat.textIndent = 0;
myFormat.color = 0x0000FF;
myFormat.fontFamily = "Arial";
myFormat.fontSize = 20;
myFormat.textAlign = TextAlign.CENTER;
myFormat.textAlignLast = TextAlign.CENTER;
myTextFlow = title_mc.textFlow;
myTextFlow.hostFormat = myFormat;
myTextFlow.flowComposer.updateAllControllers();
//CREATE BACKGROUND CONTAINER
bg_mc = new MovieClip();
menu_mc.addChild(bg_mc);
bg_mc.x = 0;
bg_mc.y = 70;
bg_mc.width = 120;
bg_mc.height = 50;
//CRETAE SPRITE
var square:Sprite = new Sprite();
square.graphics.lineStyle(1,0x000000);
square.graphics.beginFill(0x000000);
square.graphics.drawRect(0,0,300,300);
square.graphics.endFill();
menu_mc.addChild(square);
}
My problem is I want that, for example, bg_mc
inside menu_mc
and square
inside bg_mc
.
If I try, for example:
menu_mc.bg_mc.addChild(square); //error
or
menu_mc.addChild(title_mc); //textfield disapears
Flash give me this error:
TypeError: Error #1010: A term is undefined and has no properties
Why?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您希望将
bg_mc
放在menu_mc
中,请执行以下操作:menu_mc.addChild(bg_mc)
,然后在
bg_mc
内的square
执行:bg_mc.addChild(square)
。menu_mc.bg_mc.addChild(square);
会给你一个错误,因为在MovieClip
menu_mc
中没有名为bg_mc< 的属性/代码>。添加子 XYZ 并不意味着创建名为 XYZ 的属性。
If you want
bg_mc
insidemenu_mc
do :menu_mc.addChild(bg_mc)
,and then
square
insidebg_mc
do :bg_mc.addChild(square)
.menu_mc.bg_mc.addChild(square);
will give you an error because in theMovieClip
menu_mc
there is no property namedbg_mc
. adding a child XYZ don't imply the creation of a property named XYZ.