A Flash Developer Resource Site

Page 1 of 2 12 LastLast
Results 1 to 20 of 27

Thread: Movie clip visibility triggered by Mouse position

  1. #1
    Member
    Join Date
    Jan 2018
    Posts
    31

    Movie clip visibility triggered by Mouse position

    I am trying to toggle the visibility of a movieclip on the condition that mouseY is within a specific position. Code below is my approach

    Code:
    this.addEventListener(MouseEvent.MOUSE_MOVE, showLD2);
    
    function showLD2 (e:MouseEvent):void {
    		if (mouseY >= 614){
    		LD2nd.visible = true;
    		}else 
    		{
    		LD2nd.visible = false;
    		}
    }
    However, the problem is the movieclip is hidden immediately at the slightest move of the mouse instead of when the mouse is at the specified position. What might be wrong with my approach?

  2. #2
    Client Software Programmer AS3.0's Avatar
    Join Date
    Apr 2011
    Posts
    1,404
    PHP Code:
    this.addEventListener(MouseEvent.MOUSE_MOVEshowLD2);

    function 
    showLD2 (e:MouseEvent):void {
            if (
    mouseY <= LD2nd.y+LD2nd.height/2){
            
    LD2nd.visible true;
            }else 
            {
            
    LD2nd.visible false;
            }

    do you want it to fade based on position? the above scripts makes it disappear when your mouse passes the center of the mc

  3. #3
    Member
    Join Date
    Jan 2018
    Posts
    31
    Yes, getting it to fade was my actual plan.

  4. #4
    Client Software Programmer AS3.0's Avatar
    Join Date
    Apr 2011
    Posts
    1,404
    this.addEventListener(MouseEvent.MOUSE_MOVE, showLD2);

    function showLD2 (e:MouseEvent):void {
    LD2nd.alpha=(mouseY-LD2nd.y)/LD2nd.height
    }

  5. #5
    Member
    Join Date
    Jan 2018
    Posts
    31
    Wow, the code provides an even more cooler effect than I was looking for. A million thanks

  6. #6
    Member
    Join Date
    Jan 2018
    Posts
    31
    I kind of discovered that the code can only work when executed from the main timeline. I have been trying to get it to work from the timeline of a movieclip.

  7. #7
    Client Software Programmer AS3.0's Avatar
    Join Date
    Apr 2011
    Posts
    1,404
    addEventListener(MouseEvent.MOUSE_MOVE, showLD2);
    function showLD2 (e:MouseEvent):void {
    MovieClip(root).LD2nd.alpha=(MovieClip(root).mouse Y-MovieClip(root).LD2nd.y)/MovieClip(root).LD2nd.height
    }

  8. #8
    Member
    Join Date
    Jan 2018
    Posts
    31
    Quote Originally Posted by Alloy Bacon View Post
    PHP Code:
    this.addEventListener(MouseEvent.MOUSE_MOVEshowLD2);

    function 
    showLD2 (e:MouseEvent):void {
            if (
    mouseY <= LD2nd.y+LD2nd.height/2){
            
    LD2nd.visible true;
            }else 
            {
            
    LD2nd.visible false;
            }

    do you want it to fade based on position? the above scripts makes it disappear when your mouse passes the center of the mc
    Thanks for your earlier reply. I am sorry I was not entirely clear in my last question. What I meant to say is that I discovered that the above code you previously provided alongside with my initial code they both seem to only work when placed in the main timeline and regardless of if I put in the MovieClip(root).mouseY . I have reasons to believe that the X and Y values of the mouse can only be accessed or used from the main timeline. I'm sorry for been such a noob and perhaps a pest

  9. #9
    Client Software Programmer AS3.0's Avatar
    Join Date
    Apr 2011
    Posts
    1,404
    if you just do mouseY alone inside the movieclip timeline, y=0 from the movieclips first pixel, if you do MovieClip(root).mouseY y=0 will start at the first pixel of the swf.

  10. #10
    Member
    Join Date
    Jan 2018
    Posts
    31
    Quote Originally Posted by Alloy Bacon View Post
    if you just do mouseY alone inside the movieclip timeline, y=0 from the movieclips first pixel, if you do MovieClip(root).mouseY y=0 will start at the first pixel of the swf.
    I don't fully get your explanation but here is my code embedded inside a movieclip "worpan" and using the MovieClip(root).mouseY syntax.


    Code:
    var LDSroot = MovieClip(parent).LDS;
    LDSroot.addEventListener(MouseEvent.MOUSE_OUT, peekOff);
    
    function peekOff (e:MouseEvent):void {
    		if ( MovieClip(root).mouseY <= LDSroot.Y-44) {
    		gotoAndStop(2);   //the "worpan" playhead should go to frame 2 
    		LDSroot.visible=false;  //the e.target movieclip should dissappear
    		LD2nd.alpha=1;
    		}
    }
    No response either way, except if pasted on the Fla. main timeline were it works perfectly with or without the MovieClip(root).mouseY syntax
    Last edited by Solowalker; 01-12-2018 at 02:55 AM.

  11. #11
    Client Software Programmer AS3.0's Avatar
    Join Date
    Apr 2011
    Posts
    1,404
    PHP Code:
    stop();
    var 
    LDSroot MovieClip(root).LDS;
    stage.addEventListener(MouseEvent.MOUSE_MOVEpeekOff);

    function 
    peekOff (e:MouseEvent):void {
            if (
    mouseY <= LDSroot.y-44) {
            
    trace("true")
            
    gotoAndStop(2);   //the "worpan" playhead should go to frame 2 
            
    LDSroot.visible=false;  //the e.target movieclip should dissappear
            
    MovieClip(root).LD2nd.alpha=1;
            }

    I would use MOUSE_MOVE instead of mouse out,if you use mouse out the mouse must be on the mc

  12. #12
    Client Software Programmer AS3.0's Avatar
    Join Date
    Apr 2011
    Posts
    1,404
    wait use this:
    PHP Code:
    stop();
    var 
    LDSroot MovieClip(root).LDS;
    stage.addEventListener(MouseEvent.MOUSE_MOVEpeekOff);

    function 
    peekOff (e:MouseEvent):void {
            if (
    MovieClip(root).mouseY <= LDSroot.y-44) {
            
    trace("true")
            
    gotoAndStop(2);   //the "worpan" playhead should go to frame 2 
            
    LDSroot.visible=false;  //the e.target movieclip should dissappear
            
    MovieClip(root).LD2nd.alpha=1;
            }


  13. #13
    Member
    Join Date
    Jan 2018
    Posts
    31
    Tried your suggestion but still no results. If you don't mind, I have attached below, a stripped down version of the overall project to which the problem belongs to. So if you could please review it maybe some insights to where the problem is might be possible#

    Striped sample.fla.

  14. #14
    Client Software Programmer AS3.0's Avatar
    Join Date
    Apr 2011
    Posts
    1,404
    in the main timeline, .visible hides mouse movements, take out the first line from the maintimeline and it works now, you can use alpha=0.0 to hide and still use mouse functions for next time

  15. #15
    Client Software Programmer AS3.0's Avatar
    Join Date
    Apr 2011
    Posts
    1,404
    instead of a bunch of event listener you can also use one for all 3 buttons like

    addEventListener(MouseEvent.CLICK, appExecute);
    function appExecute(e:MouseEvent){
    if(e.target.name=="workWindow"){
    trace("work window clicked");
    }else if(e.target.name=="desklet"){
    trace("desklet clicked");
    }else if(e.target.name=="LD2nd"){
    trace("LD2nd clicked");
    }
    }

  16. #16
    Client Software Programmer AS3.0's Avatar
    Join Date
    Apr 2011
    Posts
    1,404
    That's a really nice window that appears by the way it has like a clear red

  17. #17
    Member
    Join Date
    Jan 2018
    Posts
    31
    Okay thanks much, I will incorporate your suggestions and give feedback. Fingers crossed if everything works!

  18. #18
    Member
    Join Date
    Jan 2018
    Posts
    31
    Quote Originally Posted by Alloy Bacon View Post
    instead of a bunch of event listener you can also use one for all 3 buttons like

    addEventListener(MouseEvent.CLICK, appExecute);
    function appExecute(e:MouseEvent){
    if(e.target.name=="workWindow"){
    trace("work window clicked");
    }else if(e.target.name=="desklet"){
    trace("desklet clicked");
    }else if(e.target.name=="LD2nd"){
    trace("LD2nd clicked");
    }
    }
    Nice, this is one efficient approach I won't have thought of. Thanks.

  19. #19
    Member
    Join Date
    Jan 2018
    Posts
    31
    Erm..... it may seem that maybe I might have to find another approach to the problem; I am still unable to hide "LDS" and "workWindow" through mouse_move beyond the Y coordinates of "LDS" after it has been revealed/made visible by the mouse over on "LD2nd". But thanks greatly for your help, I learnt a lot. I may just have to think up a new approach rather than using mouseY vs mc.Y since it seems that there are some conflicts between stage. and this. call of the mouseY property.

  20. #20
    Member
    Join Date
    Jan 2018
    Posts
    31
    Update: I think I have finally figured it out. Replacing this.addEventListener with stage.addEventListener seems to solve the problem, however another approach was to tie the two functions that made use of the mouseY property under one Mouse_Move event place on the main timeline. (Idea borrowed from ur previous suggestion )

Tags for this Thread

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