Live smooth Drag of component in flex Mobile - actionscript-3

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.

Related

Move mouse out of bounds Actionscript 3

My problem is really simple
I´ve an artifact with a mouse inside. When you use it it simulates moving the mouse cursor indefinitely to the right.
Of course when i run my project at some point the mouse will reach the right side of the movieclip and the Mouse_Move event wont work anymore
I need a way make my actionscript to recongnise mouse movement even if im out of bounds
(It´s a mobile aplication so using full screen wont work)
In other words i need a Mouse-Motion Listener!
Though it is not possible to track mouse movements outside of flash with only ActionScript, you could capture the mouse position with javascript in the browser and pass it to your SWF.
See this blog as an example. http://www.nelsond8.com/?p=515
You cannot track the mouse position or actions when it moves outside of the stage.
You can however track when the mouse actually leaves the stage using Event.MOUSE_LEAVE:
function mouseLeave(e:Event):void
{
trace("Mouse left the stage.");
}
stage.addEventListener(Event.MOUSE_LEAVE, mouseLeave);
From here you can decide what the most appropriate course of action will be for your application - adding some 'pause' functionality is pretty common.
Tip: MouseEvent.MOUSE_MOVE is what you should use to detect when the mouse re-enters the stage.

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)

drag a scaled html canvas

I'm working on a canvas application, and implemented a zoom-in and out function using scale() and translate().
After zooming in, my canvas is actually bigger than it's seen on the screen, so I want to implement a drag and drop function for the whole canvas.
How can I do it?
Drag and drop what exactly?
You mean drag the whole canvas scene around? That's known as mouse-panning.
On the mousedown event, begin panning and save the mouse position
On the mousemove event, translate the context (ctx.translate(x,y)) by the difference between the current mouse position and the original position, then redraw the scene.
On the mouseup event, stop panning.
(There are harder ways, for instance you could implement scrollbars inside or outside the canvas)

'glasspane' for as3 to intercept events to everything on stage?

Is there something like the java 'glasspane' in as3?
The glass pane is useful when you want to be able to catch events or paint over an area that already contains one or more components. For example, you can deactivate mouse events for a multi-component region by having the glass pane intercept the events. Or you can display an image over multiple components using the glass pane. http://java.sun.com/docs/books/tutorial/uiswing/components/rootpane.html
Why do this? While some animations are underway in flash, I want to prevent any mouseevents from firing. I could remove all listeners systematically, then re-add them after the animation, but if there is something like a glasspane, it might be an easier way to achieve the same effect.
My current thinking is to:
add a sprite to the stage
stretch to width and height of the stage,
give the sprite the highest z-order,
grab all events on this sprite, and stop their propagation?
if you set
enabled=false;
mouseChildren=false;
on to the top most DisplayObject it should disable all mouse events for your app. I've used it and it works a treat.
For a more specific approach, e.g. only block clicks but let mouse down etc. through I use this approach. It uses a 'clickBlocker' stage event handler during capture phase, stopping propagation to any other object.
public function blockClicks():void{
if(!stage) return;
stage.addEventListener(MouseEvent.CLICK, clickBlocker, true); //useCapture!
}
private function clickBlocker(event:MouseEvent):void{
trace("Me (the stage) gets the "+event.type+" first, and I block it #"+event.stageX+"/"+event.stageY);
event.stopImmediatePropagation();
}