Coacción implícita de un valor .. - AS3 OOP

ok, so field.as contains a field class, which contains a method that calls a method from another class (in another file.)

field.as

...
find_path.findPath(start_node, end_node, findConnectedNodes ) // I am getting the error here
...

find_path.as has a method called findPath.

public static function findPath(firstNode:Node, destinationNode:Node,  connectedNodeFunction:Function ):Array{
....

the error I'm getting (getting the same error twice):

-1118: Implicit coercion of a value with static type Object to a possibly unrelated type Node.
-1118: Implicit coercion of a value with static type Object to a possibly unrelated type Node.

preguntado el 08 de noviembre de 11 a las 12:11

How do you declare the start_node y end_node variables? -

in the class i.e. public var start_node:Node, end_node:Node; -

1 Respuestas

You might not have declared the type of start_node y end_node.

Declare those variables as

[private / public / protected] var start_node:Node, end_node:Node;

Alternatively, call the function as

find_path.findPath(start_node as Node, end_node as Node, findConnectedNodes )

respondido 08 nov., 11:16

ok, thanks mate. the second method worked. however, I am not sure why you have to do this, can you please explain? thanks @Pranav Hosangadi - dgamma3

@dgamma3 you need to do this to explicitly cast start_node y end_node which you defined as Objects a la Node type. This tells the compiler that the argument you are supplying is definitely of the class Node. It would have been better to declare the variables to be of the class Node to take advantage of the strongly typed nature of Flash - Pranav Hosangadi

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.