在 Flash 的单独层中创建的按钮内的 TextField 实例在 Flex 中为 null [英] TextField instance inside a button created in a separate layer in Flash is null in Flex

查看:26
本文介绍了在 Flash 的单独层中创建的按钮内的 TextField 实例在 Flex 中为 null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Flash 中创建了一个按钮对象.该按钮包含 2 层.一个是背景图像,在它上面是一个 textField.文本字段是动态的.我使用影片剪辑内的按钮并将其导出到 SWC 中.我正在尝试在 flex 中使用它.

I've created an button object in flash. The button contains 2 layers. One is the background image and on top of it is a textField. The textfield is dynamic. I use the button inside a movieclip and I export it in a SWC. The I'm trying to use it in flex.

我正在尝试这样做:

var myComponent:MyComponent = new MyComponent();
myComponent.button01.theTextField.text = "Caption";

我得到了按钮的实例(myComponent.button01 在 Flex 调试器中是 not null),但是 textField 的实例(myComponent.button01.theTextField) 为 null 并且我无法更改文本(但默认文本显示在屏幕上).代码在 flex 中正确编译.有谁知道出了什么问题?

I get and instance of the button(myComponent.button01 is not null in Flex debugger), but the instance of the textField(myComponent.button01.theTextField) is null and I'm not able to change the text(but the default text appears onscreen). The code is compiled correctly in flex. Does anyone has any idea what is wrong?

我也导出了 swc 中的按钮控件.所以按钮并不是Flash默认的SimpleButton,而是flash生成的派生类(与flash中定义的符号同名).它包含 TextField 成员,该成员为 null.

I exported the in swc the button control as well. So the button is not the default SimpleButton from Flash, but an derived class generated by flash(with the same name as the symbol defined in flash). It contains theTextField memeber, which is null.

这是按钮时间轴(第 2 层包含文本字段,该文本字段实例名为 theTextField):替代文字 http://img59.imageshack.us/img59/5002/timeliney.jpg

Here is the button timeline(Layer 2 contains the textfield, and the textfield instance is named theTextField): alt text http://img59.imageshack.us/img59/5002/timeliney.jpg

推荐答案

其实没有问题,一切正常.:-)

Actually, there is no problem, everyhting works as it should. :-)

在您实例化一个类 (new MyComponent()) 之后,子对象本身不会被实例化,该过程被推迟.只有将组件添加到显示列表后,才会实例化所有子控件.因此,您需要在实际将对象添加到显示列表后才能访问子控件.

After you instantiate a class (new MyComponent()) the child objects are not instantiated themselves, that procedure is deffered. Only after you add the component to the display list will all the subcontrols be instantiated. So, you need to access the subcontrols only after you actually added the object to the display list.

在 flex 控件中,您有一个用于该目的的 creationComplete 事件.

In flex controls you have a creationComplete event that is used for just that purpose.

您可以阅读对象创建的详细信息这里.

You can read up on details of object creation here.

这篇关于在 Flash 的单独层中创建的按钮内的 TextField 实例在 Flex 中为 null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