A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: Mouse X position altering object

  1. #1
    Junior Member
    Join Date
    Jul 2009
    Posts
    7

    Mouse X position altering object

    Hello

    I want to do something which is probably pretty simple but I've got absolutely no idea how to do it!

    What I want is for the Alpha value of an object (movie clip) to change depending on the x position of the mouse. So when the mouse is at 0 the alpha of the object will be 0%, and when it's at 100 the alpha will be 100%

    Does that make sense?

    Hope someone can help!
    Last edited by Spiritualized; 11-20-2009 at 11:32 AM.

  2. #2
    Member
    Join Date
    Nov 2009
    Location
    Philadelphia
    Posts
    40
    there are a bunch of different ways to do this using AS2... here is one.
    I'm assuming you mean the 'x' coordinate of the mouse.
    You will assign the x value '_xmouse' to the alpha value '_alpha' of the movie clip.

    PHP Code:
    MovieclipInstanceName._alpha _xmouse
    this is assuming that the x value of the mouse cursor will not go above 100 or if it does, you don't care...

    the next question is how often you want this to update... here is a simple way to get it to update whenever the mouse moves.

    PHP Code:
    onMouseMove = function(){
        
        
    MovieclipInstanceName._alpha _xmouse;

    - Nick Stanziani

    pls support: www.whowantsacookie.com

    My site: pebcak

  3. #3
    Junior Member
    Join Date
    Jul 2009
    Posts
    7
    Ok, thanks a lot for that I've got that working. However I need something a bit more complicated than that, and I thought maybe if I knew how to do what you've said I could work it out, but I dont think I can.

    Basically I've got 3 movie clips, and my stage is 1000 pixels wide.

    I want the first clip to have 100% alpha when the x value is in between 0 and 200. Then between 201-300 I want the alpha to decrease 1% for every pixel, like in the example you showed me. As well as this I want the alpha value of clip 2 to increase, so when it gets to 300 you can only see clip 2. Then I want this to happen again for clip 3 at about 600 pixel across.

    So I kind of know what I need to do Im just not really sure how to go about using the code. I assume its like, if _xmouse <=200, then clip1._alpha = 100 , but then I dont know how to make it go down by one.

    Hope that makes sense, I'm very grateful for any help as I can't get my head around code!

  4. #4
    Member
    Join Date
    Nov 2009
    Location
    Philadelphia
    Posts
    40
    I'm a technical instructor so this goes against my instinct to just give you the anwser since it just comes down to math and logic but here it is... I could think of more elegent ways to do this but choose to put it in as simple code as possible...

    you can tweak bound1 and bound2 variables to get the results you want:

    PHP Code:
    var bound1:Number 200;
    var 
    bound2:Number 300;

    onMouseMove = function () {
        if(
    _xmouse<=bound1){
            
    mc1._alpha 100
            mc2
    ._alpha mc3._alpha 0;
        }
        else if (
    _xmouse>bound1 && _xmouse<=bound2) {
            
    mc1._alpha 100-(_xmouse-bound1);
            
    mc2._alpha 100-mc1._alpha;
            
    mc3._alpha 0;
        } else if (
    _xmouse>bound2) {
            
    mc1._alpha 0;
            
    mc2._alpha 100-(_xmouse-bound2);
            
    mc3._alpha 100-mc2._alpha;
        }
        
    }; 
    now order some cookies from my company... ;-)
    Last edited by nstanziani; 11-20-2009 at 04:14 PM. Reason: typo
    - Nick Stanziani

    pls support: www.whowantsacookie.com

    My site: pebcak

  5. #5
    Junior Member
    Join Date
    Jul 2009
    Posts
    7
    Thanks so much thats working fine. I know what you mean I had hoped to work it out but I've got barely any knowledge of AS, I'm a designer and I just needed it to show a prototype of something.

    Thanks again

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center