HitEnter Bug! Please help!

Need help with SmartFoxServer? You didn't find an answer in our documentation? Please, post your questions here!

Moderators: Lapo, Bax

skybucks100
Posts: 81
Joined: 15 Aug 2010, 23:16
Contact:

HitEnter Bug! Please help!

Postby skybucks100 » 29 Nov 2010, 00:16

Hi, I wanted it so that when you type something in the chat bar and hit enter so that you wouldn't have to click the button. This is the code I have been using:

Code: Select all

on (release, keyPress "<Enter>")
{
    if (!_global.isBusy)
    {
        sendChatMsg();
    } // end if
}

But its not working any help?
Best Regards,
Skybucks100
Rutter
Posts: 99
Joined: 12 Dec 2007, 16:21
Location: Canada
Contact:

Postby Rutter » 29 Nov 2010, 00:59

Key.addListener(keyListener);

var keyListener:Object = new Object();
keyListener.onKeyDown = function() {
if (Key.isDown(Key.ENTER)) {
sendChatMsg();
}
};
skybucks100
Posts: 81
Joined: 15 Aug 2010, 23:16
Contact:

Postby skybucks100 » 29 Nov 2010, 01:58

Rutter wrote:Key.addListener(keyListener);

var keyListener:Object = new Object();
keyListener.onKeyDown = function() {
if (Key.isDown(Key.ENTER)) {
sendChatMsg();
}
};


I tried using:
on (release) {
var keyListener:Object = new Object();
keyListener.onKeyDown = function() {
if (Key.isDown(Key.ENTER)) {
sendChatMsg();
}
};
}
And it doesn't work do I need to use:
on (release, keyPress "<Enter>") {
var keyListener:Object = new Object();
keyListener.onKeyDown = function() {
if (Key.isDown(Key.ENTER)) {
sendChatMsg();
}
};
}
Best Regards,

Skybucks100
Rutter
Posts: 99
Joined: 12 Dec 2007, 16:21
Location: Canada
Contact:

Postby Rutter » 29 Nov 2010, 02:40

dont use on(release) Thats only used for a button or movieClip.

The keylistener object watches for an event of a key being pressed. If the enter key is pressed the sendChatMsg() function is fired. Enter the code exactly as I showed you. Cut and paste.
skybucks100
Posts: 81
Joined: 15 Aug 2010, 23:16
Contact:

Postby skybucks100 » 29 Nov 2010, 03:46

Rutter wrote:dont use on(release) Thats only used for a button or movieClip.

The keylistener object watches for an event of a key being pressed. If the enter key is pressed the sendChatMsg() function is fired. Enter the code exactly as I showed you. Cut and paste.

I'm using
Key.addListener(keyListener);

var keyListener:Object = new Object();
keyListener.onKeyDown = function() {
if (Key.isDown(Key.ENTER)) {
sendChatMsg();
}
};
And... Well, It doesn't allow you to hit enter and then speak
Best Regards,

Skybucks100
Rutter
Posts: 99
Joined: 12 Dec 2007, 16:21
Location: Canada
Contact:

Postby Rutter » 29 Nov 2010, 03:54

make sure that sendChatMsg is fired. Add a trace statement to ensure it's working.

And make sure it has something to send via smartfox.sendPublicMessage(). You will need to add text as an argument to this function. e.g.

function sendChatMsg() {

smartFox.sendPublicMessage("hello");
}

instead of a literal you probably have a text box that contains the message you want to send e.g. chatbox.text which holds the message. then use something like: smartFox.sendPublicMessage(chatbox.text);
User avatar
coolboy714cp
Posts: 323
Joined: 06 Feb 2010, 02:45
Contact:

Postby coolboy714cp » 29 Nov 2010, 22:04

I don't know if this was resolved, but this is one method I used in a few of my games:

Code: Select all

_root.onEnterFrame = function() {
if (Key.isDown(Key.ENTER)) {
_root.sendChatMsg();
}
}


You could try that if you want. :P

(This goes in the "chat" frame coding of the game if your using the SmartFoxServer example files.)

Return to “SmartFoxServer 1.x Discussions and Help”

Who is online

Users browsing this forum: No registered users and 40 guests