Is it possible to control 1 .swf from another .swf?

Hi all, I’m been a long time lurker of the forums and first time poster. I’m still pretty new to flash so please bear with me.

I’m making a page for my class project and so far I have 1 .swf that acts as a menu and I’m planning on making an .swf for the content for each of the buttons on the menu. So let’s say I have those all done and I place the menu .swf somewhere in the page and the main content .swf somewhere else in the page, is it possible for me to make the content movie switch by clicking on the menu buttons? Basically, is there a way to tell buttons in one .swf file to load different .swf’s in the same html page?

Thanks for any of your help.

i have this code come from an external button swf and it loads the movie into level5


on (press) {
	loadMovieNum("homelinks.swf", 5);
}

and on each external movie you should have


this._x = 50
this._y = 50

on the first frame of all your .swf’s so it knows where to load. Change the co-ordinates to whatever you need.

:love: ~ Seretha

Thanks Seretha :slight_smile:

I’m going to go play with it right now, wish me luck.

Just to update, your method works like a charm seretha :slight_smile:

I have another question though, now that I have a movie loaded is there a way to make it go to a certain frame by pressing a button on a different .swf?

I seem to be having no luck :frowning:

Yes there is, I’ve done this for creating my transitions ( when a button on main is clicked the external SWF goes to a certain frame ). What i did is this :

I made advantage of the fact that when an external movie is loaded into the main, they share the same root. I put a variable in _root (here it’s called [COLOR=RED]movietoplay[/COLOR]) that holds the name of the movieclip that should play when the button is clicked. I added this code to the buttons on the main swf :

[AS]on (release){_root.movietoplay = “any_value”}[/AS]

At the site i made using this i have buttons called SKINS, MAPS, …
So when you click skins, [COLOR=RED]_root.movietoplay[/COLOR] is set to [COLOR=RED]skins[/COLOR]. You should give this variable a name that suits the button.

In the external SWF, I’ve put a movieclip that checks if the variable [COLOR=RED]_root.movietoplay[/COLOR] has changed, and if it has, it goes to a certain frame :

[AS]onClipEvent(load){
_root.movietoplay = “nameofthecurrentmovie”
}
onClipEvent(enterFrame){
if (_root.movietoplay != “nameofthecurrentmovie”{
_parent.gotoAndPlay(framenumber)
}
}
[/AS]

Of course, the movie which you want to go to a certain frame has to have a stop(); action on the frame right before the frame number you want it to go when a button on the main stage is clicked

IMPORTANT:

  1. This movieclip has to be on the entire timeline until at the point where you want it to go to another frame when clicking a button on the main stage eg if you want the movie to go to frame 38 when a button on the main stage is clicked, the movieclip has be on the stage from frame 1 to frame 37, 37 included.

  2. There can NOT be a keyframe at the last frame in which the movieclip is on the stage ( in the example above, there can’t be a keyframe at frame 37 )

  3. This code will work if you put the movieclip on the timeline which you want to go to a certain frame. If not, the code _parent.goto… has to change accordingly to the stacking depth.

  4. At the last frame of the external SWF, these actions have to be applied :

[AS]_root.movieclipwhereyouloadinto.loadMovie(_root.movietoplay+".swf");[/AS]

This is an essential part: the filename you give the external SWF has to match the name you gave in the code above :

[AS]onClipEvent(load){
_root.movietoplay = “nameofthecurrentmovie
}
onClipEvent(enterFrame){
if (_root.movietoplay != “nameofthecurrentmovie”{
_parent.gotoAndPlay(framenumber)
}
}

nameofthecurrentmovie should match your filename eg if you would keep the variable nameofthecurrentmovie your fla ( and with it your SWF ) should be named nameofthecurrentmovie.fla
[/AS]

So here is what it will do: if a button on the main stage is clicked, _root.movietoplay changes value. The movie that is currently playing will detect this and go to the frame you specified, and when it’s done playing the frame(s) after that specific frame, it loads another mc. You can leave this option out, just delete the code of the last frame at the external SWF.

Wow i’ve typed so much that somebody has probably already answered :beam:

wow thanks voet, I was actually on the same track but i still couldn’t get it to work. I’ll go try out your method and let you know how it turns out, thanks! :slight_smile:

Yeah, couldn’t get it to work for a long time either :slight_smile: Spent 3 hours debugging :beam: I’m glad I can share :slight_smile: