这是对XML图像菜单的测试。在我创建容器的代码中,我在舞台上有一个影片剪辑(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);
}
我的问题是,我想要这样,例如,bg_mc
内menu_mc
和square
内bg_mc
。
如果我尝试,例如:
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
为什么?
答案 0 :(得分:1)
如果您希望bg_mc
内menu_mc
执行:menu_mc.addChild(bg_mc)
,
然后在square
内bg_mc
执行:bg_mc.addChild(square)
。
menu_mc.bg_mc.addChild(square);
会给您一个错误,因为在MovieClip
menu_mc
中没有名为bg_mc
的属性。添加子XYZ并不意味着创建名为XYZ的属性。