Frame gotoAndStop AS3 troubles

I am having trouble linking a frame to another one. Actually it does work, but frame 2 (or 3 or 4) is corrupted by content from frame 1.
Frame 1 contains 3 buttons, and each is linked to frame 2, 3 and 4 via a gotoandstop function, respectively. In addition each buttons have rollover state that show up in front of everything when moused over. So I have generated the following script for my "to top" and a "gotoAndStop" functions on the same actions layer  (fla.file enclosed)
My problem is that when I click on button 1, it does take me to frame 2, but content from frame 1 also shows up on frame 2, I have the same problem when I go to frame 3 or frame 4.... Now if I remove the "to top" function from my action layer, I do not have any problem at all ...
Can anybody help me here
Many many thanks
A newbie here

then use:
btn1.addEventListener(MouseEvent.ROLL_OVER,toTop);
btn2.addEventListener(MouseEvent.ROLL_OVER,toTop);
btn3.addEventListener(MouseEvent.ROLL_OVER,toTop);
function toTop(evt:MouseEvent):void {
    addChild(SimpleButton(evt.currentTarget));
stop();
btn1.addEventListener(MouseEvent.CLICK, mouseClickHandler);
btn2.addEventListener(MouseEvent.CLICK, mouseClickHandler);
btn3.addEventListener(MouseEvent.CLICK, mouseClickHandler);
function mouseClickHandler(event:MouseEvent):void {
   removeChild(btn1);
removeChild(btn2);
removeChild(btn3);
    gotoAndStop(event.currentTarget.name);

Similar Messages

  • Menu buttons only work in frame 1 - AS3

    Hello, smart Flasher-people out there....it would be great if
    you could help me with the following problem:
    I have a basic navigation with 5 buttons sitting on my main
    timeline. In frame 1 (on it's own separate layer), I have placed
    the AS that calls the button functions and tells the playhead to
    move to different keyframes within that main timeline and stop.
    Any of the clicks originating from frame 1 function properly
    and send the playhead to the respective new keyframe and stop.
    However, from there, the buttons do not respond to click anymore.
    Here's my script:
    Mediat_btn.addEventListener(MouseEvent.MOUSE_DOWN,mouseDownHandlerMediat);
    function mouseDownHandlerMediat(event:MouseEvent):void {
    this.gotoAndStop("Mediation");
    Coach_btn.addEventListener(MouseEvent.MOUSE_DOWN,mouseDownHandlerCoach);
    function mouseDownHandlerCoach(event:MouseEvent):void {
    this.gotoAndStop("Coaching");
    Komp_btn.addEventListener(MouseEvent.MOUSE_DOWN,mouseDownHandlerKomp);
    function mouseDownHandlerKomp(event:MouseEvent):void {
    this.gotoAndStop("Kompetenzen");
    Finanz_btn.addEventListener(MouseEvent.MOUSE_DOWN,mouseDownHandlerFinanz);
    function mouseDownHandlerFinanz(event:MouseEvent):void {
    this.gotoAndStop("Finanz");
    Kont_btn.addEventListener(MouseEvent.MOUSE_DOWN,mouseDownHandlerKontakt);
    function mouseDownHandlerKontakt(event:MouseEvent):void {
    this.gotoAndStop("Kontakt");
    Any idea as to why the script works when in frame one, but
    doesn't work after having clicked a button and the playhead has
    moved to another keyframe?
    Any help would be greatly appreciated!! Thanks in advance....

    Having them in different keyframes will kill the code for
    them that was assigned in the first frame, so you would need to
    have them span the timeline for first frame code to work for them.
    Now here's one thing that someone disagreed with me on, but I
    have yet to see that what they said work. I normally have timeline
    layers dedicated to code that applies to the whole sections of the
    timeline, meaning there would be no keyframes except the frame that
    initiates the code for that layer/section.
    So in your case, if the buttons span the timeline, so does
    the layer used to assign their code. I would also use such a layer
    for most functions because then they are available to whoever needs
    them along the timeline... sort of a global home for code.
    What someone told me was that you can interupt such
    actionscript layers with other keyframes/code, but as I said, it
    has yet to work that way for me... if I try it, the code is
    forgotten, so I leave the roads open.

  • FLVPlayer stop when redirecting to another frame. AS3

    Hi
    I am new in AS3, but now i have problem to stop plaing FLVPlayback.
    In main time line i have first frame used for preloader and second for intro.
    Frame 3 is first screen with videoand my MainMenu with buttons inside mc.
    Now when I click on button it successfully redirect screen to next frame and load my page, but I still hear music from video.
    I need to stop playing video when i redirect to frames 4, 5 ....28 where are pages frame by frame.
    In MainMenu i use
    import flash.events.MouseEvent;
    import flash.display.MovieClip;
    //menu Domov
    function btnHome(event:MouseEvent):void
        (root as MovieClip).gotoAndPlay(4);
    function btnOnas(event:MouseEvent):void
        (root as MovieClip).gotoAndPlay(5);
    function btnBoard(event:MouseEvent):void
        (root as MovieClip).gotoAndPlay(6);
    btnHome_btn.addEventListener (MouseEvent.CLICK, btnHome);
    btnOnas_btn.addEventListener (MouseEvent.CLICK, btnOnas);
    btnBoard_btn.addEventListener (MouseEvent.CLICK, btnBoard);
    website have 24 pages than i don't copy next buttons.
    sorry for my english.

    First include the SoundMixer class:
    import flash.media.SoundMixer;
    Then to stop the sounds call the stopAll method:
    SoundMixer.stopAll();

  • Help with gotoAndStop as3

    I have two scenes. Main scene and Building 1 Scene.
    If i put this code on my Main scene actionscript layer it does not work.
    bldg1_thumb1.addEventListener(MouseEvent.CLICK, bldg1_thumb1Click);
    function bldg1_thumb1Click(event:MouseEvent):void{
        gotoAndStop (2, "Building 1");
    But if I make a new actionscript layer inside my Building 1 scene it does work.
    how do i make this work by keeping all AS in my main scene?

    Keep everything in one scene or keep the code where the object it targets exists.  If the code to add the event listener to the button is in scene 1 and the button is in scene 2, the button won't work... they must co-exist in the same frame.

  • How to include .as (actionscript file) in frame in as3

    i have include an asctionScript file syntax is   #include "filename.as" when publishing comming syntax  error.

    In AS3 do not use the "#" character

  • Printing a single frame in AS3

    Hi all,  I want to create a button that when pressed will enable a single frame in a flash project to be printed.  Is there an easy way to do this?
    Any help would be great
    Laura

    check the printjob class to see if you can get it to do what you want.  often it's sufficient to do what you want, but for pixel perfect control of the printed page you may need to create (with code) a displayobject positioned and sized to conform to the print-page.

  • AS3 gotoAndPlay Frame in a prevFrame

    I think this should be a easy fix. I am self taught using Flash and putting together a photo gallery. I have a 2 swf files that when you enter play from frames 1 through 15. I have a back button that I am trying to play frames 16 to 30. I am trying to use as little code as possible and the swf files are nested in a Movieclip. I am trying to target frame 16 in each of the swf movieclip when they hit the back button.
    This is the code I have that works.
    left_btn.addEventListener(MouseEvent.CLICK, backward);
    function backward(e:Event):void {
       photos_mc.prevFrame();
    What I like it to do is
    left_btn.addEventListener(MouseEvent.CLICK, backward);
    function backward(e:Event):void {
       photos_mc.prevFrame(16);

    Are you trying to make this wrap around? When I see you advance the timeline forward in a function called backward() I assume you're trying to wrap around these two (or more) frames in your actual project.
    The img01_mc and img02_mc isn't helping you because you're using different frames. It's actually making you write more code to handle it. I'd recommend naming every image on a frame to the same name so the code can be re-used. Rename img01_mc and img02_mc to img_mc. Because they're on different frames it doesn't matter that the name is the same, they won't collide.
    After you rename them all to the same name you can do something like this to wrap:
    // back
    function backward(e:Event):void
           if (img_mc.currentFrame > 15)
                 // past frame 15 in current clip, replay from frame 1
                 img_mc.gotoAndPlay(1);
           else if ((img_mc.currentFrame <= 15) && (this.currentFrame > 2))
                 // reverse one frame in photos_mc on timeline
                 gotoAndStop(this.currentFrame - 1);
                 // play this previous clip from frame 16
                 img_mc.gotoAndPlay(16);
           else if ((img01_mc.currentFrame <= 15) && (this.currentFrame == 2))
                // on frame 2 and under frame 15, wrap to end
                 gotoAndStop(this.totalFrames);
                // play this previous clip from frame 16
                 img_mc.gotoAndPlay(16);
    // forward
    function forward(e:Event):void
           if (img_mc.currentFrame <= 15)
                // under or at frame 15 in current clip, play from frame 16
                 img_mc.gotoAndPlay(16);
           else if ((img_mc.currentFrame > 15) && (this.currentFrame < this.totalFrames))
                // over frame 15 in current image, more frames available in photos_mc, advance frame
                 gotoAndStop(this.currentFrame + 1);
                // clip should auto-play 1-15 itself
           else if ((img01_mc.currentFrame > 15) && (this.currentFrame == this.totalFrames))
                // on last frame in photos_mc, wrap to beginning, frame 2
                 gotoAndStop(2);
                // clip should auto-play 1-15 itself
    The idea here is to start your first image on frame 2, add as many frames with an image on it as you like expanding the timeline naming each image the same instance name img_mc. Each function will respectively check the current frame the image is on as well as the available frames in photos_mc and advance or reverse as needed. If frame 2 or the last frame in the timeline is encountered it should wrap.
    I wrote it quickly here so you might need to fix a typeo, missing period, etc. It should give you enough to do what you want.

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

  • One button controlling multiple buttons as3

    I'm trying to follow a tutorial I found online for a randomly selected image without using an XML or AS file.
    The problem is that I want to generate more than just one section, like generate an image from one group, and an image from another group, and etc etc. That's something I can do but there'd need to be a button for each group. It's not exactly horrible, but I was hoping to just have a "one button controls everything". So is there a basic code that will say "When this master button is clicked, all these other buttons are clicked"?
    Here's the tutorial for reference.
    Flash Tutorial: Generate a Random Frame with AS3 -HD- - YouTube

    One approach is to have the event handler of the button call all of the other button's event handler functions, passing its received event argument to them.  If you were to name the other functions in some numeric  pattern then you could loop thru them rather than writing each one out separately.
    Another approach would be to have one single function that works for all the buttons where you test which button was clicked and decide which commands to execute.

  • Preloader and Document Class BIG question (yeap please help)

    Hy,
    I know that this its a question posted many, many times, but
    after searching the net, reading a lot of books and searching this
    forum too, I cant get out with a solution. If I'd say for sure
    there is no possibility to create something like this, I just go
    back to old methods but is not the scope of Adobe with AS3 to
    encourage the use of OOP principle or not?
    The problem:
    I have a single fla file (AS3) with a single frame on
    timeline, frame that its there when you will create the file with
    flash. In the library I have different symbols, that for simplicity
    are only jpg image, (BitmapData) checked for export for
    ActionScript and exported on frame one. An external .as file called
    DocumentClass its off course my Document Class
    This its all that I want to do with the fla, the goal its to
    create, animate etc. only with AS3 in external classes, no timeline
    script. I don't want to load external files, XML, or else in this
    movie. I just want a single swf after compilation, no additional
    files.
    Ok, how do I create a preloader that will take care of
    starting the logic after the whole swf its loaded and in the same
    time shows the user a percentage or a load bar or something that
    its not the blank screen when the swf its downloading. I want to do
    this without another swf that load this swf, or timeline scripts,
    or place all the content on second frame and then gotoAndStop to
    the third frame. All this are not solution but cheap tricks, that
    are against all this OOP principle that I just continue to read in
    books and here from guru programmers.
    The big question is:
    It is possible to create a preloader, when use a document
    class with your fla? And if yes, how?
    I know that the Document Class its not instantiated if its
    not fully loaded, if that's true when the document class will be
    fully loaded? maybe after the whole movie its loaded? And, if its
    true, it will never show a percentage bar "while" the movie its
    loaded. And if that's true WHY use a document class anyway?
    Thank you for reading this and I really wait to get some
    answer.

    I am pretty sure you cannot do self preloader with one frame
    and all the objects in the library. I guess the key here is
    one-frame design. Screen refreshes (renders) only when all the
    scripts in the frame are executed - this is a very important thing
    to understand about how Flash works. Yes, you can force screen
    refresh with updateAfterEvent() method but it is attached to a
    handful of events only (MouseEvent and TimerEvent) but, again, all
    this functionality is available only after first frame scripts are
    executed. Thus, it seems like the only way to create preloader from
    within SWF is to use multiple frames and set library objects to
    load in later (not first) frame.
    quote:
    And if that's true WHY use a document class anyway?
    Well, preloader is the last thing that would be on my mind in
    terms of using AS3 ability to link DocumentClass to the top movie.
    This feature allows for very sophisticated architectural
    approaches. It has no connection to preloader as to any other
    features developer wants to implement. Neither it depends on or
    negates timeline. As a matter of fact, although I love one-frame
    applications, I find on numerous occasions that my application
    would be more efficient if I used several (at least two) frames.
    gotoAndStop is not deprecated. It is a valid MovieClip class'
    method. After all, having only one frame doesn't mean not having
    frames at all - there is one already. Frames are fundament of
    Flash. AS3 did introduce frameless entities like Sprite, etc. but
    it doesn't mean that frames are going anywhere.
    I would agree that timeline code is inferior to
    classed/packaged (read: better organized) code but, still, how is
    it not OOP? Frame is an Object, right? Why using timeline is cheap
    and not a solution?
    On a side note, I see too many times how some authors (and
    managers) are pushing their agenda (or close mindedness) onto their
    audience with no real substantiation. Claiming that timeline in
    Flash is not valid architectural decision from OOP standpoint is
    totally wrong. As wrong as strict adherence to design patterns. I
    don't think there is sharply defined "right" or "wrong" in
    programming. One finds the best optimal solution. The goal is to
    create something that works fine. Unless, of course, the process is
    the goal - but very few of us can afford focusing on the process.

  • LoadVariablesNum on button to access cgi script mail form

    Greetings: I've used this method many times in the past to create an email form in a movie clip with a "send button" that accesses a perl, cgi script to email text input fields. It worked fine in past versions of Flash, but now I'm using Flash CS3 (v9.0, AS 2.0). I've tried 3 different cgi scripts I found online for this purpose and am sure the configurations for sendmail server & perl bins, etc are correct. All of the other "if" and "else" statements on the button work fine. But I can see a Safari (browser) error message saying POST was not used, but clearly it is. I'm trying to trouble shoot whether the problem is from the flash button or the cgi script.
    Has something changed in Flash CS3 from previous versions, where I'm certain it has worked before???
    Here is my button code:
    on (release) {
    //Make sure the user filled in all the required fields.
    if (name1 ne "" and name2 ne "" and subject ne "" and email ne "") {
    //Check to make sure the email address includes and @.
    i = "0";
    validmail = 0;
    while (Number(i)<=Number(length(email))) {
    if (substring(email, i, 1) eq "@") {
    validmail = 1;
    i = Number(i)+1;
    //If there's no @ in the email go to the error page.
    if (Number(validmail) == 0) {
    gotoAndStop("error");
    } else {
    //The line below assumes the script is in the same directory as the HTML page.
    loadVariablesNum("http://www.companyname.com/cgi-bin/FormMail.pl", 0, "POST");
    //Go to the confirmation frame.
    gotoAndStop("thankyou");
    } else {
    //if the user left required fields blank, show them an error message.
    gotoAndStop("error");
    Here is the error message I can access on Safari>window>activity:
    "The HTML form fails to specify the POST method, so it would not be correct for this script to take any action in response to your request.
    If you are attempting to configure this form to run with FormMail, you need to set the request method to POST in the opening form tag, like this: <form action="/cgi-bin/FormMail.pl" method="post">
    Why isn't the command from the button in the Flash swf file, being recognized by the html page?
    Thanks in advance for any help.
    Janis

    in version 6, case didn't count. after version 6, it counts.
    so, gotoandPlay(3), used to work but, not now.  you need to use gotoAndPlay(3).
    also, undefined numeric variables were assigned a default value of 0 with flash 6 and prior.  not now, they're undefined.  so, watch for code like
    while(var1<1){
    do something
    var1++;
    where var1 is never initialized.
    about policy files:  check the security class'es loadPolicyFile() method.

  • SCENES BACK BUTTON

    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 SCENE visited from any frame in the site. There are various buttons to get to various SCENES, and the one back button will always be showing.
    What's the script to make that happen from any frame utilizing AS3?

    you should execute the following once:
    var sceneA:Array = [];
    function addSceneF(scene:Scene):void{
        sceneA.push(scene);
    function prevSceneF():void{
        sceneA.pop();
        this.gotoAndStop(1,sceneA.pop().name);
    // then on frame 1 of each scene use:
    addSceneF(this.currentScene);
    and have your previous scene button call prevSceneF whenever you want to return to a previously visited scene.
    (and you should do some error checking to make sure sceneA.length >0 before applying that goto.)

  • Detecting the end of a movie clip

    Hi,
    Objective: Display a book that the user can turn the pages to
    view more text. I used a tutorial from the web to create the
    turning page.
    Process: On layer 1, frame 1 of the main time line, I put an
    image of a book. On layer 2, frame 1 and also frame 2 of the main
    time line, I put text for the book. I then created a movie clip
    (MC) called PageTurnMC that looks like a page in the book is being
    turned. On layer 3 of the main time line, I put an instance of the
    MC and called it PageTurn. On layer 4 of the main time line, I put
    a button to play the MC and advance to frame 2 called drawer1cont
    (see code).
    //code on the button used to turn the book's page
    on (release) {
    PageTurn.play(); //plays my PageTurnMC
    gotoAndStop("drawer1cont"); //advance to the next frame of
    text
    Problem: I need to detect when the end of the MC before I
    advance to the next frame. I have to use the PageTurnMC many times,
    so it is not possible for me to put the action in the last frame of
    MC. As of right now, my frame 2 text appears as the PageTurnMC
    plays which is not what I want.
    Thanks for any help.

    I just tested it and got my quick example to work. Here are a
    couple of possible areas to double check:
    In the last frame of PageTurnMC, gotoAndStop must reference
    the main movie clip, e.g. _root.gotoAndStop().
    Also, make sure the parameter _root.frameID isn't in quotes
    because it is a variable, not the actual string.
    As I said, I'm not a Flash expert nor do I know the setup of
    your movie, but this should work as long as you have all of your
    references correct. If you can't get it to work, try to trace
    necessary variables to make sure you are accessing the appropriate
    variable.
    The suggestion by nilu_only will also work, but it will waste
    some cycles because you will have to wait for the movie clip to
    end. Here is what I mean:
    Immediately after playing PageTurn, accessing
    PageTurn._currentFrame will return the currentFrame only once. So
    if PageTurn isn't on its lastFrame, your condition statement
    (PageTurn_currentframe == PageTurn._totalframe) will fail and
    gotoAndStop will never be called.
    Instead, you would need to wait for some time and continually
    check the _currentFrame until the condition statement is true, e.g:
    on (release) {
    PageTurn.play();
    while (PageTurn_currentframe != PageTurn._totalframe) {}
    //wait until reaches the last frame
    gotoAndStop ("drawer1cont")
    This approach is likely to be suboptimal since you are
    wasting cycles checking the current frame instead of just having
    the movie let you know when it has reached the last frame.
    Depending on how Flash handles that while statement, you could have
    serious slowdown from that while statement. And since Flash doesn't
    have a sleep() function, you would have to do some sort of
    setTimeout() to slow down those checks. Either way, I would venture
    to say this approach is better off avoided.

  • General question about classes

    Hi every one,
    I have an application that works but i'll like to optimize it, regarding about speed and system ressources. For resume and represent diagrammatically the application I wrote, there is a first frame (the main menu) with severals buttons. When I push a button I show a new frame with a query resultset displayed inside.
    Theses second frames are all very similars, just a few things are differents between one and another (sql string of the query, and some controls may be visible or not).
    So there are many solutions to write it :
    1- I can make a class representing this second frame and each time I push a button from the main menu, I create a new Object with this class and when I quit this frame I do a "dispose" of it.
    2 - (the solution I got) I create an Object with the model of this second frame once and for all, and when I push a button I set visible this frame and call a method to change some parameters, when I quit the frame I set it hide.
    I think second option is not to bad and the first one is very heavy, but If I created a class B that extends my second frame A (that contains the main code for displaying results) and each time I push a button from the main menu I created an object from B type, is it a good idea ??
    Hope you understand my problem, and hope anyone will give me an idea...

    Hi rainek and ty for your attention,
    Yes you understood right :
    my app creates Frame 1 with buttons and show it, and I create on the background a raw version of Frame 2 shown, and with changed parameters when button is pressed.
    But I don't not extend Frame 2 with a SubFrame 2, I just wonder if it would be a good thing to create subframe 2 and instance it each time I push a button from Frame 1, instead to use the same Frame 2 raw version (storing it in a file config indeed) from the background. I wondered, if when I instance for the second time a subframe 2 it was speeder because an object subframe 2 as already been instancied before.
    You know my problem was also that when I created Frame 2 in the background before create Frame 1, it gave my troubles with Frame 1 display (cf. my topic :http://forums.java.sun.com/thread.jsp?forum=57&thread=231897), so now I create this frame 2 raw version the first time I push any button, but of course there is a litte big longer time answer this first time. (I thank too, to create Frame 2 raw version in a thread to avoid frame 1 display troubles)
    Hope I'm clear and you understand me, for resume in a generic problem, I wonder know if when i have this config :
    Frame 2,
    Subframe2 that extends Frame 2
    if i do
    Subframe2 myframe_a = new Subframe2 (<parameters_a>) and
    Subframe2 myframe_b = new Subframe2 (<parameters_b>)
    myframe_b is created more quickly because myframe_a as been instancied before
    Any way ty very much for your answer rainek !!

  • Control where to start and stop an SWF file inserted into a Captivate 6 slide.

    I am working on a project in which I need to insert SWFs on to slides in Captivate 6 and I've reached a hick-up. Some of the SWFs only need to start play at a specific frame (which is not necessarily the beginning of the SWF) and stop play at a specific frame (which is not necessarily the end of the SWF).
    Is there a way, by use of "Execute Advanced Actions" or "JavaScript", to control the play of a SWF, inserted on a slide, so that it starts and stops at desired frames?

    I think it is almost there now. Thanks for putting me int he right direction. You may be able to offer observations on my coding:
    this.onLoad = function() {
        stop();
    this.onMouseMove=function()
        // Test current mouse position is within the dimensions of the image
        if(_root._xmouse >= 0 && _root._xmouse <= 130 &&
           _root._ymouse >= 0 && _root._ymouse <= 420)
            // It is safe to play the animation as the mouse is within the
            // stage area
            play();
        else
            // We must stop animating and revert back to the first frame
            gotoAndStop(1);
    this.onRollOut = function() {
        stop();
    http://www.trucklesoft.co.uk/silcox/lounge.html

Maybe you are looking for