Groups | Blog | Home
all groups > flash actionscript > august 2004 >

flash actionscript : gotoAndPlay problem - please help!


Fish.boy
8/4/2004 9:53:24 PM
Hi,

This is my first post (with probably more to come) in this forum.

I could really use some help with some actionscript - I've been trying to get
this working for the past 8 hours, and I'm getting really frustrated. Here's
what I'm doing.

I've created a new document, and have written a piece of actionscript into the
first frame, which creates a new movie clip on the stage, and loads a SWF into
it, which I created earlier.

The SWF I'm loading into my document has 50 frames, but has a 'Stop();' in its
first frame, the idea being that it loads on to the stage showing only the
first frame, but doesn't play the remaining frames until I tell it to.

This is straight forward enough, and is working fine - when I preview it, I
can see the SWF appearing, and it is only showing its first frame as it should.

To then get my imported SWF to play from frame 2 to frame 50 of its timeline,
I'm using gotoAndPlay("2"), except it's just not moving as I would expect, and
just stays on frame 1, meaning I'm not able to control its timeline.

I've been through the bulk of the help documentation, searched this forum and
the Net, and can't find what I'm doing wrong. I'd really appreciate any help I
could get.

Here is the code I've written in to my document to create the movie clip, load
in the SWF, then play it from frame 2:

this.createEmptyMovieClip("mcRedBGround",11);
mcRedBGround.loadMovie("SWFs/RedBackground.swf");
mcRedBGround.gotoAndPlay(3);

mcRedBGround is the name of the movie clip I've created on the stage, and
RedBackground.swf is the SWF file I'm loading in to my new movie clip.

Please don't tell me I've missed something glaringly obvious! This has been
driving me nuts!

Thanks for any help you can give me,

fb
Happy Camper
8/4/2004 10:31:26 PM
The news is good... you are only missing one part of the command...

mcRedBGround.gotoAndPlay(3);
should be...
_level11.mcRedBGround.gotoAndPlay(3);

...but if you are going to bring it in, and play it right away, then just get
rid of the stop() action in the SWF you are loading. You would only need that
stop() if you wanted the movie to stay at that first keyframe until somebody
hit a button.. then you would put

on(press){
_level11.mcRedBGround.gotoAndPlay(3);
}

on the button.
mandingo
8/4/2004 11:17:58 PM
The 11 in the create isn't a level, it is a depth...

okay, now under normal circumstances the syntax below should work... BUT WON'T
!!

this.createEmptyMovieClip("mcRedBGround",11);
loadMovie("SWFs/RedBackground.swf",this.mcRedBGround);
mcRedBGround.gotoAndPlay(3);

the trouble is that the loadMovie hasn't finished by the time the gotoAndPlay
action is called therefor the movie hasn't been instantiated and can't play.

either in a button or a setInterval ensuring time for the loadMovie to have
loaded your SWF, mcRedBGround.gotAndPlay(3) will work...

I hope that helps,
cheers

Happy Camper
8/4/2004 11:49:58 PM
mandingo
8/4/2004 11:53:29 PM
That would depend on it's purpose... it may be a splash screen for a product
etc... and the client needs it to display info prior to continuing... there are
a lot of reasons why you may need it to wait for input...

The issue is that the movie must be fully loaded prior to interacting with it
.... like a play action.
Fish.boy
8/5/2004 12:21:06 AM
Hi mandingo and Happy Camper,

Thanks for the speedy replies. I see where you're coming from, but still feel
I should be able to control the timeline of any SWFs that I bring in through
actionscript and without any user ineraction, such as clicking a button.

To give you a little background, I'm constructing a Web site for a feature
film, and have a number of different elements to use on the site, which are
stored in seperate SWFs. The idea is that visitors to the site will navigate
to a page, and only the SWFs for that section will be loaded - I suppose it's a
modular approach to building the site. This is the first Flash site I've
created, but I've been giving this some thought and think this is a good way to
go. What are your thoughts on this?

This means if one page in the site has three SWFs that need to load in, I was
hoping to load them, and then be able to trigger them as they are needed. This
is important, as part of the site gives a synopsis of the film, and I was
hoping to have this broken down in to a series of SWF files, which I could load
in, then play back to back in the correct order.

I'm using MX Pro, and have created this in a form application, where each form
in the application represents a different page in the site, with the navigation
for the whole site built in to the top level (master) form - this seems to me
to be an easy way to construct the site.

D'you think the approach I'm taking will work, or is it simply not possible to
be able to control a SWF timeline the way I'm looking to with actionscript? Or
would you recommend a different approach?

Thanks again for your help,

fb
mandingo
8/5/2004 12:26:56 AM
If you do as Happy Camper has said and remove the stop() action in the first
frame of the loaded SWF's then they will play once they are loaded... no
problems...

of course if you are intending to load them consecutively into the same
container, then you are going to have some issues with when the next loaded SWF
is going to load as it will replace the previous swf...

nothing insurmountable... just some code on the end of each loaded SWF to tell
the _parent that it is finished and needs the next SWF... or similar

cheers,
Fish.boy
8/5/2004 12:42:43 AM
Excellent - thanks for this.

Last question on this, then, if I do let them play, can I then control the
timeline for the movies through actionscript without having to rely on a user
clicking a button to get the movie to jump to a certain frame? In other words,
will I be able to get gotoAndPlay() to work as I'm hoping?

fb
mandingo
8/5/2004 12:47:13 AM
I am not sure how you want it to work... but say you want it to sit for a short
period once it loads (say 3 secs) then play to the end from frame 3...

this.createEmptyMovieClip("mcRedBGround",11);
loadMovie("SWFs/RedBackground.swf",this.mcRedBGround);

delayOnLoad = function(){
clearInterval(loadDelay);
mcRedBGround.gotoAndPlay(3);
}
loadDelay = setInterval(delayOnLoad,3000); // 3000 milliseconds is 3 secs

that will do it automatically... is that what you are looking to do?

cheers
Fish.boy
8/5/2004 12:51:16 AM
Hi,

Yes, that should do it - I know how many frames are in each SWF, and the frame
rates they are playing at, so I should easily be able to work out how long each
SWF needs to play and set the appropriate delay on the next SWF playing.

Thanks a lot for your help - I've used quite a bit of JavaScript, but this
ActionScript seems to be a whole new ball game!

Cheers,

fb
AddThis Social Bookmark Button