Solved

How do I change an instance of movieClip based on the direction the cursor moves?

Posted on 2009-05-07
6
291 Views
Last Modified: 2013-11-11
I am trying to make something fly around the screen based on the user's control of the mouse. I've attached the movie clip via the method below. I'm looking for some kind of if statement to recognize if the mouse is reaching a positive or negative increment from it's previous position and then change the movieClip (cursor_mc) to another frame.

Thanks!
cursor_mc.startDrag("true"); 

Mouse.hide();

Open in new window

0
Comment
Question by:squarelight
  • 3
  • 2
6 Comments
 
LVL 22

Expert Comment

by:rascalpants
ID: 24332425
you could use an onEnterFrame event, or a MouseMove (preferred) event to check for the previous x position compared to the current.

rp / ZA
0
 
LVL 1

Expert Comment

by:fario
ID: 24336701
0
 

Author Comment

by:squarelight
ID: 24338088
fario - i tagged this as an as2 file but I didn't mention it in my post. I am working in as2, not as3.

I've found some code that works and have attached it below. One more thing I would like to do is unload or override the function so that xscale = 100 when a button is clicked. Can anyone help me with that?
onClipEvent(enterFrame) {
 

horizontal_check = function () {

        this.createEmptyMovieClip('tempx', this.getNextHighestDepth());

    tempx.lastX=tempx._root._xmouse;

        tempx.onMouseMove = function() {

                if (this._root._xmouse>this.lastX) {

            trace('moving right');

			_parent.cursor_mc._xscale = -100;

        } else {

            trace('moving left');

			_parent.cursor_mc._xscale = 100;

                }

    this.lastX=this._root._xmouse;

        };

};

horizontal_check();
 

}

Open in new window

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 22

Expert Comment

by:rascalpants
ID: 24341454
squarelight,

you are going it wrong...  you are using both an onEnterFrame and an onMouseMove method to do your if/then conditional statement...

you really need to separate then, or better yet, choose one or the other...

I would do something more like the below(using your code)...  it only does the check when you move your mouse, so your processing isn't going crazy.


now my code assumes you want the cursor_mc MovieClip to be the item that scales based on the position...  

Is this the desired effect you wanted?


rp / ZA



import mx.utils.Delegate;
 

cursor_mc.startDrag("true");

Mouse.hide();
 

cursor_mc.initScale = cursor_mc._xscale;

cursor_mc.lastX = _xmouse;
 
 

cursor_mc.onMouseMove = Delegate.create( this, horizontal_check );
 

horizontal_check()

{

     if ( _xmouse > cursor_mc.lastX)

     {

         trace('moving right');

         cursor_mc._xscale = cursor_mc.initScale;

     }

     else

     {

         trace('moving left');

         cursor_mc._xscale = 100;

     }

    cursor_mc.lastX = _xmouse;

}

Open in new window

0
 

Author Comment

by:squarelight
ID: 24357721
Thanks, rascalpants. I tried your code and it only traces when you are moving left. Am I missing something? I'll play with it some more.
0
 
LVL 22

Accepted Solution

by:
rascalpants earned 50 total points
ID: 24364772
looks like I just forgot to put the keyword function before horizontal_check()
also, I am not sure of this, but what initially scales the cursor_mc clip? the code will only work if you have some other code or seomthing scaling the movieclip first...
so you might change  "cursor_mc.initScale = cursor_mc._xscale"  
to
"cursor_mc.initScale = 50;"


rp / ZA








import mx.utils.Delegate;

 

cursor_mc.startDrag("true");

Mouse.hide();

 

cursor_mc.initScale = cursor_mc._xscale;

cursor_mc.lastX = _xmouse;

 

 

cursor_mc.onMouseMove = Delegate.create( this, horizontal_check );

 

function horizontal_check()

{

     if ( _xmouse > cursor_mc.lastX)

     {

         trace('moving right');

         cursor_mc._xscale = cursor_mc.initScale;

     }

     else

     {

         trace('moving left');

         cursor_mc._xscale = 100;

     }

    cursor_mc.lastX = _xmouse;

}

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
Recently, I was asked to recommend a tracking system to be implemented on a clients website. As the entire site was built on flash, my first thought was to suggest custom built tracking system. However, our company at that point of time didn't h…
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): …
The goal of the tutorial is to teach the user how to select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.

867 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now