all groups > flash actionscript > february 2006 >
You're in the

flash actionscript

group:

Holding Mouse button down


Holding Mouse button down FrogCdrom
2/27/2006 8:36:37 PM
flash actionscript: Hi all,
Im completely new to Flash and am struggling to get a simple thing working:

I have a "MovieClip" (called "gadget") within my scene which is made up of two
"Buttons" (but_burn and but_sandbag)

I need to know when the user is holding the left mouse button down within the
"but_burn" button.

This code lives on MovieClip "gadget" layer in the Scene:
var p_mouseDown:Boolean = false;
but_burn.onPress = function() {
p_mouseDown = true;
};
burnButton.onRelease = function() {
p_mouseDown = false;
};

And then on another layer in the same Scene is the object controlled by those
buttons. It has this script:
var g_balloonVertSpeed:Number = 0;
this.onEnterFrame = function() {
moveBalloon();
};
function moveBalloon() {
if(but_burn.p_mouseDown==true) {
g_balloonVertSpeed --;
if(g_balloonVertSpeed < -6) {
g_balloonVertSpeed = -6
}
} else {
g_balloonVertSpeed ++;
if(g_balloonVertSpeed > 6) {
g_balloonVertSpeed = 6
}
}
balloon._y += g_balloonVertSpeed;
};

P.S. its a hot air balloon game and the "but_burn" button controls the burner
to go up.

Many many thanks in advance of any and all help given.

** if only all coding was Lingo ** ;)
Re: Holding Mouse button down FrogCdrom
2/27/2006 9:18:53 PM
Is it something to do with:

if(but_burn.p_mouseDown==true) {

The p_mouseDown property doesnt seem to be changing at all

Re: Holding Mouse button down FrogCdrom
2/27/2006 9:26:18 PM
moving all the code into the "actions" layer, and adding the "gadget" MovieClip object reference here:

gadget.but_burn.onPress = function() {
p.mouseDown = true
};

Re: Holding Mouse button down blemmo
2/27/2006 9:31:53 PM
You have some path issues here... The burn button is inside the MC instance
"gadget", so you must add that name (if you have the code on the main timeline):
gadget.but_burn.onPress = ...
gadget.but_burn.onRelease = ...

Then, in the function moveBalloon, you don't need any path:
if(p_mouseDown==true) ...
because p_mouseDown is a variable on the main timeline.

hth,
blemmo
AddThis Social Bookmark Button