How to get other's Room Extension instance.

Post here your questions about Actionscript and Java server side extensions development.

Moderators: Lapo, Bax

Post Reply
flashbk
Posts: 16
Joined: 08 Jul 2010, 05:45

How to get other's Room Extension instance.

Post by flashbk »

My extension class name is "MyExtension"

public class MyExtension extends AbstractExtension
{
TestFunc();
}

I wanna invoke other room's function "TestFunc".

so I have to other room extension instance.
I try like this

void InvokeTest( int otherRoomId )
{
Zone zone = helper.getZone(extension.getOwnerZone());
Room room = zone.getRoom(otherRoomId);
MyExtension roomExtension = (MyExtension)room.getExtManager().get("MyExtension");
roomExtension.TestFunc();
}

but fail with very strange cast fail exception like this.

"MyExtension cannot be cast to MyExtension"

If I was in room 1 and I call InvokeTest(1), success.
If I was in room 2 and I call InvokeTest(1), raise cast exception.

could you help me. :D
BigFIsh
Posts: 1698
Joined: 25 Feb 2008, 19:26
Location: New Zealand

Post by BigFIsh »

Let's do a test to verify that the extension can talk to the other extension:

Code: Select all

Zone zone = helper.getZone(extension.getOwnerZone());
Room room = zone.getRoom(otherRoomId);
AbstractExtension roomExtension = (AbstractExtension)room.getExtManager().get("MyExtension");
roomExtension.init()
Put a trace in the init() body. Does it get traced out?
Smartfox's forum is my daily newspaper.
BigFIsh
Posts: 1698
Joined: 25 Feb 2008, 19:26
Location: New Zealand

Post by BigFIsh »

After looking at http://www.smartfoxserver.com/docs/docP ... bility.htm, I just realized that handleInternalRequest wasn't the handleInternalEvent method. So maybe handleInternalRequest function is specifically used for talking between extensions, so give that a go.
Smartfox's forum is my daily newspaper.
flashbk
Posts: 16
Joined: 08 Jul 2010, 05:45

Thank you BigFish.

Post by flashbk »

Thank you BigFish for your reply.

I solved this problem..

I think that cast is dangerous. because exception is raised by java.

So I remove cast. and create another handler that invoke TestFunc() named "InvokeTestFunc".

ISmartFoxExtension ext = room.getExtManager().get("BallyRoomExtension");
ext.handleRequest("InvokeTestFunc", msg, user, roomID);
BigFIsh
Posts: 1698
Joined: 25 Feb 2008, 19:26
Location: New Zealand

Post by BigFIsh »

Why not use handleInternalRequest?
Smartfox's forum is my daily newspaper.
flashbk
Posts: 16
Joined: 08 Jul 2010, 05:45

Post by flashbk »

thank you.

I think I have to search about HandleInternalRequest.
I don't know about it.

Thank you for your suggestion.
Post Reply