Implicit coercion of a value of type Vector.<X> to an unrelated type Vector.<X> - actionscript-3

I've got line of code
var enemies:Vector.<Unit> = _map.getEnemiesForFraction(_fraction);
where _map.getEnemiesForFraction(_fraction) is
public function getEnemiesForFraction(fraction:String):Vector.<Unit>
{
return _enemiesByFraction[fraction];
}
It compiles and works fine, but FlashBuilder keep annoying me with error
Implicit coercion of a value of type Vector.<Unit> to an unrelated
type Vector.<Unit>.
Why? How to get rid of this? Neither restart nor clean, doesn't work.

Related

AS3 Dynamic access to a sound channel

I have a flash project with many soundchannels active at the same time. I want a little function to play one and loop it, and the name of the sound channel will be passed as a parameter. This is the function:
function playBGMusic(channel:String):void
{
SoundChannel(channel) = bgSound1.play();
SoundChannel(channel).addEventListener(Event.SOUND_COMPLETE, loopBGMusic);
}
playBGMusic("bgChannel1");
This doesn't works, flash gives me this error:
1105: Target of assignment must be a reference value.
I tried to simplify the function, using an static string only in the listener
function playBGMusic():void
{
bgChannel1 = bgSound1.play();
SoundChannel("bgChannel1").addEventListener(Event.SOUND_COMPLETE, loopBGMusic);
}
playBGMusic();
This time it compiles, but it gives me this error:
Error #1034: Type Coercion failed: cannot convert "bgChannel1" to
flash.media.SoundChannel.
How can I access to a sound channel from a string?
Thaks.
You need to access it in the context of this:
SoundChannel(this[channel]) or SoundChannel(this["bgChannel1"])

Implicit Coercion of value type of flash.display.SimpleButton

My code is this:
symboll.addEventListener(Event.ENTER_FRAME, symboll);
function ball_hit_wall(e:Event):void{
(symboll.hitTestObject(box));
{
gotoAndPlay(3)
}
}
And the error message that i am getting is this:
1067: Implicit coercion of a value of type flash.display:SimpleButton to an unrelated type Function.
I'm new to actionscript, what did i do wrong
symboll and box are both buttons
Method addEventListener expects second argument of the type Function, while you're providing type SimpleButton.
Try replace your code
symboll.addEventListener(Event.ENTER_FRAME, symboll);
with
symboll.addEventListener(Event.ENTER_FRAME, ball_hit_wall);

Deep cloning using write byteArray not working

I'm writing a clone function for a class of mine.
var buffer:ByteArray = new ByteArray();
buffer.writeObject(this);
buffer.position = 0;
var gameblock:* = buffer.readObject();
Now at the last line when the time comes to read the object. I get these three errors together:
TypeError: Error #1009: Cannot access a property or method of a null
object reference. TypeError: Error #1034: Type Coercion failed: cannot
convert Object#c60efe9 to model.BlockData. TypeError: Error #1034:
Type Coercion failed: cannot convert Object#c5141c1 to
flash.geom.Matrix.
The class 'this' contains a user defined class BlockData and a Point . The errors are coming on that. How do you think I should clone this class?
I do overwrite the BlockData and the point again to make sure they get returned properly
Check this answer for better copy method with using of registerClassAlias method, but remember, that you can use this method only for simple cases, for example copy of data objects like TextFormat or Value Objects, you can't copy DisplayObject and its successor.

Error #1034: Type Coercion failed: cannot convert ... to flash.display.MovieClip

I'm new to ActionScript, so there is a possibility that I'm asking something simple.
import flash.display.MovieClip;
var WinsRM:Array = new Array (protomanwin);
var Robotmaster:MovieClip = new MovieClip;
Robotmaster = WinsRM[0];
addChild(Robotmaster);
Robotmaster.y = 250;
Robotmaster.x = 70;
No compiler error but I get this error:
TypeError: Error #1034: Type Coercion failed: cannot convert protomanwin$
to flash.display.MovieClip.
The protomanwin is a movie clip with many frames. I don't know what's wrong. No symbol will display. Also I use an array because I want to have more than one symbol to call in the future.
It seems that "protomanwin" is a name of an asset in your library. In this case, "protomanwin" is type Class, so instead of doing Robotmaster assignment as you do right now, you have to do this:
Robotmaster=new WinsRM[0]();
Note that you can make more than a single instance of your movie clip should you need to.

1067: Implicit coercion of a value of type void to an unrelated type flash.geom:Matrix

Im confused, I passed a matrix datatype into the this.graphics.beginBitmapFill(); and i get Implicit coercion of a value of type. below is my code.
var theMatrix:Matrix;
theMatrix = new Matrix();
this.graphics.beginBitmapFill(tileImage,theMatrix.translate(30,0));
this.graphics.endFill();
and the followig error sprigs
1067: Implicit coercion of a value of type void to an unrelated type flash.geom:Matrix.
It's normal you are passing to the beginBitmapFill function a parameter theMatrix.translate(30,0) who return nothing (void)
do this instead:
theMatrix.translate(30,0);
this.graphics.beginBitmapFill(tileImage,theMatrix);