首页 \ 问答 \ TextField上的隐式强制错误(Error of implicit coercion on a TextField)

TextField上的隐式强制错误(Error of implicit coercion on a TextField)

我认为我有最常见的动作错误。在下面的代码中,我有一个MovieClip与一些TextFields里面,我想动画他们。当我把类分配给MovieClip我得到这个错误1118: Implicit coercion of a value with static type Object to a possibly unrelated type flash.text:TextField. 。 当我trace孩子时,我得到[Object TextField]并且代码工作正常,如果我将它放在第一帧并将其应用于动态文本,那么为什么当我尝试将此代码应用于MovieClip的孩子时出现此错误?

是否有机会忘记import任何必要的图书馆?

我已经使TextFields动态化了,我嵌入了字符并为动画设置了反锯齿。

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;

原文:https://stackoverflow.com/questions/7985182
更新时间:2022-07-01 13:07

最满意答案

一个简短的问题,一个简短的回答:是的,是一个混合

什么使目标C动态?“,第66页


一个例子:

我有一个处理与REST-API连接的类,它被称为APIClient。 在测试中,我想连接到不同的服务器。

在测试目标中,我分类APIClient

#import "ApiClient.h"

@interface TestApiClient : ApiClient
//…
@end


@interface TestApiClient ()
@property (nonatomic, strong, readwrite) NSURL *baseURL;

@end


@implementation TestApiClient

- (NSMutableURLRequest *)requestWithMethod:(NSString *)method
                                      path:(NSString *)path
                                parameters:(NSDictionary *)parameters
{
    self.baseURL = [NSURL URLWithString:@"http://localhost:8000/"];
    return [super requestWithMethod:method path:path parameters:parameters];
}

@end

在单元测试课中,我做了#import的调配

@implementation APIUnitTests


+(void)load
{
    client = [[ApiClient alloc ] init];
    object_setClass(client, [TestApiClient class]);
}

//…
@end

这个cas是保存的,因为我第一次创建了一个基类的子类,然后用子类替换了后者。 由于子类也是一个基类,这是有效的继承。


a short question, a short answer: yes, isa swizzling

What Makes Objective C Dynamic?, page 66


An example:

I have a class that handles connections to a REST-API, it is called APIClient. In testing I want to connect to a different server.

In the testing target I subclass APIClient

#import "ApiClient.h"

@interface TestApiClient : ApiClient
//…
@end


@interface TestApiClient ()
@property (nonatomic, strong, readwrite) NSURL *baseURL;

@end


@implementation TestApiClient

- (NSMutableURLRequest *)requestWithMethod:(NSString *)method
                                      path:(NSString *)path
                                parameters:(NSDictionary *)parameters
{
    self.baseURL = [NSURL URLWithString:@"http://localhost:8000/"];
    return [super requestWithMethod:method path:path parameters:parameters];
}

@end

In the Unit test class I do the swizzling #import

@implementation APIUnitTests


+(void)load
{
    client = [[ApiClient alloc ] init];
    object_setClass(client, [TestApiClient class]);
}

//…
@end

This cas is save, as I first created a subclass of an base class and then replaced the latter with the subclass. As the subclass is also a base class, this is valid inheritance.

相关问答

更多
  • 这应该工作 5.class => Fixnum 5.class.superclass => Integer 您还可以使用祖先方法,它将为您提供所有超类的列表 5.class.ancestors => [Fixnum, Integer, Numeric, Comparable, Object, Kernel, BasicObject] this should work 5.class => Fixnum 5.class.superclass => Integer You can also use ...
  • 一个简短的问题,一个简短的回答:是的,是一个混合 什么使目标C动态?“,第66页 一个例子: 我有一个处理与REST-API连接的类,它被称为APIClient。 在测试中,我想连接到不同的服务器。 在测试目标中,我分类APIClient #import "ApiClient.h" @interface TestApiClient : ApiClient //… @end @interface TestApiClient () @property (nonatomic, strong, readwri ...
  • 你真的需要做这样的事情是非常罕见的,通常这是一个迹象,表明你在一个对象内部唠唠叨叨,以后会回来咬你。 如果真的需要做什么,你可以改变你的包只是为了方法调用来改变SUPER看到的东西,或者通过调用完整的方法名来覆盖方法查找。 { package BaseClass; sub new { bless \my $self, shift; } sub foo { my $self = shift; print "BaseClass::foo()\n"; ...
  • 如果CommonClass来自外部库,您可能希望使用Composition over Inheritance原则将其包装在Adapter Pattern中 。 如果您想要更改正在使用的库,则可以完全控制,并允许您添加dontRepeatYourself()等功能。 public class CommonClassAdapter implements MyAdapter { private final CommonClass common; private final String cache ...
  • 简短的回答是,这是可能的。 更长的答案是您滥用术语超类和子类 。 你描述的关系不是一种继承关系,而是一种组合关系。 换句话说,您的Player类不会扩展您的Team类。 您的Team类将包含Player的实例。 是的,在这种情况下,您的Team类可以访问这些实例的方法和变量,就像您可以使用任何其他Java类一样。 它可能看起来像这样: class Team{ List players = new ArrayList(); public void addPlaye ...
  • 不,通过反射是不可能的,因为使用反射来分析现有代码,而不是改变它。 No, it's not possible through reflection becuase reflection is used to analyze the existing code, not to change it.
  • 我不确定你要做什么,也不知道你期望的结果。 但是,由于numbers.Number是一个abc (抽象基类),它意味着只需将它注册到abc ,就可以将自己的类视为其子类之一。 (没有必要像我第一次想到的那样覆盖__new__ ,因为我没有意识到这个数字numbers.Number是一个abc 。) 这就是我的意思: import numbers class Parent(object): # Added only to make script runnable pass class Nu ...
  • class Child(): nmbrMovies = 0 nmbrBooks = 3 class Adult(): nmbrMovies = 2 nmbrBooks = 5 class Member(Child): pass x = Member() Member开始继承Child : print(Member.__bases__) # (,) 可以将此更改为Adult : Mem ...
  • 您可以使用此重载ICriteria CreateCriteria(string entityName) : public string CheckString(string s){ if(s == "A") return "EntityA";//entity name from the database else if(s == "B") return "EntityB";//entity name from the database } public vo ...
  • 我可能会创建一个静态类来保存Element的“扩展方法”。 这类似于Integer.parseInt(String s); Boolean isTest = MyElement.getBoolean(data.getChild("isTest")); 实施将是 public static class MyElement { public static boolean getBoolean(Element e) { // Do your thing. return e ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)