Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 04-19-2010, 03:47 AM   #1
Zukky
Registered User
 
Join Date: Apr 2010
Posts: 4
Exclamation [AS3] How to make a "gun" move with mouse?

Hi,
i'm new to the whole Actionscript scene and i'm eager to get to grips with Flash CS4 and Actionscript 3.0.

I want to make a mini-game (a prototype) and I want to make a simple target shooter.

I have a gun and a crosshair. I want to move the gun and the crosshair via the mouse x and y co-ordinates.

I have been searching for hours and I can't seem to make it work, I can only make it work using keyboard inputs.

Can someone please point me in the right direction and/or give me the code needed? This would be much appreciated.

Thank you, Zukky.
Zukky is offline   Reply With Quote
Old 04-19-2010, 04:40 AM   #2
svenjoypro
DontJustEnjoyIt,SvEnjoyIt
 
svenjoypro's Avatar
 
Join Date: Sep 2005
Location: California
Posts: 1,389
Default

This is a tutorial for a custom cursor, but your situation should be similar:
http://www.republicofcode.com/tutori...ash/cursor_bc/

If you don't want to do it that way, you can look into event listeners, specifically MouseEvent.MOUSE_MOVE.
svenjoypro is offline   Reply With Quote
Old 04-19-2010, 04:40 AM   #3
Artofwork
Senior Member
 
Join Date: Feb 2010
Posts: 180
Default

when you make your object export it to actionscript with the name crossHair

Just changed the name of the object from heart to crosshair
Source:
PHP Code:
http://biochimistu.blogspot.com/2008/02/animated-custom-cursor-actionscript-30.html 
ActionScript Code:
Mouse.hide(); var angle:Number = 0; var heartScale:Number = 0.5; var range:Number = 0.05; var speed:Number = 10; var crosshair:crossHair = new crossHair(); addChild(crosshair); stage.addEventListener(Event.ENTER_FRAME, enterFrameHandler); function enterFrameHandler(event:Event):void { crosshair.mouseEnabled = false; crosshair.x = mouseX; crosshair.y = mouseY; crosshair.scaleX = crosshair.scaleY = heartScale + Math.sin(angle) * range; angle += speed; }
Attached Files
File Type: zip crosshairs.zip (5.7 KB, 161 views)

Last edited by Artofwork; 04-19-2010 at 04:43 AM.
Artofwork is offline   Reply With Quote
Old 04-19-2010, 05:54 PM   #4
Zukky
Registered User
 
Join Date: Apr 2010
Posts: 4
Default

Omg! Thank you so much Artofwork and svenjoypro! That was unbelievably helpful! Artofwork, your code helped me perfectly, now I just need to work out how I'm going to make the gun animate when I left click! Thx peeps !
Zukky is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 11:54 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.