Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 01-02-2009, 05:07 PM   #1
wyattt
Registered User
 
Join Date: Dec 2008
Posts: 5
Default mouseX problems

Hey there,

I'm new to AS3 and programming in general actually. I've ran through the basics of AS3 and now for more practice I am working on translating some AS2 tutorials into AS3.

While working on something really simple I discovered some problems with mouseX. My code is error free, but I'm not getting the results that I want with the code in question.

ActionScript Code:
package {     import flash.display.MovieClip;     import flash.events.Event;     public class Character extends MovieClip {         public function Character() {             addEventListener(Event.ENTER_FRAME, moveCharacter);         }         public function moveCharacter(event:Event) {             this.x = stage.mouseX;         }     } }

I have a movieclip positioned on the stage already, and all I want is for my MC to follow my mouse. This may be more due to what I'm doing in Flash itself, but it only works the way I want to if I have the crosshair on the MC positioned exactly in the middle of the very left side of my stage. If I put the MC in the middle, it moves left and right with my mouse, but it's way off to the right of where my mouse is. What exactly am I doing wrong?

Thanks for the help!
wyattt is offline   Reply With Quote
Old 01-02-2009, 05:40 PM   #2
G.Bob
Registered User
 
Join Date: Dec 2008
Posts: 11
Default

Hi. Try removing "stage." before mouseX. mouseX is just mouseX.
G.Bob is offline   Reply With Quote
Old 01-03-2009, 01:23 AM   #3
runawayprisoner
ActionScripted
 
Join Date: Nov 2008
Posts: 94
Default

Quote:
Originally Posted by wyattt View Post
Hey there,

I'm new to AS3 and programming in general actually. I've ran through the basics of AS3 and now for more practice I am working on translating some AS2 tutorials into AS3.

While working on something really simple I discovered some problems with mouseX. My code is error free, but I'm not getting the results that I want with the code in question.

ActionScript Code:
package {     import flash.display.MovieClip;     import flash.events.Event;     public class Character extends MovieClip {         public function Character() {             addEventListener(Event.ENTER_FRAME, moveCharacter);         }         public function moveCharacter(event:Event) {             this.x = stage.mouseX;         }     } }

I have a movieclip positioned on the stage already, and all I want is for my MC to follow my mouse. This may be more due to what I'm doing in Flash itself, but it only works the way I want to if I have the crosshair on the MC positioned exactly in the middle of the very left side of my stage. If I put the MC in the middle, it moves left and right with my mouse, but it's way off to the right of where my mouse is. What exactly am I doing wrong?

Thanks for the help!
You are moving the whole DisplayObjectContainer, which is "this" as you are putting it, therefore... something in the middle of it is obviously not going to be right where your mouse is.

The correct way to do it would be either this:

mc.x = stage.mouseX; //(or mouseX)

Or this:

getChildAt(0).x = mouseX; // First symbol you ever create on the stage will follow the mouse
runawayprisoner 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

Similar Threads
Thread Thread Starter Forum Replies Last Post
AS 2.0 - Cannon game problems ScionOfWar Gaming and Game Development 0 09-06-2008 09:28 PM
Major Problems with Depth and Components Veleek Components 15 01-16-2008 04:31 PM
Problems with onClipEvent handler? crusher ActionScript 2.0 2 02-26-2007 03:26 AM
Problems with Loading Text Into a Textbox holdaway ActionScript 2.0 6 02-03-2004 04:21 AM
levels, linkage of audio, and load movie problems to a specfic frame problems ooolie ActionScript 1.0 (and below) 0 12-05-2002 07:54 PM


All times are GMT. The time now is 07:15 PM.

///
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.