all groups > flash actionscript > july 2005 >
You're in the

flash actionscript

group:

_no['rhyme'].nor.reason = ahhhhhh


_no['rhyme'].nor.reason = ahhhhhh jesus102984783093987
7/14/2005 10:03:45 PM
flash actionscript:
This has got to be the #1 question:
Is there a chart of something somewhere that explains how to target vars and
instances, movieclips, etc. from different objets,depths, etc??

And why are the paths to attachMovie MCs different in the browser when served
from the website rather than previewed locally?

I'm loosing my mind.
Re: _no['rhyme'].nor.reason = ahhhhhh David Stiller
7/14/2005 10:16:48 PM
[quoted text, click to view]

lol Crackin' me up, Jeckyl.

To jesus102984783093987 (I thought there were only 102984783093986
Jesuses): As Jeckyl mentioned, paths are pretty much straight forward.
Since you used brackets in your subject line, I'll make a guess that you're
confused about when to use brackets and when not to when referencing movie
clip instances and other objects.

Normal dot notation should be familiar enough to anyone who uses folders
on a hard drive. Mac, Unix, Linux, Windows, you name it ... files live in
folders, and folders can be stacked in folders, and eventually you hit
bottom. In Flash, the bottom is _root or a level number _level0, _level1,
etc. If you had a clip with the instance name clipA and another inside it
with the instance name clipB in the main timeline, your path might be
expressed ...

_root.clipA.clipB

If you had a third clip in the main timeline, clipC, its path might be
expressed ...

_root.clipC

Now, from clipC's point of view, clipB could be expressed like this ...

_parent.clipA.clipB

.... because _root is the parent of both clipC and clipA. Make sense? Of
course, from clipC's point of view, the first example we looked at ...

_root.clipA.clipB

.... makes equally valid sense. Having said that, it's a good idea to get
used to relative pathing (with _parent and this), because you might, for
example, load your current SWF into another ... at which point the
*container* SWF's main timeline becomes the _root (no longer so the main
timeline of the *contained* SWF). So don't depend on the _root reference
unless you absolutely know you can.

So where do the brackets come into play? Well, they're known as the
array access operator. When they're not used in arrays, they can be used to
make object paths with strings instead of actual paths. So, for instance
....

_root["clipA"].clipB

.... is the same as ...

_root.clipA.clipB

.... even though the center part is a string. For that matter, these are all
equivalent:

_root["clip" + "A"].clipB
_root["cl" + "ip" + "A"].clipB

var str = "clip";
_root[str + "A"].clipB

.... and so on.

And really, that's all there is to it. Use the array access operator if
you need to create a path dynamically; otherwise, you generally don't need
it.


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

Re: _no['rhyme'].nor.reason = ahhhhhh Jeckyl
7/15/2005 12:00:00 AM
[quoted text, click to view]

Hardly

[quoted text, click to view]

Everything is targetted the same way .. using dot notation. It either
starts from a special target (_root, _leveln, _parent, this) or from the
current context object (possibly added to by any 'with' statements) and then
follows from there similar to folders. A chart would be pretty useless as
the details of how to get to a given target depends on where it is.

[quoted text, click to view]

they aren't .. do you have an example where you think they are?

[quoted text, click to view]

did you look where you last had it? its always in the last place you look
anyway.

Jeckyl

Re: _no['rhyme'].nor.reason = ahhhhhh jesus102984783093987
7/15/2005 10:49:45 AM
<David>
_root["clipA"].clipB

... is the same as ...

_root.clipA.clipB
</David>

Are you sure?

I find that this works:

this.varName or this[clip_instance_Name]

and this does not work:

this.clip_instance_Name

# I'm good on the other problem. I was using attachMovie and used such similar
linkage id and instance names that I got them switched all through the script.
You can imagine what havoc that can cause.


Re: _no['rhyme'].nor.reason = ahhhhhh mandingo
7/15/2005 11:15:11 AM
Yes, In David's example they are the same...

in your example however, they are different...

David was evaluating a string reference to a movieClip using the array
notation "[ ]" and basically it allows you to dynamically reference multiple
clips from the same generic string (great for loops) but each instance actually
exists as _root.clipA etc.

In yours, you are evaluating a variable reference but the difference is whilst
it will evaluate correctly, it DOESN'T exist anywhere as
this.clip_instance_Name. clip_instance_Name is only a reference to the clip
that is currently pointed to by the variable.

I hope that makes sense
cheers,
Re: _no['rhyme'].nor.reason = ahhhhhh Rothrock
7/15/2005 12:01:16 PM
Or even more plainly.

In David's example in the first way "ClipA" is in quotes. In your first
example clip_instance_Name isn't. Which, of course seems odd, because both of
those examples work, but for different reasons.

To paraphrase mandingo, it is the difference between a string and a variable.
AddThis Social Bookmark Button