2 Replies Latest reply on Oct 18, 2007 7:50 AM by Newsgroup_User

    AS3 Confusing!!!

    DJ_James Level 1
      I found that to use (what was orignally attachMovie) I had to create a linked mc in the library, then write a class for it.. which I've done.

      The only problem, is that the linked mc that I have created, has to interact with a function on the main timeline. I've never created my own classes before and this is just confusing me all to h-e double hockey sticks...

      How do I get a linked mc to do ANYTHING with functions on the main timeline?
        • 1. Re: AS3 Confusing!!!
          kglad Adobe Community Professional & MVP
          you can pass (to your class) a reference to your main timeline:

          • 2. Re: AS3 Confusing!!!
            Level 7
            DJ James,

            >I found that to use (what was orignally attachMovie) I had
            > to create a linked mc in the library, then write a class for it..
            > which I've done.

            Actually, Flash CS3 will write that class for you automatically. All
            you really have to do is supply a Linkage Class (which used to be a Linkage
            Identifier), and you'll get the little warning that Flash hasn't found that
            class and will write it for you. Is that were you currently are?

            > The only problem, is that the linked mc that I have created, has
            > to interact with a function on the main timeline. I've never
            > created my own classes before and this is just confusing me all
            > to h-e double hockey sticks...

            This perspective may help. At least, I hope it does! ;) Everything in
            ActionScript is already the result of a class. Classes define objects, just
            like a recipe defines an entree or a blueprint defines a house. Even in
            ActionScript 2.0 -- which you can still use in Flash CS3, by the way (just
            change the Publish Settings) -- what attachMovie() is really doing is
            creating an instance of the MovieClip class. In ActionScript 3.0, it's the
            same thing, just a more formalized. In both versions of the language, the
            attached movie clip is a subclass of MovieClip (a particular custom class
            the extends, or inherits from, MovieClip).

            In either version of the language, once that movie clip is on the stage,
            it interacts with the stage in the same way that a manually place movie clip
            does. In ActionScript 2.0, the stage *is* a movie clip, so it features all
            the same class members as a movie clip symbol does. What are class members?
            They're the categories you'll find under any of the class entries in the
            ActionScript 2.0 or 3.0 Language Reference. Generally, there are one or
            more of these three: properties (characteristics of the object), methods
            (things the object can do), and events (things the object can react to).
            All you need is a reference to the object in question, then an invocation of
            one of those members. That's why, for example, you can write ...

            _root.play();

            ... in AS2. _root refers to a MovieClip instance -- the main timeline --
            and the MovieClip class features a play() method. That's why you can also
            use this:

            this.play();

            ... provided that the code is sitting inside a MovieClip instance. When in
            a keyframe of the main timeline in AS2, the word "this" refers to the main
            timeline ... which, as we've already seen, is a MovieClip instance.

            Just as often, you'll give your movie clips instance names in the
            Property inspector (or via ActionScript). For a clip named myClip, for
            example, you could do this:

            myClip.gotoAndPlay(15);

            ... which would send *that clip* to frame 15 of its own timeline.

            In ActionScript 3.0, when you do your attaching, you'll use the "new"
            keyword:

            var mc:MovieClip = new MyLinkageClassHere();

            ... and that variable name, mc, is your reference to the new clip. In AS3,
            movie clips feature a name property (_name, in AS2) that represents the
            movie clip's instance name. That's the name you'd give it in the Property
            inspector. So you could so this:

            var mc:MovieClip = new MyLinkageClassHere();
            mc.name = "carrots";

            ... and refer to that attached movie clip as either mc or carrots from that
            point forward. The varible mc is your reference, and carrots is your
            instance name, which is just another reference.

            Now, The above two quick snippets are not technically 100% correct.
            While MyLinkageClassHere() -- a ridiculous name, true, but you get the
            idea -- is, indeed, a MovieClip instance (because it inherits from
            MovieClip), it is more specifically an instance of the MyLinkageClassHere
            class. So the above lines should actually be:

            var mc:MyLinkageClassHere = new MyLinkageClassHere();
            mc.name = "carrots";

            ... and, of course, you'd be using a much more descriptive class name than
            that.

            In both versions of ActionScript, movie clips have a parent property
            (_parent, in AS2) that refers to the timeline that contains the movie clip
            in question. Therefore ...

            mc.parent (or mc._parent)

            or

            carrots.parent (or carrots._parent)

            ... would reference the main timeline, assuming carrots was *in* the main
            timeline. And that's one way you could reference the main timeline from the
            point of view of your attached movie clip.

            Does that help?


            David Stiller
            Co-author, Foundation Flash CS3 for Designers
            http://tinyurl.com/2k29mj
            "Luck is the residue of good design."