Play movie clip on click at mouse coordinates - actionscript-3

I'm trying to play a movie clip of a circle expanding and fading away every time a user clicks. I make the movie clip, then I convert it to a movie clip again and create a motion tween making the circle get larger and fade away. But, when I call on the clip it just keeps playing over and over in the last place you click. If I set a stop at the last frame of the tween the next time you click it, it won't play.
fs15secTapBtn.addEventListener(MouseEvent.MOUSE_DOWN, fs15secdownHandler);
function fs15secdownHandler(event:MouseEvent):void
{
circletouch.x = mouseX;
circletouch.y = mouseY;
}
Thanks!

You need to start/stop the movieclip every time you click. Right now, when you click the first time the clip would be put on stage and playing. Then when you click again, all you're doing is modifying the x and y positions of the clip, which moves the clip to the mouse coords...but the clip itself would still be continuing to be in whatever state it is in during the click (playing on it's own at whatever frame).
Within your click handler add in a circletouch.gotoAndPlay(1); to restart the playing at frame 1. Also, you may want to re-add that stop(); back in so that it'll only play once.

Related

using mouse_over when dragging a movie clip onto another movie clip in AS3

I'm' trying to do the following: I want to drag a mc (mc1) over another mc (mc2), and trigger a timeline navigation when it's over--not when it's releasaed (mouse is up). Apparently flash doesn't recognize the mouse is over mc2 because it's reading it only as being over mc1. This is probably very simple but I'm lost as to how to do it.
Feeble attempt at code:
mc2.addEventListener(MouseEvent.MOUSE_OVER, mcOver1);
function mcOver1(Event:MouseEvent):void {
mc2.gotoAndStop(2);
}
When I'm not dragging anything it works fine, because flash can detect where the mouse is. But I'm unsure how to get flash to detect the mouse's location when it's dragging a movie clip. I tried basing the code on the location of the movie clip I was dragging (mc1) but that didn't work, either.
Any help is appreciated.
EDIT: ok, I just thought of a really cheap workaround, but I'd still like to know how to do it without needing a workaround. Basically, since my mc (mc1) is so small, I made it so that the mc's x-position is 5 pixels more than the cursor's x-position, so mc2 recognizes the mouse now:
this.addEventListener(MouseEvent.MOUSE_DOWN, startDragging1, true);
this.addEventListener(MouseEvent.MOUSE_UP, stopDragging1, true);
function startDragging1(e:MouseEvent) {
mc1.startDrag();
mc1.x = mouseX + 5;
}

Restart a Moviclip from the stage after stoping it

On my main stage I have a few Movieclips, which all start at a different frame position, and also end at a different frame position. So I put a keyframe to the Movieclips, after the animation is finished, and put a stop() on it. After all animations are finished, the main stage also gets a stop() and a replay button appears. Now if I click on the replay button, every movieclip should start again - of course. I have tried gotoAndPlay(1) but the moviclips are not starting with that, only the mainstage (of course, i know that moviclips have their own timeline.. ) So how can I restart every animation with just the one click on the replay button?
In Flash, movieclips are running seperate from the Main Stage.
In order to run all the movieclips, you should restart all the movieclips:
Let's say the names of the movieclips are MovieClip1, MovieClip2 and MovieClip3.
on(release){
gotoAndPlay(1);
MovieClip1.gotoAndPlay(1);
MovieClip2.gotoAndPlay(1);
MovieClip3.gotoAndPlay(1);
}
Hope this will work.

Touch movement will not animate

Ok, so I'm in the process of developing a game in Adobe Flash (air) it will be a mobile game.I asked this question a while ago, but animation doesn't work so know I'm back.Anyway, the problem I was having was that there was no continuous movement when I held down a button, so I had to constantly keep pressing the button to move.the person told me to use ticks, so it's how I built the movement engine, all around ticks.When I go to add my animation, it goes once and just stops (the animation) here is my code:
myButton.addEventListener(MouseEvent.MOUSE_DOWN,mouseDown);
function mouseDown(e:Event):void {
stage.addEventListener(MouseEvent.MOUSE_UP,mouseUp); //listen for mouse up on the stage, in case the finger/mouse moved off of the button accidentally when they release.
addEventListener(Event.ENTER_FRAME,tick); //while the mouse is down, run the tick function once every frame as per the project frame, this is where I add the players animation.
}
function mouseUp(e:Event):void {
removeEventListener(Event.ENTER_FRAME,tick); //stop running the tick function every frame now that the mouse is up
stage.removeEventListener(MouseEvent.MOUSE_UP,mouseUp); //remove the listener for mouse up
}
function tick(e:Event):void {
//do your movement
}
What I'm saying is, is there anyway to get around the problem? How can I animate with the tick!
Like others, I find the code perfectly fine. Since, I don't have access to entire code and timeline, I have the below guess about the problem:
Since, you want to start animation only on mouse down, then you must be having a stop() action in the first frame of your animation. (Please correct me if this isn't the case). The last frame of your animation must be having gotoAndPlay(x) action again for looping.
Based on above assumption, when your animation loops, it again reaches a frame which has stop() action already defined.

how do I stop a scene and play the next scene in adobe flash cs6 actionscript 3.0

I'm trying to make a loop animation scene where its like an eye opening and closing. I have one black rectangle that goes down and meets with another black rectangle going up to create the blink effect. Then in the middle I have a button that the viewer can click to go to the next scene. The problem is that before and after the button is pressed both scenes play simultaneously. How can I play the first loop scene and then stop it to play the next scene when a user presses that button? Thanks.
You need to tell your respective scenes to stop. Otherwise flash player will just move on to the next scene automatically after the last frame of the previous scene (and loop back to the first scene after the last frame of the final scene).
In flash, open your first scene and open the timeline view. scroll to the very end of your timeline, add a new layer, on the very last frame of your timeline on your new layer, create a keyframe (F6 on windows). With that new keyframe selected, open the code editor (F9 on windows) and put in the command stop(); OR if you want the current scene to keep looping (without moving on the next scene) put in the command gotoAndPlay(1);
If you want your other scene to stop as well at the end, repeat the above steps on it's timeline.

AS3 move object back to first frame from current position in tween

I have an object with an instance name of arrow that moves across the page on a motion tweet when a button is pressed. When the button is released I want the arrow to move back to the start of the tween frame by frame.
I have set up an if statement when the button is released and its current frame is more than 1 to go back 1 frame.
So far the arrow is ignoring the if and stopping due to the else statement.
btn.addEventListener(MouseEvent.MOUSE_OUT, out);
function out(e:MouseEvent){
if(arrow.currentFrame > 1){
arrow.gotoAndStop(arrow.currentFrame - 1);
}else{
stop();
}
}
You would probably be better off making another tween on the timeline that goes backwards then just playing that. Another option is to use a third party tweening library like tweenlite since in there you can easily setup animations to run forward or in reverse.
Are you sure arrow is the name of the movie clip that you want to run the frames backwards on, or is that the instance of the element that changes over some other movie-clips timeline?