Solved

MC follows mouse question

Posted on 2006-11-27
3
235 Views
Last Modified: 2010-04-03
Hi, Experts

I would like to make the MC follow the mouse. However, it is not really working.... The 1st layer MC instance name is "allMC" and there is another movie clip inside "allMC" called "fighter".... I want to control the "fighter" inside the "allMC". Thanks

--------------------  CODE  ---------------------

allMC.fighter._x = allMC.Stage.width/2;
allMC.fighter._y = allMC.Stage.height/2;
var myConstant = 5;
_root.onEnterFrame = function() {
      var destinationX = _root._xmouse/6;
      var destinationY = _root._ymouse/6;
      inertiaX = (destinationX-allMC.fighter._x)/myConstant;
      inertiaY = (destinationY-allMC.fighter._y)/myConstant;
      allMC.fighter._x += inertiaX;
      allMC.fighter._y += inertiaY;
      //fighter._xscale += inertiaX;
      //fighter._yscale += inertiaY;
      if (_xmouse<5 || _xmouse>295 || _ymouse<5 || _ymouse>245) {
            allMC.fighter._x = allMC.Stage.width/2;
            allMC.fighter._y = allMC.Stage.height/2;
      }
};
----------------------------------------------------------------
0
Comment
Question by:mingchih
  • 2
3 Comments
 
LVL 13

Expert Comment

by:FLAASHER
ID: 18022444
its work with me ..... its move the same direction as mouse

what kind of moving u want exactly ???



FLAASHER
0
 

Author Comment

by:mingchih
ID: 18022487
Hi, Flaasher

Thanks for the reply....here is the fla file and please take a look

http://www.4shared.com/file/6551562/d63677fa/dropBomGame2.html

Thanks
0
 
LVL 13

Accepted Solution

by:
FLAASHER earned 500 total points
ID: 18022765
allMC._x = Stage.width/2;
allMC._y = Stage.height/2;
var myConstant = 5;
_root.onEnterFrame = function() {
      var destinationX = _root._xmouse/1;
      var destinationY = _root._ymouse/1;
      inertiaX = (destinationX-allMC._x)/myConstant;
      inertiaY = (destinationY-allMC._y)/myConstant;
      allMC._x += inertiaX;
      allMC._y += inertiaY;
      //fighter._xscale += inertiaX;
      //fighter._yscale += inertiaY;
      if (_xmouse<5 || _xmouse>295 || _ymouse<5 || _ymouse>245) {
            allMC._x = Stage.width/2;
            allMC._y = Stage.height/2;
      }
};
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This is a very simple example to help those of you who are still migrating from AS2 to AS3 understand the redesigned event model in AS3. In AS2.0, event functions (that is, the function to be performed when an event is fired) were stored as a pro…
I come across a lot of question about how to access things in the document class from a movieclip, or accessing something from a movieclip in the document class. It took me a while to figure this out but once I did it makes life so much easier. …
In this tutorial viewers will learn how to create a basic motion tween animation in Flash Open a new document in Flash: Draw/import an image: Press CTRL + F8 to convert it into a graphic symbol: Select a frame (how long you want the tween to last): …
This Micro Tutorial will teach to how to utilize bit rate in Adobe Flash Media Live Encoder.

837 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question