A Flash Developer Resource Site

Results 1 to 9 of 9

Thread: MC to Follow Mouse Horizantially - ASAP Help

  1. #1
    Member
    Join Date
    Sep 2009
    Location
    Florida
    Posts
    60

    MC to Follow Mouse Horizantially - ASAP Help

    I am trying to make a menu bar that when the mouse moves around from button to button it has a bar that follows under the text.I have found scripts for making a MC follow a mouse around the screen but I cant find anything for what I need. Can anyone help me with this, I need this asap because it is for a project Im working on for school. I would appreciate any help

    Thanks Chris

  2. #2
    Senior Member
    Join Date
    Dec 2010
    Posts
    121
    Why not put the menu into a movie clip and use the same code you found?

  3. #3
    Member
    Join Date
    Sep 2009
    Location
    Florida
    Posts
    60
    what do you mean?

  4. #4
    Senior Member
    Join Date
    Dec 2010
    Posts
    121
    Why don't you just make the menu bar into a movie clip and has its x coordinate follows the mouse?

  5. #5
    Senior Member x-death's Avatar
    Join Date
    Aug 2009
    Posts
    175
    ok so maybe something like this:
    Actionscript Code:
    btn1.addEventListener(MouseEvent.MOUSE_OVER,runCode);
    btn2.addEventListener(MouseEvent.MOUSE_OVER,runCode);
    btn3.addEventListener(MouseEvent.MOUSE_OVER,runCode);

    function runCode(evt:MouseEvent){
        var tween:Tween = new Tween(myBar,"x",Strong.easeInOut,myBar.x,evt.currentTarget.x,1.5,true);
    }

    this is just an example. it moves your bar from its current location to the button you mouse over. i assume you wanted it to move over to the button rather then just appear there?

    if you want it to just appear there then use this:
    Actionscript Code:
    btn1.addEventListener(MouseEvent.MOUSE_OVER,runCode);
    btn2.addEventListener(MouseEvent.MOUSE_OVER,runCode);
    btn3.addEventListener(MouseEvent.MOUSE_OVER,runCode);

    function runCode(evt:MouseEvent){
        myBar.x=evt.currentTarget.x;
        myBar.y=evt.currentTarget.y;
    }

    anyways hope this has helped you

  6. #6
    Ө_ө sleepy mod
    Join Date
    Mar 2003
    Location
    Oregon, USA
    Posts
    2,441
    PHP Code:
    stage.addEventListener(Event.ENTER_FRAME, function(e:Event):void{
    //    bar.x = stage.mouseX;                        //  no easing
        
    bar.-= (bar.stage.mouseX) / 2.5;        //  Zeno's paradox easing
    }); 
    Please use [php] or [code] tags, and mark your threads resolved 8)

  7. #7
    Member
    Join Date
    Sep 2009
    Location
    Florida
    Posts
    60
    Quote Originally Posted by neznein9 View Post
    PHP Code:
    stage.addEventListener(Event.ENTER_FRAME, function(e:Event):void{
    //    bar.x = stage.mouseX;                        //  no easing
        
    bar.-= (bar.stage.mouseX) / 2.5;        //  Zeno's paradox easing
    }); 
    Awesome thanks this worked..

  8. #8
    Member
    Join Date
    Sep 2009
    Location
    Florida
    Posts
    60
    what code would I add that once my mouse left the stage the bar goes back to a certain X value? I appreciate your help with this.

  9. #9
    Ө_ө sleepy mod
    Join Date
    Mar 2003
    Location
    Oregon, USA
    Posts
    2,441
    Give this a try

    PHP Code:
    var barTarget:Number 250;

    stage.addEventListener(Event.ENTER_FRAME, function(e:Event):void
        if(
    stage.mouseX || stage.mouseX stage.stageWidth) return;
        
    barTarget stage.mouseX;
    });

    stage.addEventListener(Event.MOUSE_LEAVE, function(e:Event):void{
        
    barTarget 250;
    });

    stage.addEventListener(Event.ENTER_FRAME, function(e:Event):void{
        
    bar.-= (bar.barTarget) / 2.5;
    }); 
    Please use [php] or [code] tags, and mark your threads resolved 8)

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