flash click and drag sametime doesnt work - actionscript-3

I have a seek bar for video player
just like youtube, user can drag the cursor in seekbar or click anywhere on seekbar to jump to the time
I use mouse.down and mouse_up event for dragging the cursor:
mc.cursor.addEventListener(mouse_down)=>mc.cursor.startdrag();
mc.cursor.addEventListener(mouse_up)=>mc.cursor.stopdrag();
and for clicking:
mc.addEventLister(mouseevent.click)=>mouseEvent.target.mouseX
here is my problem:
if I do only clicking or dragging nothing wrong
but when I do both clicking works but dragging isnt
when mc.cursor.mouseEvent up is called mc.mouseEvent click is also called and since mc.cursor is clicked click event got the coordinates wrong
I remove the click event in mouseEvent up function in 1st line and in the last line I add again but it does the samething again
how can I use them in the sametime
thanks

I guess the best way to go here would be to attach the click handler to the bar (you have an horizontal bar BELOW the cursor, right?).
So, it would go something like this:
var timelineBar:Sprite = mc.bar; // This is the clickable horizontal bar below the cursor
var cursor:Sprite = mc.cursor; // This is your current cursor
// Add dragging events to the cursor sprite
cursor.addEventListener( MouseEvent.MOUSE_DOWN); // start drag
cursor.addEventListener(MouseEvent.MOUSE_UP); // stop drag
// Add the CLICK event to the timeline-bar Sprite INSTEAD of to the cursor's parent
timelineBar.addEventLister( MouseEvent.CLICK );

Related

How to implement click event and drag event in HTML Canvas

I have created a business tool using html canvas.
It contains numerous elements that can be dragged and dropped. I have coded this functionality myself basically saying (pseudocode):
if(mouseIsDown && mouseInBoundsOfIcon){
icon.grabbed = true;
}
if(icon.grabbed){
icon.x = mouseX;
icon.y = mouseY;
}
Now I would like some of these icons to implement an onClick event as well, making them both clickable and 'drag & droppable'.
The problem is the mousedown event gets fired as soon as I click down on a mouse button (obviously). I'm thinking I could use a short timer, when mousedown fires and mouseInBoundsOfIcon==true, I can start it, when it hits 0.5 seconds for example icon.grabbed = true, else if the button is released it counts as a click?
I'm not sure how to go about this. Any suggestions?
There are at least 2 common ways of differentiating between clicks and drag-starts.
Both these methods involve taking a measurement during mousedown and comparing it to another measurement taken in either mouseup or mousemove.
Measure the distance the mouse moves. For example, if it moves more than 5 pixels before mouseup it's a drag.
Measure the time between mousedown and mouseup. For example, if mouseup occurs within 200ms of mousedown, then it's a click.
Helpful Hint: Let mousedown default to drag-start rather than click. Start dragging on mousedown. If you later determine the user intended a click then put the icon back at its starting position so they don't have slightly nudged icons when intending clicks.

Live smooth Drag of component in flex Mobile

I Try to drag component using DragManager but it will not drag my component live. it will drag like given image below.
But i don't want to drag compoenent like this.
So, I will try to drag component by changing it's X Position. I will change it's X Position when i drag Component using mouse, for that i use MouseDown, MouseMove and MouseUp event. OnMouseUp I put that component at that place when MouseUp event call.
But, It didn't work smooth. I use event.updateAfterEvent(); for smooth move but still didn't get good output. The Component will jurk some times when i move and some times move go outside screen and component stick to mouse.
Is Live Drag Possible in flex? I Like to use drag component functionality in mobile application.
Thanks
Simply use "startDrag" and "stopDrag" function for your object.
On the "On Mouse Down" Event:
yourObject.startDrag();
And "On Mouse Up" Event:
yourObject.stopDrag();
For keeping the object inside specific bounds you can pass a Rectangle Object as parameter to the startDrag call:
yourObject.startDrag(false, new Rectangle(0, 0, stage.stageWidth, stage.stageHeight));
Above call will keep your object on the stage.

Custom cursor issue with nested movieclips

I made a custom cursor and add mouse event listeners to it, so it can animate according to mouse clicks (Up/Down) and also hide after 4 seconds if the user didn't click or move the mouse.
The custom cursor was working OK, but after loading external SWF to the container I found that custom cursor event listeners is not working with all movie clips on the child SWF (external loaded SWF). So It is not animating with mouse events and not resetting hide timer, which causing mouse to hide even if the user are moving or clicking it.
The hierarchy of movie clips as follows:
-- Scene 1
-- container's Buttons and controls MCs
-- myLoader content //added under the controls MC
-- content_mc //contains the child movie clips
-- child's movie clips //contains animations and simple buttons
I tried to set
myLoader.mouseChildren = false;
This solves the custom cursor issue but also blocked all mouse events on the child SWF and make all child's buttons unclickable.
So, I wonder if you can help me finding a way to make the custom cursor events working with the nested movie clips without blocking the nested movie clips mouse events.
You should find that if you place the listener at the top level class and set capture to true you should get all the events you need

As3: Button only working in certain locations?

I really don't know how to explain this problem. I'm really stumped as to what is causing it.
Here is the code:
var abutton:AButton = new AButton; //Where AButton is a button defined in my library
addChildAt(abutton, numChildren);
abutton.addEventListener(MouseEvent.CLICK, attack);
It doesn't want to work when certain movie clips are underneath it, but I don't want to make it more complicated by switching to another screen. Is it possible to make the button work with movieclips underneath?
What do you mean by "certain movieclips"? What do you mean by not working? The CLICK event isn't firing? Normally if a click isn't working on a button, it means that something else it trapping the mouse click above your button. This can be another Sprite, MovieClip or TextField.
Add a click listener to the stage, and have it print out target and currentTarget. Then, when you button doesn't work, the stage listener will still fire and you'll be able to see the object that's blocking your button.

AS3 - Detect if mouse is down, even if overlaps

I would like to know if the mouse button is down, even if another object is being clicked. How do I do that? Simply adding event listeners doesn't work as it does not trigger if something else is on top of the object.
Thanks
Add both a Click & MouseDown event listeners to the stage.
If an object is clicked , the event will bubble up to the stage so you should be able to register it and react accordingly.
You can also check the event.currentTarget property to find out where the event originated from , this should tell you if it was the stage or an object being clicked as well as where the mouse down event came from.
Add a mouse down event listener to the stage (or other parent of all objects in question)