What is the implicit cast behaviour of Actionscript?

78 views Asked by At

Myself being a C++/C# programmer I now have the misfortune of having to implement some changes into a bigger Actionscript/Air project written by somebody else some time ago.

Got the project to compile (well more or less) with "FlashDevelop" as an IDE. But For other reasons we want to use "IntelliJ" now.

Thing is that IntelliJ apparently does some more checking and now spits out dozens of errors like:

Error:(319, 0) [SomeSourceFile]: Implicit coercion of a value of type ByteArray to an unrelated type String.

On code like that:

  public function send(ba:ByteArray):void{
                mdm.COMPort.send(ba)
            }

With the "mdm.COMPort.send" function expecting a string.

Yes, thats a type mismatch error! I fully agree!

But for some reason it worked with the old project. Apparently Actionscript was able to do some implicit type conversion/casting and did not check for type safety.

Question is now: How do I correct that? What was the implicit behaviour that actionscript applied in such cases?

mdm.COMPort.send(ba.toString())
mdm.COMPort.send(string(ba))
mdm.COMPort.send(ba as string)
mdm.COMPort.send(ba.ReadUTFBytes(ba.length))

Or other I do not know of?

I do have that problem now on many places with many types (not only "byte array" and "string"), so a general answer would be appreciated.

0

There are 0 answers