AS 2.0 problem

  • Started
  • Last post
  • 3 Responses
  • Beeswax

    I'm stuck here for 2 days, I've written to stackoverflow but no responses yet. I hope there's someone who can find a cure to this.

    I use attachMovie to call movie clips succesively on the stage. I use a forward button to slide them in progression but when I want to go back in the same order everything gets messed up. You can see the swf playing here,

    http://www.taltin.net/FILES_WEBD…

    I numbered each frame so you can see when clicking on back button it gets messed up.

    // Each of the button functions here call the add_page() function and
    // pass the Identifier of the page that they will display
    b_0.onRelease = function() {
    next_page( "Video1A_" + page_count);
    };

    b_1.onRelease = function() {
    prev_page( "Video1A_" + page_count);
    };

    // This function manages the page clips that are attached to content_mc.
    // The variable page_count is used to make sure that each page gets a unique
    // name and depth. It also gives us a way to get the instance name of the
    // last page clip that was created.
    var page_count = 1;

    // The add_page() function takes the Linkage identifier of the new page to be
    // created as a parameter.
    function next_page( next_page ) {
    // Make the name of the last page attached
    var old_page = content_mc[ "Video1A_" + page_count ];
    // If that page exists remove it by sliding off out of the visible area.
    if ( old_page != undefined ) {
    old_page.slideTo( '-600', '0', 1, '', 0, old_page + '.removeMovieClip()' );
    }

    // Up page count by 1
    page_count ++;

    // Attach the new page to content_mc
    var new_page = content_mc.attachMovie( next_page, "Video1A_" + page_count, page_count );
    // Position the new page below the visible area
    new_page._x = 600;
    // slide the new page into the visible area.
    new_page.slideTo( '-600', 0, 2 );
    }

    // The add_page() function takes the Linkage identifier of the new page to be
    // created as a parameter.
    function prev_page( next_page ) {
    // Make the name of the last page attached
    var old_page = content_mc[ "Video1A_" + page_count ];

    // If that page exists remove it by sliding off out of the visible area.
    if ( old_page != undefined ) {
    old_page.slideTo( '600', '0', 2, '', 0, old_page + '.removeMovieClip()' );
    }

    // Up page count by 1
    page_count --;

    // Attach the new page to content_mc
    var new_page = content_mc.attachMovie( next_page, "Video1A_" + page_count, page_count );
    // Position the new page below the visible area
    new_page._x = -600;
    // slide the new page into the visible area.
    new_page.slideTo( '600', 0, 2 );
    }

  • dasmeteor0

    Obviously it's an incrementation problem.
    onRelease you are using the old "page_count" variable.
    I suggest you to trace that variable and maybe to increment it on the release event :
    b_0.onRelease = function() {
    page_count ++;
    next_page( "Video1A_" + page_count);
    };
    b_1.onRelease = function() {
    page_count --;
    prev_page( "Video1A_" + page_count);
    };

    or

    increment your variable at the end of your next_page and prev_page functions

    But the problem is here.
    Also try to test the limits >>> I guess there's nomovieclip named Video1A_-1 or Video1A_500

  • Beeswax0

    I'm sorry I'm really not good at this.
    If a try the first solution should I remove page_count++; and page_count--; as well?
    Or in second solution, how can i increment the variable at the end of the function?

  • mikotondria30

    This was what aged me 10 years doing any sizable Flash project - the unpredictability of finding solutions to problems like that that meant completion dates for deadlines became more inaccurate the closer they got. 2 days to solve this ? No one can afford that - the saving grace of Flash is that there's always another way to do things. Rather than spending 2 days trying to match your concept of incrementation to that of the code you wrote to do it, and giving yourself a minor stroke and putting the project back 2 days, redo it another way. Of the top of my head - have a timeline along which you progress with the as controlling specifically which MC to addtostage, scroll out or in, and eventually removefromstage. It might seem long-hand, and a bit of a hack, but it'll work and when you come back to it in 6 months it'll be easy to understand and you won't have to relearn all the code you spent 2 days learning, that you'll forget in a weeks' time. It fits the mantra of keeping it simple and reducing code and keyframes and actions and all to try it the proper way as you have been doing, but if you haven't nailed something like that within an hour, trash it and do it quick and dirty - you don't get extra marks for being clever. Bosh it out, spend that extra time you save sprucing up the other stuff so the client loves it.