A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: AS 2.0 : .onMouseMove issues

  1. #1
    Junior Member
    Join Date
    Nov 2009
    Posts
    4

    AS 2.0 : .onMouseMove issues

    Okay, this is my first post and I am very new to Flash and AS still - I am sticking with 2.0 since I know more about that than 3.0 right now.

    I would like to make a portion of a site that is stimulated from the mouse being moved. So, as the user moves their mouse I want the timeline to change (for an image will load on each new timeline). So, it will be kind of like a flip book that is activated by the mouse moving. Hopefully that makes sense. Each scene a person will be moving (new picture in a new frame) as the mouse moves up or down.

    Here is the code I have so far (my newbie attempt!):

    -------

    stop();

    var MouseListener:Object = new Object();
    var oldY:Number;
    MouseListener.onMouseMove = function(){
    CheckDir(_ymouse);
    }
    function CheckDir(newY:Number){

    if(oldY > newY){
    gotoAndPlay (nextFrame + 1);
    }else if(oldY < newY){
    gotoAndPlay (prevFrame - 1);
    }
    oldY = newY;
    }
    Mouse.addListener( MouseListener);

    ------

    If anyone has any idea about what to do, that'd be fantastic.
    Thank you!

  2. #2
    Member
    Join Date
    Nov 2009
    Location
    Philadelphia
    Posts
    40
    How about this...
    set the total number of frames in your main timeline
    establish the stage height
    when the mouse moves - divide the total number of frames by the stage height THEN divide the mouse location by that to get the correct frame....


    PHP Code:

    stop
    ();

    var 
    totFrames:Number 50;
    var 
    stageHeight:Number Stage.height;

    var 
    MouseListener:Object = new Object();
    MouseListener.onMouseMove = function() {
        
    CheckDir(_ymouse);
        
    };


    function 
    CheckDir(newY:Number) {
        var 
    newFrame:Number Math.ceil(_ymouse/(stageHeight/totFrames));
        
    this.gotoAndStop(newFrame);
        
        
        
        
    myText.text "frame #"+this._currentframe+" / "+newY+":mouse y";
    }
    Mouse.addListener(MouseListener); 
    check out my website... i put up an example:
    my site
    once there, click the link: Set the current frame based on the mouse location
    - Nick Stanziani

    pls support: www.whowantsacookie.com

    My site: pebcak

  3. #3
    Junior Member
    Join Date
    Nov 2009
    Posts
    4
    Perfect. It works like a charm!

    Thank you so much for your quick and efficient response! *tears of happiness* lol

  4. #4
    Member
    Join Date
    Nov 2009
    Location
    Philadelphia
    Posts
    40
    no problem... to show your appreciation you can order some cookies. ;-)
    - Nick Stanziani

    pls support: www.whowantsacookie.com

    My site: pebcak

  5. #5
    Junior Member
    Join Date
    Nov 2009
    Posts
    4
    LoL - I would love to, but give me a couple weeks til I graduate and finish this project! I promise!

    But now I have another question. So everything works great, but Im trying to get the actionscript to stop doing it (the Y movement) on a different part of the time line. In this area there is just a shape tween which causes the screen to go white. (Then a movie will play). But, if I move my mouse during the white screen, it goes back to the earlier part of the timeline with the Y movement area. How do I make it stop? stop(); just isn't cutting it. I even told the earlier script to only pay attention to frames 1 - 154, and everything else (the tween and the stop(); white screen) is 155 - 170. So, how is it going back? Is there any way to stop it from going back? Maybe Im totally missing something really simple. But Im totally stumped! Hope you can help me out on this one!

  6. #6
    var x:Number = 1; x /= 0;
    Join Date
    Dec 2004
    Posts
    549
    Code:
    delete MouseListener.onMouseMove();
    Z¡µµ¥ D££

    Soup In A Box

  7. #7
    Junior Member
    Join Date
    Nov 2009
    Posts
    4
    That sort of worked. I had to put that in the last frame of the timeline and also put in this:

    var totFrames:Number = 0;


    Thats what ended up causing the script to stop all together. Without that it didn't work and it would just go back to the beginning of the timeline.

    Thanks for all the help!

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