Touch movement will not animate - actionscript-3

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.

Related

Actionscript-3 looping issue--Adobe Animate CC

My employer decided they wanted me to start doing animation with Adobe's new "Animate CC" application. My issue is that I don't know how to loop my animation outside of the Adobe Animate environment. I am new to Adobe Animate CC and ActionScript, unfortunately, so I will probably need a relatively basic answer to understand why my solution isn't working. From what I can tell, my ActionScript code is being ignored by the IDE completely.
In the IDE and in the browser test command, the animation plays beyond frame 100, to the end, and then flashes a frame of white before repeating. I need it to loop without this white frame interrupting the screen, whether that be through a loop or some other means that I'm just not aware of.
For context: my project has about 100 layers of content and I'm unfamiliar with how this program works. I've thoroughly searched the web for tutorials on how to do what I need to do, but I've come up empty handed.
I have an actions layer among my motion tweens and other layers
https://gyazo.com/6e0b8502d98b6c9903bb96ac3a939bae
I've been trying to use gotoAndPlay(0) at frame 100 to start the animation over from the beginning.
https://gyazo.com/704ee7158bae6dfd149b6283cfa33451
Basically, how do I use Action-Script in Adobe Animate CC in order to infinitely loop my animation until closed?
Thanks everyone.
Your flicker may be a result of having an extra blank keyframe on one of your layers.
Assuming that you don't have any additional scripts to stop your animation (e.g. stop()), the Timeline should loop automatically whether your animation is inside a MovieClip or on the main Timeline. You shouldn't have to put any script on your timeline or in a separate AS file to make an animation loop. I would suggest this method.
Additionally, although you have the code specifying that you want it to go the first frame, it will ignore your call because the timeline is still playing and therefore the priority. One way you can combat this is by adding a stop(); function and a delay timer that contains your gotoAndPlay(0) function. This will take focus away from playing the Timeline and will allow you to execute your script. I wouldn't suggest this method because it seems a bit redundant.
However, if you're curious one way that you could approach this is shown below, simply add this script to the frame you want the animation to restart at.
//Stop the Timeline
stop();
//Create a delay timer for 5 miliseconds that is executed once
var timer:Timer = new Timer(5,1);
//Add an event listener that calls once the timer is complete
timer.addEventListener(TimerEvent.TIMER_COMPLETE, timerHandler);
//Start the timer
timer.start();
//Timer handler that is called once the delay timer is complete
function timerHandler(event:TimerEvent){
//Go to and play the first frame
gotoAndPlay(0);
}

How to make a movieclip play on a specific frame in AS3?

I'm incredibly rusty at Flash having not touched it in probably 10 years and can't seem to figure this out, or find it online:
I have a MovieClip with two layers, each having a Shape Tween. Basically its a Door that opens and closes.
I dropped it onto the main timeline but now I need it to start and stop. This is where I'm now struggling since the last time I used Flash actions could go on specific keyframes.
I made a new layer called actions just to keep things organized and currently have:
barrier1.stop();
I just want something that lets me state a frame, say 57 to have barrier1 start playing on. Tried using play(); and Event.ENTER_FRAME with no luck. How would I set this up?
Well it is easy with the instance name of your movieClip
barrier1.stop(); // Stops the movieClip
barrier1.play(); // Resumes
barrier1.gotoAndStop(12) // Goes to 12nd frame and stop
barrier1.gotoAndPlay(12) // Goes to 12nd frame and play
barrier1.currentFrame // returns barrier currentframe
For capturing frame from scene level:
this.addEventListener(Event.ENTER_FRAME,onLoop);
function onLoop(event:Event){
if(barrier1.currentFrame == 57){
trace("BARRIER is in 57. frame");
}
}
Inside on the animation clip on the first frame
var root:MovieClip = this.parent as MovieClip
root.makeStartSceneAnimation()
**in timeline scene level [root]**
function makeStartSceneAnimation(){
/// barrier started to play
}
If you are using timeline, you can add Key frame on the desired frame, and then add stop(); as Action in the action layer. But bear in mind that if you do this in the main timeline - it will stop everything. If you want to stop that MovieClip, then you have to do this inside MoviceClip's timeline.

Action Script 3. How to play animation once?

I'm creating flash game and I have animations for character movements. How correctly setup animations to play It only 1 time after action? For example: If I click "Space" button - character jumping and "Jumping" animation starts playing forever, if character stay on the ground jumping animation continue playing. How to stop It when character stay on the ground? Or if I use attack animation It loop forever too.
In normal state character should use Hero.gotoAndStop("staying");
Here is my jumping code:
if (Hero.y_speed > 0 && Hero.hitTestObject(ground))
{
Hero.y_speed = 0;
Hero.x_speed = 0;
if (space)
{
if (true)
{
Hero.gotoAndStop("jumping");//here starts jumping animation loop non stop
stop(); //this not working
Hero.y_speed = -20;
}
else
{
}
}
}
You need to put a stop(); on the last frame of the MovieClip, so that the MovieClip stops playing once the playhead reaches there.
Given that there is an MovieClip on the frame, you need to tell that MovieClip containing the jump animation to stop.
You would need to have a stop on the last frame of that animation. You'd put that stop on that animation's timeline.
edited to answer comment :
You could probably use a line like this to switch to the "staying" animation when complete.
parent.gotoAndStop("staying");
In this case you wouldn't need to have a stop as the playhead would be moving off of that animation in going to the staying animation.
I think this particular post : flash event listener for movieclip end?
gives a particularly good example of extending a MovieClip giving it a much welcomed ANIMATION_COMPLETE event. So if you are looking to handle things via code exclusively, that would be a good direction to choose.

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 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?