replay btn in flash cs6 using actionscript 3 is not behaving correctly - actionscript-3

I have a flash animation that using action script at the end to stop the animation and has a button for the user to click and replay at the animation. When they click and replay the animation the last scenes that were on the screen don't disappear as the animation restarts. My button has an instance name of replay_btn. Any suggestions?
my action script code is
stop();
import flash.events.MouseEvent; function onClick(event:MouseEvent):void { gotoAndPlay(1); } replay_btn.addEventListener(MouseEvent.CLICK, onClick);
This has been answered now. It seem like there was a bug in flash causes the last scenes to hang while replay the start of the animation. The workaround was to make the replay button go forward one frame to a blank white frame and then direct it back to the start.

Assumed the button is inside the movieclip you want to startover.
stop();
import flash.events.MouseEvent;
function onClick(event:MouseEvent):void {
replay_btn.removeEventListener(MouseEvent.CLICK, onClick);
MovieClip(parent).gotoAndPlay(1);
}
replay_btn.addEventListener(MouseEvent.CLICK, onClick);

Related

My AS3 code will not run my animation properly

I want to be able to press any key on my keyboard so as to appear to be typing my specific
text. No matter what key is pressed, the same scripted text appears, letter by letter(one per keystroke)/frame by frame. Can anyone help me here? As it stands, my animation just continues to loop unless I hit enter (then it stops until pressed again.)
stop();
var keyList:Object = new Object();
keyList.onKeyUp = function () {
nextFrame();
}
Key.addListener(keyList);
stop();
Using Flash cc-thanks
Your code appears to be AS2 rather than AS3?
If your looking for AS3 functionality, you'll want to do something like listen to the stage for keyboard events, and then have an event handler that progresses the frame.
stage.addEventListener(KeyboardEvent.KEY_DOWN,_handleKeyboardPress);
function _handleKeyboardPress(e:KeyboardEvent)
{
nextFrame();
}
Your code looks as though it would work if you are publishing to AS2 though?

How do I stop a timed event from happening?

I am making a game where a user clicks on insects and tries to get a good high score. When the user clicks on one insect, the insect plays an animation and stays in its spot for 2 seconds in this code:
import flash.events.MouseEvent;
import flash.display.MovieClip;
import fl.motion.Animator;
import flash.events.*;
play();
var mysound:squish = new squish();
this.addEventListener(MouseEvent.CLICK, kill);
this.dead = false;
function kill(e:MouseEvent):void
{
this.dead=true;
mouseChildren=false
mysound.play();
gotoAndPlay(21);
this.removeEventListener(MouseEvent.CLICK, kill);
flash.utils.setTimeout(removeSelf,2000);
}
function removeSelf():void
{
this.parent.removeChild(this);
}
When the user pauses the game, the enemies are stopped and they turn invisible. The only problem is that when the user clicks on the insects, and hits the pause button, the insects stay there for 2 seconds. How do I remove the timer when the person pauses the game so that no insects are on the screen?
A few tips:
Never use timeouts, they will produce poor, unsustainable, hard to debug code. Use Timer instead. Timer provides nice little features like: repeat times, pausing, resuming and resetting the timer. So you could set the timers timeout to 2000ms, repeat once and set an event listener TimerEvent.TIMER_COMPLETE to remove the insect etc. You can pause the timer when you pause the game and resume when needed.
If you do however use timeouts, assign a uint to it and use a clearTimeout() method to stop it.
construction such as this.parent.removeChild(this); is ugly. Instead, dispatch an event as an alternative and let the parent to manage the dead bugs (remove from arrays, display list etc).
Storing a sound in every bugs instance will take way more memory than needed. Make a static sound library class and call the play() method from it.

play/pause button in flash

