Play Again button w/ AS3

how would I code a play again button using AS3 since you
cannot place the code on the button itself anymore. Would the code
still be gotoAndPlay(1);?
would I need to give the button an instance name and what
would I need to change the code to?
thanks in advance!

DPSwebmaster,
> I have given my button an instance name of 'PlayAgain'
and
> placed the AS code on frame 1 of my timeline.
As long as that button (with the instance name PlayAgain)
appears in
frame 1 as well, you should be good.
> PlayAgain.addEventListener(
> MouseEvent.MOUSE_UP,
> function(evt:MouseEvent):void {
> gotoAndPlay(1);
> }
>
There should be a closing parenthesis on that [... this one:
which is basically the other half of the "sandwich" that
begins with
addEventListener( ...]. But other than that, your code looks
fine. Be
advised that you can also use a named function, if you like:
PlayAgain.addEventListener(MouseEvent.MOUSE_UP,
mouseHandler);
function mouseHandler(evt:MouseEvent):void {
gotoAndPlay(1);
Do you see how those are effectively the same thing? The
addEventListener() method accepts two parameters: a) an event
to listen for
and b) a function to perform. In the examples I've shown, one
of them
illustrates an anonymous function; the other illustrates a
named function.
In any event, to make sure your code is responding at all,
it may help
to use a trace() function. This is nothing more than a
mechanism to print
text to the Output panel, but it's great for debugging:
PlayAgain.addEventListener(
MouseEvent.MOUSE_UP,
function(evt:MouseEvent):void {
gotoAndPlay(1);
trace("I've been clicked!");
Try that revision (only one line has changed), and when you
click on the
button, you should see the message "I've been clicked!" in
your Output
panel. If you don't, we'll know that this event listener
isn't getting
assigned properly.
David Stiller
Co-author, ActionScript 3.0 Quick Reference Guide
http://tinyurl.com/2s28a5
"Luck is the residue of good design."

Similar Messages

  • Play/Pause Button in AS3

    I have search the internet, but I cannot find a simple way to
    create a play/pause button in AS3. All the solutions I find are for
    older versions when buttons could have actionscript directly
    applied to them.
    I created a flash animation and exported it as a .swf to work
    with only one layer in a new .fla file. I have three layers
    created, button, video, and actionscript. What I need is a button
    that will look like a pause button when the animation is playing
    and to pause the animation when clicked. It would be nice if it
    could also switch to a play button when paused.

    I made a movieclip (ppBtn) with 2 frames. The first has the
    pause button and the frame label 'pause'. The second frame has the
    play button, 'play'. I placed your script into the action layer.
    When I preview the animation, the buttons just alternate really
    fast and have no fuction.

  • Play again button after video is done playing

    Hi,
    I need help with some flash video stuff please... I am importing video into flash via FLVPlayback Component..
    What I would like to do is have a button after the video is done playing that offers to re-play the video and may be another button with some other action.. I"m sure it's some kind of "if" statement... (to see when the video is done playing) but I'm very new to AS - I would really appreciate any help. Thanks ahead of time!!

    What I"m trying to do is have a movie play (with auto hide controls), and once it's done playing, I wanted to have an option to
    either play it again or do something else, like to to all movies etc. Now my code doesn't give me any errors but it still doesn't doesn't do what I want it to do. Now it plays the movie and afterward the button appears.. but it doesn't restart the movie..
    import fl.video.FLVPlayback;
    import fl.video.VideoEvent;
    import flash.events.MouseEvent;
    bttn.visible = false;
    player.addEventListener(VideoEvent.COMPLETE, addPlayAgain, false, 0, true);
    function addPlayAgain(e:VideoEvent) {
        bttn.visible = true;
        bttn.addEventListener(MouseEvent.CLICK, restart);
        function restart(e:MouseEvent):void {
        gotoAndStop(1);

  • Never play again popping back up

    I've been using itunes radio on my iphone 4 for about 6 months now and some of the songs I told it to "never play again" are starting to play while still having the never play again button highlighted. Why is this happening?

    It is possible that there is a problem with the files [http://kb.mozillazine.org/sessionstore.js sessionstore.js] and sessionstore.bak in the [http://kb.mozillazine.org/Profile_folder_-_Firefox Profile Folder]
    Delete [http://kb.mozillazine.org/sessionstore.js sessionstore.js] and sessionstore.bak in the [http://kb.mozillazine.org/Profile_folder_-_Firefox Profile Folder]
    * Help > Troubleshooting Information > Profile Directory: Open Containing Folder
    If you see files sessionstore-##.js with a number in the left part of the name like sessionstore-1.js then delete those as well.
    Deleting sessionstore.js will cause App Tabs and Tab Groups to get lost, so you will have to create them again (make a note).
    See:
    * http://kb.mozillazine.org/Session_Restore

  • Button rollover state plays again after click

    Hello, I have made a portfolio in Flash 8 using Presentation
    Screens. The intro and all the navigation buttons are on the first
    parent screen. I have a rollover label animation on each button,
    which plays fine on the first rollover, but also plays again after
    a button click takes the user down to another screen. This seems to
    be a glitch in the Screens feature, as my tests show that this is
    not the case within a regular FLA document. Has anyone come across
    this??
    You can see the buttons in action at:
    www.opcarto.com
    Thanks

    I had a similar problem whereby I had built my own "frame" - complete with custom "minimize" and "close" roll-over buttons at the top right corner. The problem was that when you minimized the frame, then re-maximized it, the "minimize" button stayed in its "rolled-over" state, for the same reason yours does - the mouse never officially "leaves" the button.
    My workaround, which may or may not help you, was to call the processMouseEvent() method of the Component class (which is a parent of AbstractButton), whenever the frame is minimized. This seems to do the trick.
    Note that processMouseEvent() is a protected method, so I had to override it and make it public in a subclass, so I could go ahead and call it.
    You could do the same thing, but you would need to decide what event you would use to trigger the call (i.e. my event was minimizing the frame - your event might be mouseOver for your overlapping frame?? Might get a bit messy.... ;-)
    Hope this helps!
    M

  • Controlling sound file with play, stop and mute button in AS3.0?

    the method for stopping/playing sound in 2.0 don't work for 3.0.  i can stop the sound by going to a different page/frame on the site.  but i want the buttons. 
    1. play button?
    2.stop button?
    3.mute button?
    thanks in advance!

    for pause (example 2) :
    for volume -mute (example 1) :
    package
    import flash.display.Sprite;
    import flash.display.StageAlign;
    import flash.display.StageScaleMode;
    import flash.events.*;
    import flash.media.Sound;
    import flash.media.SoundChannel;
    import flash.media.SoundTransform;
    import flash.net.URLRequest;
    import flash.utils.Timer;
    public class SoundTransformExample extends Sprite
      private var url:String = "MySound.mp3";
      private var soundFactory:Sound;
      private var channel:SoundChannel;
      private var positionTimer:Timer;
      public function SoundTransformExample()
       stage.align = StageAlign.TOP_LEFT;
       stage.scaleMode = StageScaleMode.NO_SCALE;
       var request:URLRequest = new URLRequest(url);
       soundFactory = new Sound();
       soundFactory.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
       soundFactory.load(request);
       channel = soundFactory.play();
       stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
      private function ioErrorHandler(event:Event):void
       trace("ioErrorHandler: " + event);
      private function setPan(pan:Number):void
       trace("setPan: " + pan.toFixed(2));
       var transform:SoundTransform = channel.soundTransform;
       transform.pan = pan;
       channel.soundTransform = transform;
      private function setVolume(volume:Number):void
       trace("setVolume: " + volume.toFixed(2));
       var transform:SoundTransform = channel.soundTransform;
       transform.volume = volume;
       channel.soundTransform = transform;
      private function mouseMoveHandler(event:MouseEvent):void
       var halfStage:uint = Math.floor(stage.stageWidth / 2);
       var xPos:uint = event.stageX;
       var yPos:uint = event.stageY;
       var value:Number;
       var pan:Number;
       if (xPos > halfStage)
        value = xPos / halfStage;
        pan = value - 1;
       else if (xPos < halfStage)
        value = (xPos - halfStage) / halfStage;
        pan = value;
       else
        pan = 0;
       var volume:Number = 1 - (yPos / stage.stageHeight);
       setVolume(volume);
       setPan(pan);
     package
    import flash.display.Sprite;
    import flash.media.Sound;
    import flash.media.SoundChannel;
    import flash.net.URLLoader;
    import flash.net.URLRequest;
    import flash.text.TextField;
    import flash.events.MouseEvent;
    import flash.text.TextFieldAutoSize;
    public class SoundChannel_stopExample extends Sprite
      private var snd:Sound = new Sound();
      private var channel:SoundChannel = new SoundChannel();
      private var button:TextField = new TextField();
      public function SoundChannel_stopExample()
       var req:URLRequest = new URLRequest("MySound.mp3");
       snd.load(req);
       button.x = 10;
       button.y = 10;
       button.text = "PLAY";
       button.border = true;
       button.background = true;
       button.selectable = false;
       button.autoSize = TextFieldAutoSize.CENTER;
       button.addEventListener(MouseEvent.CLICK, clickHandler);
       this.addChild(button);
      private function clickHandler(e:MouseEvent):void
       var pausePosition:int = channel.position;
       if (button.text == "PLAY")
        channel = snd.play(pausePosition);
        button.text = "PAUSE";
       else
        channel.stop();
        button.text = "PLAY";

  • My rented movie stops at a certain spot in the movie, and wont ever play again. WHY

    Whenever i try to play 21 Jump Street as a rented movie it stops at 8:16 and wont play again. Restarting itunes doesnt help.

    I'd report the problem to the iTunes Store. 
    Log in to the Store. Click on "Account" in your Quick Links. When you're in your Account information screen, go down to Purchase History and click "See all".
    Find the item that is not playing properly. If you can't see "Report a Problem" next to the item, click the "Report a problem" button. Now click the "Report a Problem" link next to the item.

  • I've installed Flip4Mac WMV in Lion and when I try to listen to audio in some sites, it starts playing and after about 0.5 seconds it starts playing again. So, I have the same thing playing with a delay... What is happening and how to fix it?

    I've installed Flip4Mac WMV in Lion and when I try to listen to audio in some sites, it starts playing and after about 0.5 seconds it starts playing again. So, I have the same thing playing with a delay... What is happening and how to fix it? Is there any other way to play theese kinds of files without using Flip4Mac WMV?

    Use Flash Media Server to stream the files.......set up a timer and have all three of them play at once....and have a button switch the streams depending upon which stream you want to play.....and wallah......
    you can also capture the stream.time from the video playing and resume from that point on the other videos as well....havent done this theoretically so I dont know how smooth the transistion between streams will be....but it can be done....
    plus u may have to use double buffering techniques to make sure it starts up right away......
    thelegendaryghost

  • Re deleting Play Movie button and associated links.

    Hi - thanks in advance for any help to a newbie.
    I have created an iDVD5 file from iMovie5. All went well with Chapter markers etc all coming through into my chosen theme. I started to customise the theme to my liking and noticed in the map area a file called 'Beginning' which was not one of my chapters. I saw that it was the start of the movie which I already had created a chapter marker for, and so I deleted it, thinking it superfluous. Subsequently, I noticed that the 'Play Movie" button had disappeared from the opening screen. The chapters are all intact and I can access and play these in the usual way. I can't, however, opt to play the full movie from the start because of no button or underlying link. Is there a solution?

    Hi, Laureid,
    Welcome to the discussions!
    Glad you are using iDVD and making your project from iMovie! You have made an error with your chapter markers, and unfortunately, you would have had no way of knowing that.
    You will have to recreate your DVD project. Go back into iMovie and delete your beginning chapter marker. As you have seen, iDVD makes the beginning chapter marker for you. Your movie will not play correctly if you do not let iDVD do this for you.
    Relaunch iDVD and create the project again, then import your movie into the new iDVD....or you can use the "Create DVD" button in iMovie if that is what you did the first time and it worked for you. This time you should have all your chapter markers as well as the beginning one. You can easily rename that first marker in iDVD's scene selection menu, so that you can have it the name you wish instead of 'Beginning.'
    Your movie should play and burn to DVD just fine now.
    Good luck, and post back if this doesn't work.

  • Play & Pause buttons work...but not with each other

    V!P and dzedwards were a big help to me yesterday but now
    I've come up against something else...
    I've got 3 music buttons on a page. The code that I have
    plays and pauses each button perfectly. But if I have Button 1
    playing and I click on button 2 (without stopping button 1
    manually), and button 1 is still playing...both play at the same
    time. Which, I understand why it's doing that but I'm not sure how
    to fix it.
    What do I need to add to the code so as to stop the first one
    from playing if I don't manually click it to stop? The first
    button's instance is monkey7, the second button's instance is
    iBelieve and the third button's instance is Perfection.
    monkey7 = new Sound();
    monkey7.attachSound("monkey7.mp3");
    monkey7.start(0);
    var elapsedTime:Number;
    var played:Boolean = false;
    pauseButton.onRelease = function() {
    if (played) {
    monkey7.start(monkey7.position/1000);
    played = false;
    } else {
    monkey7.stop();
    played = true;
    Thanks. And I apologize to V!P and DZ in advance.

    Well..not exactly. Crap, how do I explain this? The
    pauseButton is where you're applying the stop commands but from
    what I can tell, it's not doing anything because the play/pause
    button (pauseButton) isn't the problem, it's the button for the
    next song.
    My problem is when they don't click the play/pause button and
    go directly to the next button with the next song.
    If it makes it easier to see what I'm talking about, you can
    go to
    http://www.monkeypunk.com/,
    click on the music button, click on Monkey #7 button and you'll see
    the layout. It takes a couple of seconds for the preloader to
    appear.
    The arrow button on the right of the songs is the
    pauseButton. My problem is, when they don't click that but click
    the next button beneath, the button previous to it continues to
    play.
    Again, I apologize if I didn't explain it better
    originally.

  • Back button in AS3

    I did a search on this and didn't find a successful answer
    yet. I need to have a back button in AS3 that'll remember the last
    frame visited from any frame in the site. There are various buttons
    to get to various frames, and the one back button will always be
    showing.
    What's the script to make that happen from any frame
    utilizing AS3?

    OK, syntax was wrong and I fixed that (I knew it had to be
    some silly error like that).
    So now, if I go to one of the pages (frames), then go back to
    the home page (home frame), and click the back button it works to
    take you back to whatever subpage you were just on. However, it
    only works from the home page to go back to a subpage. You can't
    use the back button to go from one subpage to another you were just
    on, or back to the home page again. Why would that be? Is there a
    way to make the back button work from anywhere?
    Also, it only works if I don't assign the home page a
    backvalue (probably why you can't go "back" to the home page). But,
    since it works to go back from there to any other page you were
    just on, I think it must be close to working across the
    board… just curious what the problem could be…
    help??

  • Universal dock remote control play/pause button doesn't work

    Hi all,
    Ok since updating to Ipod touch software v2.2 I have been unable to use the play/pause button on my Apple universal dock remote, whilst my iPod touch is in the dock.
    The volume controls and track next and previous buttons commands on the remote control work just fine.
    I have tried unpairing and then pairing the remote with the universal dock but same issue. I thought that maybe the play/pause key was possibly broken. However I tested the remote on my iMac and play/pause button works fine in front row.
    Any ideas/suggestions would be much appreciated.

    Strange thing is mine started working again last night and is still working. Seems the problem went away as it originally appeared. I hope it doesn't stop working.
    I will mark this thread as unanswered until we can figure why the remote, universal dock and iPod touch are behaving this way.

  • Creating a 'Play All' button which will play individual tracks

    I've created a DVD with a main menu with connections to three sub menus which each have several separate tracks, each with their own individual buttons. The tracks do not have chapters. I would like to make a 'play all' button on each sub menu, so that all the tracks play one after another. I have tried it in a 'story' but found I can't link separate tracks--that seems to only be for linking chapters within the same track.
    I am already at 4.6 GB on a DVD 5 so I was hoping not to have to recreate another track with all of the movies in one... then I think I would have to jump up to a DVD 9. ... or...? Anyone have any info?

    The easiest way to do this is as Eric said - create one track and put ALL your clips into it, delete the other tracks. You'll need to set chapter markers up, and use stories to play the different sections on their own, but you can then make a simple play all scenario.
    If you really don't want to do that, you'll need to script this. The model to have in your head is that when you use the 'play all' button you set 'flag'. The first track plays and at the end the jump goes to a short script that looks to see if the 'flag' is in place - if it is you jump to the next track. If not, you go back to the menu. This continues for every track you need to include - each end jump goes to a short script which looks for the 'flag'.
    the 'flag' is simply a value that you put into a memory slot. You have got 8 memory slots to play with, called 'GPRMs' (General Parameter Register Memory). They are sometimes called variables.
    As with almost everything else in DVDSP, there are several ways to create this scripted solution. One way is here:
    http://www.dvdstudiopro.co.uk/tutorials/play-all-1/
    It has a set of sample files to download and explore. The thing to remember is that the sample layouts are not intended to be used for a real project, only prove the concept. A couple of additional things need to be done to make them suitable for full production.
    If you are comfortable with scripting in general, a slightly more complex solution is here:
    http://www.dvdstudiopro.co.uk/tutorials/play-all-3/
    This last one uses just three scripts, and makes use of the internal numbering system to identify which track and menu you were just on, or going back to. Three scripts is simple, but the detail of the scripts is a little more complex! Once again, these are just examples and in order to use this particular sample layout a couple of other things need to be added to ensure it will work in a production disc. All very simple to do, of course.

  • While playing songs on my classic, they stop playing intermittently. I have to press "play" again to get them to play. I've restarted the iPod. No help there. Any ideas?

    While playing songs on my classic, they stop playing intermittently. I have to press "play" again to get them to play. I've restarted the iPod. No help there. Any ideas?

    I, too, am having this problem with my classic today. It's just begun stopping itself once on each song I play today. I press the middle Select button to start it again, but this is getting very annoying! I haven't tried anything on mine today.
    EDIT: I just realized that it's now doing this more than once per song. I just had this happen three times in a single 4 and half minute song. Any clues?

  • Scripting Play All Button Question

    Is there a way when I script a play all button, that at the end of playing each track individually, the button for the follow track is highlighted?
    Thanks.

    Eric,
    There are several ways to optimize Play All through different aspect clips, depending on the project type.
    One method is to conform the assets - though, this depends on the ratio of 4:3 to wide footage, and other factors - if you only have a couple of 4:3 assets, then you can make them wide (black on either side), and nestle them in with all the other wide clips in a single Track. You could also put them in another Track by themselves (still make them wide, and set for Pan and Scan - not failing to stripe the mpeg assets with the P&S centering vectors with John Brisbin's "Mpeg Append Force Pan and Scan"; that way the footage displays properly pillar bar'd on 16:9 TVs and full-screen on 4:3 TVs).
    If you have more or less equal number of different footage aspects, you can order your 'Play All' sequence to play through all the Wide Footage in one Track first and then jump to the other Track with all the 4:3 footage lined up in there (prepared for wide and set for Pan and Scan, as outlined above, so the clips aren't stretched out when presented on wide displays), and play them all the way through. I do have a procedure I use to make the jump from the first Track to the second super compatible with even marginal players, which prevents the back and forth jump.
    There are other ways, as well; again, depending on project parameters (and of course, wether Hal "got to 'em first" and had them script the twenty separate Tracks for Play All! ).
    Heck, *you don't even need a single script to set a project up to Play All through 20 Tracks (or any supported number), and then to have those same Tracks be switched to single play mode for targeting from their respective buttons on the menu. Zero scripts.* Play 20 Tracks in the order you define, or singly play any of the same 20 Tracks and return to the menu and proper button. But it's still better to put all the clips in a single Track and go with Stories.
    I have a start of an article on this whole question, and hopefully I'll be able to post it soon. My SPRM table I mentioned in another thread was delayed because of the games in NY (I'm based in Philly :- ), that will be up by Monday (feels good saying it!).
    Oh, and one correction to my reply above; When I said a Track is an entire 'Video Title Set Menu Domain', while true, all Tracks and Slideshows include such a structure; I should have said a Track is an entire 'Video Title Set'. It was late (that's my story, and I'm sticking to it :- )
    Take care,
    Trai
    Trai Forrester
    New Constellation Technologies
    DVD Verification

Maybe you are looking for