How can I get a button within a movie to play another movie?

How can I get a button within a movie to play another movie?

Post by Nick L » Sat, 03 Sep 2005 21:55:59


I'm currently trying to create a Flash based website using Loader Components
and external swfs. The master swf file has a menu bar at the top with buttons
that call up various external swfs in the appropriate Loader Component below.
These links work fine. The problem is I want to sometimes have a button in one
external swf that plays another swf at a different part of the timeline of my
master swf.

Can anyone tell me what the Actionscript should be for the button?
My Master movie is called: index.swf
The movie with the button is called: home.swf (Loader Component: home_ldr,
frame label: home)
The movie I want to link to is called: about_us.swf (Loader Component:
about_us_ldr, frame label: about_us)

Here's what I'm currently doing:
Each loader component has its own Instance name and is set to:
autoload: true, content path: (the appropriate .swf movie), scaleContent: False
The timeline is divided into sections. Each has a 'stop' command in 'Actions'.
Each has a Frame Label title. To create the button command, I select the
button, then go to 'Behaviour' - 'Movie Clip' - 'Go to and stop at frame or
label'. Where it says: 'Choose the movie clip ...' I leave it on 'this' and I
also leave 'Relative' selected. Where it says: 'Enter the frame ...' I type in
the Frame label title.
 
 
 

How can I get a button within a movie to play another movie?

Post by David Stil » Sat, 03 Sep 2005 22:40:00

ick,


This is certainly doable. It comes down to understanding how objects
interact in ActionScript, especially what paths they use to "see" each
other. Everything in Flash exists in a hierarchy, much like the documents
and programs on your hard drive. If you're on a PC, the root is generally
c:\, and in SWFs, the root is the keyword _root. Generally speaking, all
objects can refer to each other if they drop back to the _root and build up
again from there.

When you load external SWFs into an instance of the Loader Component,
the absolute path to that loaded SWF might be something like
_root.loaderInstance.content (since the Loader class has a content property,
which is a "reference to the content of the loader" -- see the ActionScript
Language Reference for full details). From that loaded SWF's point of few,
_root is the beginning of all things, as it is for any object. When run on
its own, _root would be the origination point of all paths in that SWF
alone, but once loaded, the term _root now refers to origination point of
all paths of the SWF's parent (that is, the SWF that contains instances of
the Loader Component). So if you have an internal movie clip -- internal to
the parent SWF -- whose instance name is myClipA, the loaded SWF should be
able to access myClipA by simply referring to ...

_root.myClipA

... assuming that myClipA resides in the parent clip's main timeline. If
not -- say, if myClipA was nested inside a clip with the instance name
myContainerA, that absolute path would be ...

_root.myContainerA.myClipA

... and again, this path wouldn't mean anything to the loaded SWF on its
own: that path doesn't exist in *that* SWFs hierarchy until it is loaded
into the parent, which *does* have that hierarchy.


Put yourself in the point of view of that loaded SWF and think through
what the path is to the intended recipient of your message.


So far, so good.


The word "this" is context dependent. When the word "this" is scoped to
a particular movie clip, "this" is synonymous with that clip; when "this"
appears in a frame script, "this" is synonymous with *that* object; i.e.,
the timeline. For example, "this" in a frame script of the main timeline
refers to _root.

So when your Behavior tells "this" to gotoAndStop(), the
MovieClip.gotoAndStop() method, which is what is triggered, applies to the
movie clip to which your Behavior is applied. What you want to do is
provide the correct path to the *other* movie clip, as described above.

Unfortunately, the Behaviors only go so far. They work in the expected
garden variety scenarios, but as soon as you step out of the box, so to
speak, they don't give you the wiggle room you may need to path to a given
object correctly. I recommend you applie a Behavior, then select that clip
and open the Actions panel to see exactly what ActionScript the Behavior
applied (all Behaviors do is write ActionScript for you -- you can do
everything they do, plus more).

Let me know if my discussion of paths makes sense to you. If not, we
can keep hacking away at your goal until you achieve it.


David
stiller (at) quip (dot) net
"Luck is the residue of good design."



 
 
 

How can I get a button within a movie to play another movie?

Post by Nick L » Thu, 08 Sep 2005 01:11:40

Thanks a lot, David for your in-depth reply

The magic word _root is just the trick!

Cheers

Nick