Changing frame on character stops control over movement etc - actionscript-3

I have a character that turns and looks at the mouse and moves with WASD. This is all done within a class for the character. When I click, the character changes his frame to a different animation, and completely stops following the mouse and moving with the buttons. There is no reference to his frame in the code anywhere so I cant work out why he just stops like this. It seems like for some reason the class just stops working the moment the frame changes.
I am using gotoAndPlay() to trigger the animation.

Related

How to re-spawn particles randomly in Away3D

I'm attempting to create a particle effect using Sparticle and Away3d. The effect is a little burst of bubbles that float up to the top of the screen when items are clicked.
I have the effect loaded and working and it looks good, but unfortunately the effect always spawns the bubbles with the same random velocities each time. The velocities seem to be set when the animation first runs and then never changes.
How do I restart the animation with new velocities each time?
I've tried calling stop and start on the animator, and resetTime but I suspect it's just moving the time back to 0 and that's why the animation isn't actually restarting properly.
i.e.
particleGroup.animator.stop();
particleGroup.animator.start();
The reset method doesn't do anything because it expects an animation name, and the animation name set in the sparticle editor doesn't seem to be available.

Collision test to play a movie clip

I have a character that can move left and right and can jump. I have all this coded. I included two invisible buttons that I want, when the character runs into them, to play a movie clip. I tried to set up collision detector, but failed. I have been looking through tons of code, and can not find a solution that will help. What do I need to do in order for the mc to play when the character runs over the invisible button?
if (invisiblebutton.hitTestObject(character)) {
other_movieclip.play();
}
All of this should be running in your main game loop (ENTER_FRAME event handler)

How can I send control of the playhead back to a parent timeline from a movieclip using createJS?

I'm making a multi-part introductory animation for a game. It works when I preview in Flash, but not when I export using the CreateJS toolkit to get HTML5 output.
On my scene's timeline, I have this.stop(); on the first frame, as well as a movie clip that contains several seconds of animation (and which may have to change in length as we develop).
My second frame is labeled "sc2" and I would like the animation to pick up there when the first movieclip is finished. To accomplish this, I went into the first movie clip and put this on the last frame:
_parent.gotoAndPlay("sc2");
This works fine in Flash, but perhaps I can't use the _parent object in JS? Is there an alternative way to access the flow of control or another way to accomplish this? My goal is to avoid doing animation on the main timeline and to control the flow by scripting there so that if the length of the individual sections of animation changes, I don't have to change the start and end frames of the various sections in several places.

AS3 : MovieClip script stop when done playing

I am a beginner with AS3 and I'm having a problem with MovieClip class.
I have a character that move through a simple script that handles collision, sound etc. Everything was working seemlessly so far but when I started adding animation, the character would stop at the end of the animation cycle.
Does someone comfortable with AS3 knows what's wrong here ?
Thanks in advance =)
Inside the Flash IDE, try clicking the instance of your character that's not looping the way you want it to (and this should be from outside the animation itself; from the container of your character), then look inside the Properties tab/window. Near the bottom, there will be a LOOPING header, and inside there you can modify the behaviour.
In case you have any problems with this, or otherwise want to have more control over the animation playhead, you can include script in the form of e.g. gotoAndPlay(1); which you might add at the last frame of your animation cycle to tell Flash to play from the start again. The frame number parameter doesn't have to be 1 of course. You could for example set up a series of animation sequences on a single timeline, and use gotoAndPlay() to have them loop internally, until an event occurs and you direct the playhead to another animation loop inside the same MovieClip.
Usually when play(); is called, an animation is being repeated all the time.
You should seek in your code for stop(); that essentially makes an animation stop, and remove it.

AS3 Button stops working after random amount of click

I have a movieclip being used as a button. After a random amount of clicks the button stops working. In other words, the mouse will become a hand when hovering over the button but no clicks are registering to fire the function. I've even clicked it 40 times and it will work but then suddenly, bang!, it stops working. Heres the function that adds the btn, listener, animates it into the screen and also adds text.
function makeButton():void{
addChild(myBtn);
myBtn.mouseChildren=false;
myBtn.buttonMode=true;
myBtn.x=(stage.stageWidth/2)-(myBtn.width/2);
myBtn.y=-300;
myBtn.addEventListener(MouseEvent.MOUSE_DOWN, btnClicked, false, 0, true);
myBtn.btn_text.text="The string goes here";
TweenLite.to(myBtn, 0.5,{x:(stage.stageWidth/2)-(myBtn.width/2),y:(stage.stageHeight/2)-(myBtn.height/2)});
}
And then here's the function that animates the button outside the screen:
function btnClicked(e:MouseEvent):void{
myBtn.removeEventListener(MouseEvent.MOUSE_DOWN, btnClicked);
TweenLite.to(myBtn, 0.5,{x:(stage.stageWidth/2)-(myBtn.width/2),y:-300});
}
Strange thing is, I added a trace("listener added") into the 'makeButton()' AT THE VERY END, AFTER THE ADD EVENT. And it traces everytime, even on the times the button stops working. SO i can only assume there are no errors with listener being added. But then why is it not working?
I'm stumped. I thought it could be an event propagation problem. In other words the listener was being added to the target (myBtn) but somehow it was capturing or bubbling wrong but..... then why does it work at all? And for so many clicks?
The truth is out there. Or maybe in here, your insights will be much appreciated.
Where does myBtn get created? I can see right at the beginning of makeButton() that you are adding it the display list but can't see where it actually gets created? Is it already on the stage?
Adding a trace statement in the makeButton function will only tell you that a button is created, it won't say much about the functionality of your button. If you want to check if your button reacts to a click , you need to add your trace statement in the click listener.
According to your description , it sounds like you keep adding the same button to the stage rather than actually clicking the same button.
How often do you call the makeButton function before it stops working? This function looks like it should only be called once. As for the btnClicked function , why do you remove the listener, if you wish to click the button again?
Practically it looks like you should only have your Tweening functionality in your functions, I mean , once the button is created , you need one function to tween the button, then instead of adding the button again, simply call a function to tween the button back in place.
All the rest shouldn't be repeated.
I've fixed the code and the problem hasn't occurred again. The problem must have been that I was running the addChild every time the function called and that was doing something odd to the MC in the display list. I haven't pursued the error by clicking the buttons many times in a row for a minute or two, as I did to make the error happen originally. I think i'll let sleeping dogs lie.
With that said, my code is a lot cleaner with the addChild and other crap running in the initialization function and just sitting above the stage - and then being tweened into position in the 'makeButton' and 'btnClicked' functions (which are now fittingly named 'tweenBtnIn' and 'tweenBtnOut').
Thanks again