开发者

Implicit coercion of a value of type X to an unrelated type X

开发者 https://www.devze.com 2023-03-25 03:36 出处:网络
HiI have this error : Implicit coercion of a value of type X to an unrelated type X where X is the type of the object and yes it\'s type X to an unrelated type X.

Hi

I have this error :

Implicit coercion of a value of type X to an unrelated type X

where X is the type of the object and yes it's type X to an unrelated type X. It appears 6 times in my project, in 3 differents .mxml file, in the script element. It's in 3 files that I'm not editing and the file I has changing has no link with the 3 files with the errors.

Here a line of code with the problem.

var loadApplicationEvent:LoadApplicationEvent = new LoadApplicationEvent(application);

It was working perfect an when it was compiling and other file that I ch开发者_开发技巧anged, it put me and error.

Bug from Flash Builder or Flex? Or not?

How can I get ride of it?


I just ran into this issue myself with Flash Builder 4.5. The return type is exactly as it should be.

The solution for me was to do a full rebuild of the project via: Project -> Clean.


I have recently started having this problem with FlashBuilder and here's what I did.

Starting with:

    protected var _foo:FooType;
(X) public function get foo():FooType { return this._foo; }

(where (X) is the error in the form Snote described it, with X = FooType)

change to:

    protected var _foo:FooType;
    public function get foo():* { return this._foo; }

and rebuild. The * type always passes type checking no matter what, so the error disappears.

Then change it back:

    protected var _foo:FooType;
    public function get foo():FooType { return this._foo; }

The error message then disappears, at least for a while.

So far this technique seems to be reliable, if annoying.


I had the same problem. I resolved it by disabling "strict type checking"

Project properties > ActionScript Compiler > Enable strict type checking


It happens when you try to assign a different type object to some variable. For example, if you try to assign a string value('4') to an object where an int(4) is expected. Look for all the given locations and correct the type casting.


It is an implicit casting, but I cannot tell you the precise problem with the information you have provided.

var loadApplicationEvent:LoadApplicationEvent = new LoadApplicationEvent(application);

What type of object is "application" and what argument is expected by the LoadApplicationEvent constructor? That is where your implicit coercion is occurring. My guess is "application" is not the same type as expected by LoadApplicationEvent in its constructor.


In my case is was going every thing right. Thus it looks to be a IDE problem, as the same code worked few times and the other time it showed me this error. You can try few steps to solve this problem
1. Clear the compiled code and compile again. (There is a clear option in Project tab).
2. Create the a file with the same code and delete the old file.
3. If all this doesn't work, make another class which inherits the base class and change the expected value to *

example:

   
       public class DataGroupOX extends DataGroup
       .....
       public function set itemRenderer2(value:*):void{
            value = value as IFactory;
            super.itemRenderer = value;
        }


   
0

精彩评论

暂无评论...
验证码 换一张
取 消