def join(username: String): scala.concurrent.Future[(Iteratee[JsValue, _], Enumerator[JsValue])] = {
println("friend name in model" + username)
val first = Akka.system.actorOf(Props[ChatRoom2], name = username)
println("this is chat room two default")
}
and when i use this val first = context.actorOf(Props[ChatRoom2],name=username)
I am use this for create a child actor in a different chat room but it shows an error not found value context.
You cannot access actor context
from a class not extending Actor
. You must be extending Actor
in the class having join
method above (not only ChatRoom2)
When you use an actor system
reference, you're creating "top level" actors, whereas using context
creates "child actors" of your current actor. This means that accessing context
only makes sense from within an Actor
.
Here's an example:
val system = ActorSystem("name")
val act = system.actorOf(classOf[SomeActor])
class SomeActor extends Actor {
def receive = {
case _ => val child = context.actorOf(...)
}
}
In this example "act" is a "top level" actor, and "child" is a child of "act", because it was created by act's context.
I hope this helps!
For more help please refer to the docs: http://doc.akka.io/docs/akka/2.3.1/scala/actors.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With