Actionscript 3 addChild 问题

发布于 2024-10-11 06:22:07 字数 2094 浏览 6 评论 0原文

这是对 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_mcbg_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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

淡看悲欢离合 2024-10-18 06:22:07

如果您希望将 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 inside menu_mc do : menu_mc.addChild(bg_mc) ,
and then square inside bg_mc do : bg_mc.addChild(square).

menu_mc.bg_mc.addChild(square); will give you an error because in the MovieClip menu_mc there is no property named bg_mc. adding a child XYZ don't imply the creation of a property named XYZ.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文