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

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

问题描述

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



我试图这样做:

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

我得到和按钮的实例( myComponent.button01 not null ),但是textField( myComponent.button01.theTextField )的实例是 null ,我无法更改文本(但默认文本出现在屏幕上)。代码在flex中正确编译。有谁知道什么是错的?



我也在swc中导出了按钮控件。所以这个按钮不是Flash中的默认SimpleButton,而是由Flash生成的派生类(与Flash中定义的符号名称相同)。它包含theTextField memeber,它是null。

这是按钮时间轴(第2层包含文本字段,textfield实例命名为theTextField):
< a href =http://img59.imageshack.us/img59/5002/timeliney.jpg =nofollow noreferrer> alt text http://img59.imageshack.us/img59/5002/timeliney.jpg

解决方案

实际上,没有问题,每个人都应该这样做。 : - )

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

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

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


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.

I'm trying to do this:

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

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?

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.

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. :-)

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.

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天全站免登陆