Groups | Blog | Home
all groups > flash actionscript > june 2006 >

flash actionscript : Substitute from spacebar to mouse



IndianChsPrdctns
6/3/2006 8:30:37 PM
I have 2 snippets of code for a game. In the code, the spacebar key is defined
as "jump". I want to use a left mouse click instead of the space bar to
perform the action, however. The code snippets are quite lengthy, but I have
no other choice. Here is the first code:

<i>
if (Key.isDown(jump) && g == "on" && tunnel != "on")
{
if (jumpdown == "off")
{
if (duck == "on")
{
_root.fx.fx("dash");
dash = "on";
}
else
{
_root.fx.fx("jump");
makejump();
} // end if
} // end else if
jumpdown = "on";
}
else
{
jumpdown = "off";
} // end else if
if (duck != "on" && dash == "on")
{
_root.fx.fx("dashoff");
x = _xscale / 100 * 15;
roll = "on";
dash = "off";
} // end if
if (roll == "on" && x <= 2 && x >= -2)
{
roll = "off";
} // end if
tunnel = "off";
} // End of the function
</i>

And now the second:

<i>
if (Key.isDown(jump))
{
if (jumpdown == "off")
{
if (chara == "tails" || chara == "cream")
{
if (fly == "off")
{
if (j == "on")
{
fly = 100;
j = "off";
} // end if
}
else if (fly > 0)
{
if (y < 2)
{
y = y + 1;
}
else
{
y = 2;
} // end if
} // end if
} // end else if
} // end else if
jumpdown = "on";
}
else
{
jumpdown = "off";
} // end else if
} // End of the function
</i>

You can probably tell which kind of game I am making from the code. ;)
NSurveyor
6/3/2006 8:43:54 PM
I guess the easiest way is to use jump=1;

However, if this code is going inside an onKeyDown event handler, it will not
pick up the click. So, you would have to put this code in a loop (e.g.
onEnterFrame)
juankpro
6/3/2006 9:27:11 PM
An error like that is called a sintax error. This error does not mean that
flash cannot do it. It means that you have forgotten to type something or that
you wrote something that is not right.
In the first snipped the last bracket does not have to be in there.

If you want to use the mouse, well yes, there is actually a handler caller
onMouseDown.
AddThis Social Bookmark Button