Posted by smuella in SWF Studio V3 on Mar 17 2008, 07:00 am

Hi there,
I'm developing a exhibition kiosk application that is going to have three buttons and a tracker ball. I want to use the buttons to let users navigate through menu options, and have been coding it using the Mouse.setNotify events..

My problem is that the first mouse click seems to get seen twice - so when you click to go from screen 1 to screen 2, you end up in screen 3: ie the user is pressing the button once in screen 1, but the program seems to think it has been pressed once in screen 1 AND once in screen 2..

I've written a test function using keyboard button presses instead of mouse clicks and it works fine like this - so it seems to be a problem with the Mouse.setNotify event rather than just a bug in my actionscript..

I also saw in the knowledgebase the FAQ about buttons firing twice and the proposed solution of activating the code inside an interval - and I've tried this but the solution isn't working for me..

I'm very much a Northcode newbie - so I apologise if I'm misunderstanding something fundamental!

Here is my code: if anyone can give me some pointers as to what is wrong it would be greatly appreciated!

Many thanks,

Sam.

screen = "attractor";

//setup northcode button events

ssCore.init();

ssCore.Mouse.setNotify({event:"onMouseButton"},{callback:"onMouseButton", scope:this});

function onMouseButton(ret_obj, cb_obj, err_obj) {
//try northcode timing fix from Knowledge base:
id = setInterval(function () {
clearInterval(id);
doClick(ret_obj);
}, 100);

function doClick(ret_obj) {

if (ret_obj.success) {
v = ret_obj.result.split(",");

switch (v[0]) {
case "LEFT" :
buttonPressed("left");
ssDebug.trace("LEFT");

break;

case "MIDDLE" :
buttonPressed("middle");
ssDebug.trace("MIDDLE");

break;

case "RIGHT" :
buttonPressed("right");
ssDebug.trace("RIGHT");
}
}

}
}


// keyboard event to simulate northcode:

var keyListener:Object = new Object();
keyListener.onKeyDown = function() {
switch (Key.getAscii()) {

case 49 :
trace("pressed 1");
buttonPressed("left");
break;
case 50 :

trace("pressed 2");
buttonPressed("middle");
break;
case 51 :
trace("pressed 3");
buttonPressed("right");
break;
}
};
Key.addListener(keyListener);

//prefectmatch version 1
//resolution set to WXGA = 1366 x 768

//start by loading in attractor sscreen
loadScreen("attractor");

function buttonPressed(whichButton) {

switch (screen) {

case "attractor" :
// if any button was pressed during attractor screen, load in choose character screen
screen = "character";
loadScreen("character");
break;

case "character" :
//if LEFT pressed, go to Laura, if RIGHT pressed, go to Bob..
switch (whichButton) {
case "left" :
screen = "laura";
loadScreen(screen);
break;
case "right" :
screen = "bob";
loadScreen(screen);
break;
}
}
ssDebug.trace("you pressed"+whichButton+"in"+screen);
}

function loadScreen(which_screen) {
switch (which_screen) {
case "attractor" :
_root.attachMovie("attractor","attractor",1);
_root.attractor.onMouseDown = function() {
trace("start game");
};
break;
case "character" :
_root.attachMovie("character","character",1);
break;
case "laura" :
_root.attachMovie("laura","laura",1);
break;

}
}


Posted by smuella in SWF Studio V3 on Mar 17 2008, 07:39 am

Don't worry - I've worked out what was going on - I hadn't realised the mouseEvent sends two events - one for mouse down and one for mouse up

it works fine if you make it check which state is being sent - I'm now doing this like this and it seems to be happy!

if (ret_obj.success) {
v = ret_obj.result.split(",");

switch (v[0]) {
case "LEFT" :
if (v[1] == "UP") {
buttonPressed("left");
ssDebug.trace("LEFT");
}

break;