A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: Actionscript not working

  1. #1
    Member
    Join Date
    Jul 2005
    Posts
    47

    Actionscript not working

    Hi everyone,

    I have 5 movieclips on the main timeline and each of these movieclips contains their own animation on their own timeline. When the movie loads, I need to have movieclip 1 place first, then movieclip 2, then 3 etc., then loop back to movieclip 1 and play over.

    On frame 1 of the main timeline, I have the following actionscript:

    root.gotoAndPlay(this.first_mc)

    I thought this would tell it to go to first_mc movieclip and play.

    Then on frame 1 of each of the movieclips timelines I have a stop action - stop();

    On the last frame of each of the timelines I have an action that should instruct which of the movie clips to play next:

    root.gotoAndPlay(this.second_mc)

    Problem is when I test, nothing plays.

    Any advice on what I might be doing wrong would be much appreciated.

  2. #2
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    You gotoAndPlay to either a frame number or a label on a timeline.

    Also you have a typo. it's supposed to be _root. And you need a semicolon at the end of each statement. As in:

    Actionscript Code:
    _root.gotoAndPlay(10);
    or
    Actionscript Code:
    _root.gotoAndPlay("someLabel");

    gparis

  3. #3
    Member
    Join Date
    Jul 2005
    Posts
    47
    Thanks for the reply,

    Just to clarify, all of the five movieclips are located on 5 different layers on the main timeline and they're all on frame 1.

    On frame 1 of the main timeline I have the following:

    first_mc.onEnterFrame = function () {
    this.play();
    }

    The above piece of code has successfully played through first_mc.

    On the first frame of first_mc I have a stop(); action and on the last frame I have the following code:

    _root.second_mc.gotoAndPlay(1);

    So after first_mc has played through, the above line of code has successfully caused second_mc to play. The problem is that after first_mc plays through, it plays through again, at the same time that second_mc plays through.

    Third_mc, Fourth_mc and Fifth_mc all have a stop action on frame one and on the last frame of each of these timelines there's the following code:

    _root.third_mc.gotoAndPlay(1);

    _root.fourth_mc.gotoAndPlay(1);

    _root.fifth_mc.gotoAndPlay(1);

    But as mentioned it's only playing the first_mc and second_mc.

    Can you help further?

  4. #4
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    first_mc.onEnterFrame = function () {
    this.play();
    }

    not necessary. it will play on its own if there's no stop on that 1st mc's 1st keyframe.

    Also is it possible that you higher layers hide the ones below.
    I'm also guessing you have a stop() on keyframe #1, so you'd need a play() on keyframe #2 and say gotoAndPlay(2) instead.

    That said, why not put these sequential mcs each on its own keyframe?
    Then, at the end of an mc, place:
    _parent.nextFrame();

    Then _parent (the parent timeline, ie _root) will go to its next keyframe and the mc there will automatically start to play.

    gparis

  5. #5
    Member
    Join Date
    Jul 2005
    Posts
    47
    Ok so I've adjusted the setup as you've suggested. Each movieclip is sitting on its own keyframe - each of them one after the other.

    These are the movieclip names;

    One_mc
    Two_mc
    Three_mc
    Four_mc
    Five_mc

    One_mc is on frame 1, Two_mc on frame 2 etc.

    On frame 1 of the main timeline there is a stop() action only.

    On frame 1 of One_mc's timeline is a play() action and on the last frame of this timeline is _parent.nextFrame();

    Two_mc, Three_mc and Four_mc each have the following code on frame 1:

    stop();
    gotoAndPlay(2);

    and the following code on the last frame:

    _parent.nextFrame();

    The final mc, ie. Five_mc also has stop() and gotoAndPlay(2) on the first keyframe (like the previous 3) but on the last frame it has:

    _parent.One_mc.gotoAndPlay(1);

    This is because I wanted it to loop back to the first movieclip.

    It all plays well, ie. going from one movieclip to the next, but when it gets to the last mc, ie. Five_mc, it doesn't loop back to the first. Instead it loops through itself over and over again. So it's stuck on this last movieclip.

    In addition to this, when I test I get the following compile error:

    Scene=Scene 1, layer=MovieClip1, frame=1, Line1
    Statement must appear within on/onClipEvent handler

    Not sure what's happening here. Are you able to help further?

  6. #6
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    The error means you put the action ON an object instead of a frame.
    On frame 1 of the main timeline there is a stop() action only.
    you'll need stops on each keyframe where the mcs are on the main timeline. Saying nextFrame() is like saying gotoAndStop(_currentframe+1)
    stop();
    gotoAndPlay(2);
    Wrong. don't put anything in these mcs' first frames (appart from the last keyframe that sends the main timeline to its next keyframe. Your movies will play on their own.

    gparis

  7. #7
    Member
    Join Date
    Jul 2005
    Posts
    47
    That's fixed it. Thanks for your help.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center