Fade out when running removeChild() in ActionScript - actionscript-3

I am creating a very rudimentary UI in Flex and Open Exhibits SDK, which I'm just starting to learn.
The UI has buttons and text. When I click a certain button, it removes everything from the screen using removeChild() (by detecting Mouse Up), and puts in new buttons and text.
This is not very pretty. I would like there to be a fade out animation when removeChild() is invoked. How do I do this?
If there is an alternative to removeChild() for this case, what would it be?

1) In your current Mouse Up event handler initiate some tweening effects (in your case you want to decrease alpha) instead of removing the children.
2) Add new event handler to process tweening completion. Remove your children there and add new (possibly with tweening as well).

Maybe if you can listen to removed or removedFromStage event, then prevent event to happen, start effect on event.target which is to be removed, and when effect ends then remove child.

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 Can StageWebView be tween or animated?

Just wondering can you apply some animation on the StageWebView, for example slide in and slide out, i have apply with TweenLite.to() but i don't it accept StageWebView? Is it possible or i just have to be appear visible show and hide?
No it's not possible. You can create the StageWebView, capture a snapshot of the contents and tween this snapshot into place, then once the tween has completed, replace the snapshot with the actual StageWebView.
The function required to do this is
drawViewPortToBitmapData(bitmap:BitmapData):void

Tweening in as3 stopping the next tween to happen until the last one is finished

How to stop the next tween action to start until the previous tween completes playing in as3.0?
and also i want to stop the tween to happen on the same object twice.
Basically i have a container (movie-clip) in which there are n number of movie-clips (arranged as bricks). When i click on the container the target (brick) will disappear (made scaleX and alpha to 'o'). also i am tracking how many bricks are closed.
But the problem is if i do a fast double click the tween seems to happen twice. and the count also seems to increase for the same brick. how to solve this problem.
Tween after Tween
Use an event handler to wait for the first tween to complete, Something like
myTween.addEventListener(TweenEvent.MOTION_FINISH, onFinish);
function onFinish(e:TweenEvent):void {
... // Call the next tween here
}
Double click problem,
Remove the event listener for the button click as soon as it is clicked, Something like:
my_btn.addEventListener(MouseEvent.CLICK, onClick);
function onClick(e:MouseEvent){
my_btn.removeEventListener(MouseEvent.CLICK, onClick);
myTween.start();
}
You could use Tweener and use
isTweening() or autoOverwrite = false to get around this.
I haven't used those properties/functions in a while but I'm sure something in Tweener can do this easily.
Any reason you are using Tweener. Greensock's Tweenmax/lite package is seemingly the industry standard these days.
The problem you seem to be having is that you are initiating the tween multiple times. If all the blocks need to shrink simultaneously, i would probably use a for loop and run a tween on each of them.
The thing you have to make sure though is once its clicked to remove the click event handler until its complete so it won't be clicked again.
I also would recommend using TweenMax/Lite because it has something called TimelineMax/Lite where you can compound a bunch of tween be it simultaneous or staggered and listen for one COMPLETE event on that Timeline object. When that event fires you can reactivate the clicks or do whatever it is you need to do after the animation is complete.
TimelineMax has some nice features as well like reverse and timeScale.
would you be able to paste some code? that would also help us help you.

Listen to click event on overlapped sprites

I have two sprites in my movieclip, one under the other, and i want both to listen to mouse clicks event.
I found that only the top level sprite receives the event when i click on it.
I need to dispatch the events on both, so I can't use mouseenabled=false.
Is there a simple workaround for this?
Another solution is, that you listen to the click-event on the upper sprite, and fire it again with
dispatchEvent(new MousEvent(event));
Have a look at the "bubble" property of the event.
You can use the 'getObjectsUnderPoint' method native to the DisplayObjectContainer
You can see how it works here:
http://snipplr.com/view/34945/as3-trace-movieclips-under-mouse/
and the AS3 reference here:
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/DisplayObjectContainer.html
You would listen on the stage for any click event and if one occurs, check to see if the element you require is under that click position.

'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();
}