问题描述
这是一个问题,最好的在code解释。
This is a problem that's best explained in code.
我看不出 active_button.upState
,这是我所知道的是一个文本字段(见trace语句),神不知鬼不觉变成一个DisplayObject,当我尝试访问文字颜色
属性。
I don't see how active_button.upState
, which I know is a TextField (see trace statements), mysteriously turns into a DisplayObject when I try to access the textColor
property.
我已经包含下面的错误信息,以供参考。
I've included the error messages below for reference.
另外,为什么是它,当我有,我知道为SimpleButton对象(同样,见踪迹),我需要将其转换为SimpleButton的,以便将其存储在一个变种?这没有任何意义,我。
Also, why is it that when I have an object that I know is a SimpleButton (again, see traces) I need to cast it to SimpleButton in order to store it in a var? That doesn't make any sense to me.
所有帮助是非常AP preciated。谢谢你。
All help is much appreciated. Thanks.
public class Menu extends MovieClip
{
private var active_button:SimpleButton;
public function Menu()
{
// menu_list is a collection of SimpleButtons, I make the first one the 'active_button' and give each a MOUSE_DOWN event listener.
trace( menu_list.getChildAt( 0 )); // writes [object SimpleButton]
active_button = SimpleButton( menu_list.getChildAt( 0 )); // Cast is required here. Otherwise throws Error 1118. Strange. Why is that?
for( var i:Number = 0; i < menu_list.numChildren; i++ )
{
menu_list.getChildAt( i ).addEventListener( MouseEvent.MOUSE_DOWN, menuClick );
}
}
private function menuClick( e:Event ) : void
{
trace( e.target ); // writes [object SimpleButton]
active_button = SimpleButton( e.target ); // Cast is required here. Otherwise throws Error 1118. Still Strange.
trace( active_button ); // writes [object SimpleButton]. Normal.
trace( active_button.upState ); // writes [object TextField]. Normal.
active_button.upState.textColor = 0xAAAAAA; // Throws Error 1119. WTF?! textColor is a perfectly valid property of active_button.upState. Why is it suddenly type DisplayObject?
}
}
错误:
1118:静态类型flash.display使用的值的隐式强制:要的DisplayObject一个可能无关的类型flash.display一:SimpleButton的
1118: Implicit coercion of a value with static type flash.display:DisplayObject to a possibly unrelated type flash.display:SimpleButton.
1119:可能未定义的属性文字颜色的通过静态类型flash.display使用参考访问:的DisplayObject
1119: Access of possibly undefined property textColor through a reference with static type flash.display:DisplayObject
编辑:我凝聚我的问题一点点,张贴http://stackoverflow.com/questions/2165095/as3-why-does-datatype-automatically-change-from-textfield-to-displayobject-on-it
I've condensed my question a little bit and posted as http://stackoverflow.com/questions/2165095/as3-why-does-datatype-automatically-change-from-textfield-to-displayobject-on-it
推荐答案
凡是被从图像显示拉被归类为可能的最低dinominator(例如displayObject的),因为虽然SimpleButton的是一个DisplayObject,不是所有的DisplayObject将SimpleButtons 。这可能是你的第二个问题的原因也一样,只是在执行中略有不同。有没有在SimpleButton的一个直接引用,指出纽约州北部是一个TextField?
Anything that is pulled from the displaylist is classed as the lowest possible dinominator (eg. displayObject), as although SimpleButton is a displayObject, not all displayObjects will be SimpleButtons.This is probably the reason for your second problem too, just slightly different in execution. is there a direct reference in SimpleButton that states upState is a TextField?
尝试关闭编译严格模式,看看是否有帮助。看<一href="http://livedocs.adobe.com/flash/9.0/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00000045.html"相对=nofollow>类型检查的LiveDocs 了解详情
try switching off Strict Mode of compilation and see if it helps.see Type Checking Livedocs for more information
这篇关于AS3:类型的全局变量的SimpleButton变化的DisplayObject由于未知原因,不会让我访问.upState.textColor!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!