5 Replies Latest reply on Dec 22, 2008 1:28 PM by kglad

    Referencing a instance inside a Class

    Level 7
      Hi --

      I am working on converting a movie clip to a Class so that I can more easily
      reuse it in later projects.

      I have pretty succesfully converted my AS code from my include file to a
      Class file. However, I have two objects on the stage, topBG and botBG and
      whenever I reference these items inside my code, such as botBG._y I get an
      error at compile time saying "There is no property with the name 'botBG'"
      How can I set it so these assets can be referred to inside my code?

      The code worked fine when it was just a movie.. Also, this is ActionScript
      2.0.

      Thanks

      Rich


        • 1. Re: Referencing a instance inside a Class
          kglad Adobe Community Professional & MVP
          among the ways, you can give your class access to the main timeline so it can reference anything in your swf. you can do that by passing a timeline reference in your constructor:

          var tl:MovieClip = this;
          var yourclass:YourClass=new YourClass(tl);
          • 2. Re: Referencing a instance inside a Class
            Level 7
            Hi --

            Thanks. I will give this a shot, although now I'm not 100% sure I phrased my
            question correctly -- the instance I am trying to access is inside the class
            (on the time line of the movie clip I am converting to a class). However, I
            get an error at compile time when I refer to this instance.

            Thanks

            Rich

            "kglad" <webforumsuser@macromedia.com> wrote in message
            news:gi94sc$70t$1@forums.macromedia.com...
            > among the ways, you can give your class access to the main timeline so it
            > can
            > reference anything in your swf. you can do that by passing a timeline
            > reference in your constructor:
            >
            > var tl:MovieClip = this;
            > var yourclass:YourClass=new YourClass(tl);
            >


            • 3. Re: Referencing a instance inside a Class
              kglad Adobe Community Professional & MVP
              you want class instances to be able to reference each other?
              • 4. Re: Referencing a instance inside a Class
                Level 7
                Hi --

                Thanks for responding. What I had created was this:

                I have a movie clip, "MainClip" with two movie clips ("ClipA" and "ClipB")
                inside that clip.

                I put MainClip on the stage (_root) and had Actionscript code in the main
                time line. I referenced ClipA & ClipB this way:

                MainClip.ClipA
                MainClip.ClipB

                Now, I want to turn MainClip into a class, "classMainClip". However, having
                moved the Actionscript into the class AS file and changed the above
                reference to just

                ClipA
                ClipB

                I get an error at compile time.

                How do I refer to the movie clips, "ClipA" and "ClipB" inside the
                actionscript that is the over lying class of which I want these clips to be
                a part?

                Hopefully I've explained this right.

                Thanks,

                Rich

                "kglad" <webforumsuser@macromedia.com> wrote in message
                news:gibuh8$qbh$1@forums.macromedia.com...
                > you want class instances to be able to reference each other?


                • 5. Re: Referencing a instance inside a Class
                  kglad Adobe Community Professional & MVP
                  you have the correct reference. you just need to declare those in your class:

                  var ClipA:MovieClip;
                  var ClipB:MovieClip;