//how can i return the symbol of pause button in the end of Movie Clip ,it back to a play button ?
import flash.display.MovieClip;
stop();
play1.addEventListener(MouseEvent.CLICK,playbutt);
function playbutt(event:MouseEvent):void{
MovieClip(root).play();
MovieClip(root).am.play();
gotoAndStop(2);
}
Your question isn't very clear but from what I gather is that you need to add a listener to whatever you have playing, and then execute a gotoAndStop(1); How you do this however depends on what you are playing and what would be the most effient way of listening for its completion.
If you are playing music or a video, there is usually a Object.COMPLETE that you can use.

flash as3 fullscreen browser jams up playback

I have an AS3 project which when the user clicks a button the browser is set to fullscreen. This works great, however the playback sticks after the navigation is sent to the next frame. The MC on frame two plays, but then the playback head doesn't move forward to frame 3. Once escape is pressed, the fullscreen is broken and then the movie skips to where it would have been normally if it hadn't have gotten stuck on frame two (as if the project was running in the background). This problem also occurs without the fullscreen AS3, just using the controls for a projector to go to fullscreen, and it also occurs if the .swf file plays back directly in a flashplayer without the browser. I don't understand, without fullscreen, everything plays back perfectly....
Here's the code on frame 1:
fullscreenMe.addEventListener(MouseEvent.CLICK, fullScreenIt);
function fullScreenIt(event:MouseEvent):void {
MovieClip(root).gotoAndPlay('two');
stage.displayState=StageDisplayState.FULL_SCREEN;}
And here's the code on frame 2:
var titlesTimer = new Timer(11000,1);
titlesTimer.addEventListener(TimerEvent.TIMER_COMPLETE, titlesTimerFinished);
titlesTimer.start();
function titlesTimerFinished(e:TimerEvent):void {
//trace("timer is finished");
MovieClip(root).nextFrame();
}
var creditsSound:credits = new credits();
var creditsChannel:SoundChannel = new SoundChannel();
creditsChannel = creditsSound.play();
And here's the code on frame 3:
import fl.transitions.Tween;
import fl.transitions.easing.*;
function alphaTween(mc,b,f,d) {
var Alpha:Tween = new Tween(mc, "alpha", Regular.easeIn, b, f, d, true);
}
alphaTween(moon1,0,1,7);
var moonTimer = new Timer(1000,7);
moonTimer.addEventListener(TimerEvent.TIMER_COMPLETE, moonTimerFinished);
moonTimer.start();
function moonTimerFinished(e:TimerEvent):void {
//trace("timer is finished");
MovieClip(root).nextFrame();
}
Hmm from the information given I am not sure if the Playhead is in play mode or stop mode in a frame.
Before we can solve it
Is there a this.stop(); command added before any code is written in the frame. This ensures the Playhead is not in playing mode and stops in the present frame. If you want it playing, then no issues. But looking at the timers, I assume you must have added the stop() command.
Documentation for MovieClip for nextFrame says it sends the playhead to the next frame and stops it. This happens after all remaining actions in the frame have finished executing. So is this intended?

Checking if Mouse Click was not in a MovieClip

I have number of movieClips on stage, with each having it's own Event Listener. Once Click/Touch the event is called each movie clip does something. For example one movieClip makes about 6 other movie clips visible.
What I want to do is, when the user Touch/Click somewhere else on stage, where there is no movieClip I want to know, so I can perform some actions such as make some movieClips invisible.
P.S the reason why I say Touch/Click is I'm developing this app for Android, however to make testing easier I'm currently testing everything in PC with MouseEvent, rather than TouchEvent. Once I get all the features working, I will switch over to TouchEvent and test it in mobile.
Many Thanks,
Mike
Add event listener to the stage. And in the event handlers of your inner movieclips use event.stopPropagation function to prevent bubble event to the container.
I would just do a check, it's simple and quick and doesn't require adding code to alter propagation.
import flash.events.MouseEvent;
stage.addEventListener(MouseEvent.CLICK, onClick, false, 0, true);
function onClick(e:MouseEvent):void
{
if(e.target == stage)
{
trace("click click");
}
}