1
votes

I am getting error: "1067: Implicit coercion of a value of type Number to an unrelated type String."

When attempting to run:

var cam_array: Array = Camera.names;
for (var ci:Number=0; ci < cam_array.length; ci++){
    trace(Camera.getCamera(ci).name);
}

yet when I run:

var mic_array: Array = Microphone.names;
for (var mi:Number=0; mi < mic_array.length; mi++){
    trace(Microphone.getMicrophone(mi).name);
}

there is no issue. The only change is from Microphone to Camera, so what gives?

Thanks in advance!

1
the parameter in getCamera is probably a String. Unrelated: why are you using number in for loops? use int.user2655904
Unrelated reason: This is my first time using AS3, or ActionScript for that matter, and it's been a few years since my last go at scripting.user3924479
a for loop is typically used with an int not a Number.BotMaster

1 Answers

0
votes

Camera function getCamera() accepts an optional parameter of name:

name:String (default = null) — Specifies which camera to get, as determined from the array returned by the names property. For most applications, get the default camera by omitting this parameter. To specify a value for this parameter, use the string representation of the zero-based index position within the Camera.names array. For example, to specify the third camera in the array, use Camera.getCamera("2").

If you do not want the default parameter, cast the index position to a string:

var cam_array:Array = Camera.names;
for (var ci:uint = 0; ci < cam_array.length; ci++){
    trace(Camera.getCamera(ci.toString()).name);
}

Another method to loop camera names would be:

var cam_array:Array = Camera.names;
for each (var camera:String in cam_array) {
    trace(camera);
}

On the other hand, Microphone function getMicrophone() accepts an optional parameter of index:

index:int (default = -1) — The index value of the microphone.