TextField 上的隐式强制转换错误
我认为我有最常见的动作脚本错误。在下面的代码中,我有一个 MovieClip,里面有一些 TextFields,我想为它们设置动画。当我将类分配给 MovieClip 时,我收到此错误 1118: Implicit coercion of a将静态类型 Object 的值转换为可能不相关的类型 flash.text:TextField.
。当我 trace
孩子时,我得到 [Object TextField]
并且如果我将它放在第一帧上并将其应用到动态文本,代码可以正常工作,所以为什么我得到这个当我尝试将此代码应用于 MovieClip 的子级时出错?
是否有可能忘记导入
任何必要的库?
我已经使文本字段动态化,我已经嵌入了字符并设置了动画的抗锯齿。
package AScripts
{
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;
import com.greensock.*;
import com.greensock.easing.*;
import flupie.textanim.*;
public class TextFade extends MovieClip {
private var child : Object;
public function TextFade( )
{
/* for (var i : int = 0; i < numChildren; i++ ) {
child = getChildAt( i );
trace( child );
*/
child = getChildAt( 0 );
var txtanim:TextAnim = new TextAnim( child ); // <-- Error
/* TextAnim expects a TextField as argument */
txtanim.mode = TextAnimMode.RANDOM;
txtanim.split = TextAnimSplit.WORDS;
txtanim.effects = myEffect;
txtanim.start();
}
function myEffect( block:TextAnimBlock ) : void
{
TweenLite.to( block , .5 , {alpha : 0 , delay : Math.random( ) * 1 } );
}
}
}
更新:我对建议进行了更改并起作用了。
import flash.text.*;
private var child : TextField;
child = getChildAt( i ) as TextField;
I think i have the most common actionscript error.In the code below i have a MovieClip with some TextFields inside and i want to animate them.When i assign the class to the MovieClip i get this error 1118: Implicit coercion of a value with static type Object to a possibly unrelated type flash.text:TextField.
. When i trace
the childs i get [Object TextField]
and the code works fine if i place it on the first frame and apply it to a Dynamic Text so why i get this error when i try to apply this code to the childs of a MovieClip ?
Is there a chance to have forgot to import
any necessary library ?
I have made the TextFields dynamic,i have embed the characters and set anti-alias for animation.
package AScripts
{
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;
import com.greensock.*;
import com.greensock.easing.*;
import flupie.textanim.*;
public class TextFade extends MovieClip {
private var child : Object;
public function TextFade( )
{
/* for (var i : int = 0; i < numChildren; i++ ) {
child = getChildAt( i );
trace( child );
*/
child = getChildAt( 0 );
var txtanim:TextAnim = new TextAnim( child ); // <-- Error
/* TextAnim expects a TextField as argument */
txtanim.mode = TextAnimMode.RANDOM;
txtanim.split = TextAnimSplit.WORDS;
txtanim.effects = myEffect;
txtanim.start();
}
function myEffect( block:TextAnimBlock ) : void
{
TweenLite.to( block , .5 , {alpha : 0 , delay : Math.random( ) * 1 } );
}
}
}
UPDATE : I made the suggestion changes and worked.
import flash.text.*;
private var child : TextField;
child = getChildAt( i ) as TextField;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
试试这个:
Try this:
当您获取对象或更改子变量的声明时,您可以将 child 强制转换为对象:
You can just cast child as an Object when you get the object or change the declaration of the child var: