Making a shooting game, would like the gun to flip _xscale

I’m making a shooting game, would like the gun to flip _xscale when you move the gun past half the width of the stage.

Here’s the script I made which doesn’t work and is probably not written correctly:

if(_xmouse >= Stage.width/2){
_root.gun_mc._xscale * -1;
}

Thanks ahead for your reply/answers

-Line

I guess I should also add that, the gun_mc is following the mouse on the x axis in case anyone is confused.

-Line

[quote=Line;2335042]I’m making a shooting game, would like the gun to flip _xscale when you move the gun past half the width of the stage.

Here’s the script I made which doesn’t work and is probably not written correctly:

if(_xmouse >= Stage.width/2){
_root.gun_mc._xscale * -1;
}

Thanks ahead for your reply/answers

-Line[/quote]

if (_xmouse >= Stage.width / 2) {
 _root.gun_mc._xscale *= -1;
}

Thanks Glos, you were close, the *= is the correct usage to multiply. What I didn’t know was that the number is the percentage and not an actual number to multiply by. So the number is -100.

Only downside to the script that we have now is that it only occured once. I needed a listener or something to keep checking to see if the x coordinate of the mouse had changed.

The script that seems to be working correctly is:

_root.onMouseMove = function(){
if(_xmouse >= Stage.width/2){
trace(“it is at more than half!”);
_root.gun_mc._xscale = 100;
}else{
trace(“it is at less than half!”);
_root.gun_mc._xscale = -100;
}
}

Thanks for replying!
-Line

[quote=glosrfc;2335053] ActionScript Code:
[LEFT][COLOR=#0000FF]if[/COLOR] [COLOR=#000000]([/COLOR][COLOR=#0000FF]_xmouse[/COLOR] >= [COLOR=#0000FF]Stage[/COLOR].[COLOR=#0000FF]width[/COLOR] / [COLOR=#000080]2[/COLOR][COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]
[COLOR=#0000FF]_root[/COLOR].[COLOR=#000080]gun_mc[/COLOR].[COLOR=#0000FF]_xscale[/COLOR] *= -[COLOR=#000080]1[/COLOR];
[COLOR=#000000]}[/COLOR]
[/LEFT]

[/quote]

So the number is -100?

Let’s say that your movie is 50 pixels wide:
_xscale= 100; // mc is still 50 pixels wide
_xscale*= -1 // 100 * -1 = -100 so mc is flipped but still 50 pixels wide
As you can see, = -100 and *= -1 are both the same

But what if you’ve already resized your movie, say by 50%?
_xscale= 50; // mc is resized to 25 pixels wide

Now, if you use _xscale= -100, your movie is flipped but it reverts back to the original 50 pixel width. However, if you use _xscale*= -1, then 50 * -1 = -50 so your movie is flipped but it still retains your amended scaling of 25 pixels.

So -100 isn’t the number in these circumstances. Hope that explanation helps.

And updateAfterEvent() might help solve the other problem…check it out in the Help files.