-
MOUSE_OVER not sensitive enough?
Hi,
I'm trying to do a video playback control, like the normal ones, when you
mouseover the video, the control will appear. so I did this:
Code:
float.addEventListener(MouseEvent.MOUSE_OVER, getControl);
float.addEventListener(MouseEvent.MOUSE_OUT, removeControl);
private function getControl(e:MouseEvent):void {
if(mouseX > float.x + 20 && mouseX < float.x + 500 && mouseY > float.y + 20 && mouseY < float.y + 290) {
Tweener.addTween(bar_mc, {alpha:1, time:1});
}
}
private function removeControl(e:MouseEvent):void {
Tweener.addTween(bar_mc, {alpha:0, time:1});
}
I checked the code many times, but if I mouseover from the top of the
video, the control doesn't always appear, seems like if I move the mouse
faster, then it would appear. However, if I mouseover from the bottom, it
always appear... I find this really weird, does anyone know how to solve this?
Another thing is that although I set the eventlistener to detect mouseover to
a certain area, and the controlbar would appear, however, if my mouse is
over the controlbar, the controlbar would disappear. Why is that?
Here's the complete code
Code:
package {
import flash.display.*;
import flash.system.Capabilities;
import flash.events.Event;
import flash.net.*;
import flash.media.Video;
import flash.events.MouseEvent;
import caurina.transitions.*;
public class main extends MovieClip {
var trailer:Video = new Video(480,270);
public function main():void {
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
stage.addEventListener(Event.RESIZE, resizeHandler);
addEventListener(Event.ENTER_FRAME, enterframe)
resizeHandler(null);
rect.alpha = .8;
var conn:NetConnection = new NetConnection();
conn.connect(null);
var stream:NetStream = new NetStream(conn);
//float.addChild(trailer);
trailer.attachNetStream(stream);
//stream.play("trailer.flv");
var metaListener:Object = new Object();
metaListener.onMetaData = theMeta;
stream.client = metaListener;
trailer.x = 20;
trailer.y = 20;
bar_mc.alpha = 0;
float.addEventListener(MouseEvent.MOUSE_OVER, getControl);
float.addEventListener(MouseEvent.MOUSE_OUT, removeControl);
bar_mc.play_mc.buttonMode = true;
bar_mc.stop_mc.buttonMode = true;
}
private function resizeHandler (e:Event):void {
var sw:Number = stage.stageWidth;
var sh:Number = stage.stageHeight;
rect.width = sw;
rect.height = sh;
}
private function enterframe(e:Event):void {
float.x = stage.stageWidth/2 - float.width/2;
float.y = stage.stageHeight/2 - float.height/2;
bar_mc.x = float.x + 20;
bar_mc.y = float.y + trailer.height - 10;
}
private function theMeta(data:Object):void {
var totalLength = data.duration;
}
private function getControl(e:MouseEvent):void {
if(mouseX > float.x + 20 && mouseX < float.x + 500 && mouseY > float.y + 20 && mouseY < float.y + 290) {
Tweener.addTween(bar_mc, {alpha:1, time:1});
//trace("in")
}
}
private function removeControl(e:MouseEvent):void {
Tweener.addTween(bar_mc, {alpha:0, time:1});
//trace("out")
}
}
}
Thanks in advance!
Christine
-
a.k.a gltovar
having booth event listeners active at once can lead to issues where they get called back to back. try this code out and see if it helps any. (since it might not ^_~ )
Code:
package {
import flash.display.*;
import flash.system.Capabilities;
import flash.events.Event;
import flash.net.*;
import flash.media.Video;
import flash.events.MouseEvent;
import caurina.transitions.*;
public class main extends MovieClip {
var trailer:Video = new Video(480,270);
public function main():void {
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
stage.addEventListener(Event.RESIZE, resizeHandler);
addEventListener(Event.ENTER_FRAME, enterframe)
resizeHandler(null);
rect.alpha = .8;
var conn:NetConnection = new NetConnection();
conn.connect(null);
var stream:NetStream = new NetStream(conn);
//float.addChild(trailer);
trailer.attachNetStream(stream);
//stream.play("trailer.flv");
var metaListener:Object = new Object();
metaListener.onMetaData = theMeta;
stream.client = metaListener;
trailer.x = 20;
trailer.y = 20;
bar_mc.alpha = 0;
float.addEventListener(MouseEvent.MOUSE_OVER, getControl);
//float.addEventListener(MouseEvent.MOUSE_OUT, removeControl);
bar_mc.play_mc.buttonMode = true;
bar_mc.stop_mc.buttonMode = true;
}
private function resizeHandler (e:Event):void {
var sw:Number = stage.stageWidth;
var sh:Number = stage.stageHeight;
rect.width = sw;
rect.height = sh;
}
private function enterframe(e:Event):void {
float.x = stage.stageWidth/2 - float.width/2;
float.y = stage.stageHeight/2 - float.height/2;
bar_mc.x = float.x + 20;
bar_mc.y = float.y + trailer.height - 10;
}
private function theMeta(data:Object):void {
var totalLength = data.duration;
}
private function getControl(e:MouseEvent):void {
float.removeEventListener(MouseEvent.MOUSE_OVER, getControl);
float.addEventListener(MouseEvent.MOUSE_OUT, removeControl);
if(mouseX > float.x + 20 && mouseX < float.x + 500 && mouseY > float.y + 20 && mouseY < float.y + 290) {
Tweener.addTween(bar_mc, {alpha:1, time:1});
//trace("in")
}
}
private function removeControl(e:MouseEvent):void {
float.removeEventListener(MouseEvent.MOUSE_OUT, removeControl);
float.addEventListener(MouseEvent.MOUSE_OVER, getControl);
Tweener.addTween(bar_mc, {alpha:0, time:1});
//trace("out")
}
}
}
-
Hi,
I may have another angle on this too. Mouse over and mouse out events are a little bit tricky as you will get a mouse out as soon as the mouse moves over a child object so it looks like the mouse over doesn't work properly. Try to use the ROLL_OVER and ROLL_OUT events instead. If you want to keep the MOUSE_OVER event, then try to set the mouseChildren property to false.
Whyves
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
|