-
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?
-
Client Software Programmer
PHP Code:
this.addEventListener(MouseEvent.MOUSE_MOVE, showLD2);
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
-
Yes, getting it to fade was my actual plan.
-
Client Software Programmer
this.addEventListener(MouseEvent.MOUSE_MOVE, showLD2);
function showLD2 (e:MouseEvent):void {
LD2nd.alpha=(mouseY-LD2nd.y)/LD2nd.height
}
-
Wow, the code provides an even more cooler effect than I was looking for. A million thanks
-
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.
-
Client Software Programmer
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
}
-
 Originally Posted by Alloy Bacon
PHP Code:
this.addEventListener(MouseEvent.MOUSE_MOVE, showLD2);
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
-
Client Software Programmer
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.
-
 Originally Posted by Alloy Bacon
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.
-
Client Software Programmer
PHP Code:
stop(); var LDSroot = MovieClip(root).LDS; stage.addEventListener(MouseEvent.MOUSE_MOVE, peekOff);
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
-
Client Software Programmer
wait use this:
PHP Code:
stop(); var LDSroot = MovieClip(root).LDS; stage.addEventListener(MouseEvent.MOUSE_MOVE, peekOff);
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; } }
-
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.
-
Client Software Programmer
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
-
Client Software Programmer
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");
}
}
-
Client Software Programmer
That's a really nice window that appears by the way it has like a clear red
-
Okay thanks much, I will incorporate your suggestions and give feedback. Fingers crossed if everything works!
-
 Originally Posted by Alloy Bacon
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.
-
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.
-
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|