6 Replies Latest reply on Aug 8, 2006 4:51 PM by Ignitrix

    AS 3 - Referencing and unloading child MC's

    Ignitrix
      I'm using AS 3 in Adobe Flash 9 Public Alpha.

      I have a MovieClip named "RandImg" in my Library with an associated "RandImg.as" class file. I'm placing this MC on the stage during design time. This MC contains an instance of another MC with with the instance name of "mcDefault". In the constructor of my RandImg.as class file, if I attempt to reference mcDefault, I get the following error when I try to compile:
      ReferenceError: Error #1056: Cannot create property mcDefault on RandImg.
      How do I reference this movie clip in AS 3?


      Also, if I want to remove mcDefault from memory, but keep the RandImg MC in memory, in the "RandImg.as" class file would I just call: removeChild( mcDefault ); ?


      Thanks!
      ~JC
        • 1. Re: AS 3 - Referencing and unloading child MC's
          Level 1
          Hi,

          can you give us a bit of code ... that will help. And did you declare your movieClip before (and outside of) the constructor? Like this i mean:

          class RandImg{

          private var mcDefault:MovieClip; // --> here it is .. mcDefault

          public function RandImg(){ // --> cunstructor
          trace("mcDefault path = " + mcDefault);
          }
          }

          If mcDefault is not declare before and outside your constructor, its impossible for your class to access it. Of course you are probably aware of that .. but im trying to figure out what can be the problem .. just guessing.

          So please give us some code and we will try to help!
          • 2. AS 3 - Referencing and unloading child MC's
            Level 1
            sorry ... this site geve me an error so i reposted ... but to find that my first post was double! Sorry again!
            • 3. AS 3 - Referencing and unloading child MC's
              Level 1
              Is there a way to delete our own post in this forum?
              • 4. Re: AS 3 - Referencing and unloading child MC's
                Level 1
                Hi,

                can you give us a bit of code ... that will help. And did you declare your movieClip before (and outside of) the constructor? Like this i mean:

                class RandImg{

                private var mcDefault:MovieClip; // --> here it is .. mcDefault

                public function RandImg(){ // --> cunstructor
                trace("mcDefault path = " + mcDefault);
                }
                }

                If mcDefault is not declare before and outside your constructor, its impossible for your class to access it. Of course you are probably aware of that .. but im trying to figure out what can be the problem .. just guessing.

                So please give us some code and we will try to help!
                • 5. Re: AS 3 - Referencing and unloading child MC's
                  Ignitrix Level 1
                  Thanks for responding butcho. I did, of course, declare protected var mcDefault:MovieClip; before my constructor with the rest of my variables. I did some more messing around, it appears that in Flash 9 and AS3, the problem is that I can't actually have a named MC inside of a parent movie clip that has an associated class..? If I place mcDefault on the stage inside of RandImg during design time, the swf compiles properly. However, if I give the mcDefault an instance name, and do nothing else different, then I get my compile error: ReferenceError: Error #1056: Cannot create property mcDefault on RandImg. I don't get it; this used to work great in AS2...
                  • 6. AS 3 - Referencing and unloading child MC's
                    Ignitrix Level 1
                    I found the answer in another thread (thanks Raymond Basque):
                    http://www.adobe.com/cfusion/webforums/forum/messageview.cfm?catid=612&threadid=1169750

                    Apparantly, you have to declare the variable as public (which seems counter-inuitive since a big part of AS3 was better OOP and data-encapsulation). But alas, at least for now, it will have to do...