7 Replies Latest reply on Jul 27, 2009 1:55 PM by fenosc

    Customclass accessing children

    fenosc Level 1

      Hi there,
      I made a search looking for custom class problems but didn`t find anything about what I`m having trouble with. Witch I thought to be pretty weird. I think I may be doing something stupid.

       

      I have a customScrollBar_mc in my library which consists of 2 movieclips instanced as mcBar and mcBackGround.

       

      I exported customScrollBar_mc for actionscript with a custom class attached to it called CustomScrollBar and I UNchecked the export in frame 1 option (I left only the preloader things with that checked).

       

      Well, I made my CustomScrollBar class but the problem is. If I try something like this in its constructor
      mcBar.height = 10; or
      mcBackGround.width = 10;

       

      Flash tells me that those instances doesn`t exist.
      How can I make flash recognize them ?

       

      Here is some structure information:

      Project organization

      /Project
         /bin
         /src
           Main.as
           /sessions
             CustomScrollBar.as
             Session.as this class instances CustomScrollBar

       

       

       

      Export SWC is checked.
      Sourcepaths added are /src and /src/sessions
      Automatically declare stage instances is UNchecked.
      All my files have no PACKAGE especification (if I add "sessions" to the package name it tells me that it doesn`t especify the real location of the files. Don`t know why this happends.)

       


      Could anyone please help me with this ?
      Thanks in advance,
      Oscar

        • 1. Re: Customclass accessing children
          kglad Adobe Community Professional & MVP

          recheck export in frame 1 to test.  make sure both child movieclips exist in frame 1.

          • 2. Re: Customclass accessing children
            fenosc Level 1

            Hi kglad!

             

            Didn`t work.

             

            One thing though, you told be to be sure that they are on frame 1.

            Here is the thing, they are not. I instance my CustomScrollBar during my code in the Session.as and the errors telling me the mcBar and mcBackGround don`t exist happen in the CustomScrollBar constructor, where I change some of their values.

             

            Something like

             

            var scroll:CustomScrollBar = new CustomScrollBar();

             

            and inside the constructor is

            mcBar.height = 10;

             

            Any idea ?

            • 3. Re: Customclass accessing children
              fenosc Level 1

              upping the topic so it wont be forgotten

              sorry about this.

               

               

              What I could do to fix this is instance a CustomScrollBar from my library into my CustomScrollBar class, but that seems a little redundant to me. I don`t think that is the best way to solve this problem...

              Since the class already represents my object in the library, it should have access to its children.

              Thanks again

              • 4. Re: Customclass accessing children
                fenosc Level 1

                Hi there, the topic was on the 4th page so I decided to make some screenshots and explain better this so it would be easier to help me out.

                I don`t have a clue about it and I just crossed a point where I can`t go any further without this.

                 

                I took a photo of my publish settings, library, movieclip properties andproject folder so you can understand what is happening.

                First of all, the problem is related to the topico_mc movieclip (translation: topic_mc)

                 

                topico_mc is composed by:

                movieclip topico_quadrado_mc (translation: square_topic_mc) that is just a small square: mcSquare

                dynamic text: dynText

                 

                I export it to actionscript with class name TopicosFlash and unchecked export in frame 1 (I tested with this checked too). I also tried browsing my symbol in the Source field just as shown in the screenshot.

                 

                I make the TopicosFlash.as file, make it extends movie clip and add a simple code to the constructor: mcSquare.alpha = 1

                In the document class I simply add it: addchild(new TopicosFlash());

                 

                The issue: mcSquare is a undefined property

                Screenshot:

                http://img24.imageshack.us/img24/6344/telasflash.jpg

                 

                Trying to solve this I found some things that for me were strange:

                1) If I don`t make the TopicosFlash.as file, the movieclip is added with no problems.

                2) If I make the TopicosFlash.as file but let it empty flash throw an error: Cannot create property dynText on TopicosFlash.

                3) If I make the file, it gives the mcSquare undefined error.

                 

                Sorry for the bad words but wtf is going on?

                I really am not being able to understand this and I can`t find any answers anywhere.

                 

                Thanks in advance,

                Oscar

                • 5. Re: Customclass accessing children
                  Rothrock Level 5

                  You haven't shown your class file. But in the variable declaration do you have a line such as:

                   

                  public var mcSquare:Movieclip;

                   

                  If you don't how is the constructor to know that this class has such a thing?

                  • 6. Re: Customclass accessing children
                    fenosc Level 1

                    Hi there,


                    Thanks for the answer!

                    Well, I didn`t declare any mcSquare variable because since the whole movieclip was exported with a custom class, that custom class should have access to its children. But that is not happening in my case.

                    Well, I did try what you said, I declared a variable a variable mcQuadrado but it doesn`t work either.

                     

                    If I don`t have a custom class, I can instance my topic_mc movieclip with no problems. I can also access its children with objectName.childrenInstanceName command. But with custom class I`m not able to.

                     

                    Here is what I want to do.

                    In Flash IDE I want to have lots of topic_mc objects with different instance names and by code I`ll change their content and some of their behaviors.

                    This way I can position them all in flash IDE and change their content by coding. This makes my life much easier since I don`t have to make different buttons for different contents. I just nee to change the content by code and the rest will be automatic.

                     

                    But this class problem is not alowing me to do that and I`m strangely thinking that this might not be possible? If that is right, I don`t have any ideas on how and why using custom classes.

                     

                    Still needing help with this matter =(

                    Oscar

                    • 7. Re: Customclass accessing children
                      fenosc Level 1

                      Hi again Rothrock.

                      Problem solved! You were right!

                       

                      But with your explanation alone I couldn`t do it. A guy in other forum told me that PUBLIC is a must. I was trying with private (I like making my classes closed, but I didn`t think it would be a problem until now).

                       

                      I didn`t imagin either that I would need to add the instances as children again. By doing so I though i would be adding anothe instance of objects that are already there.. but hey... it is not what happened.

                       

                      Now I`m able to continue.

                      Thanks alot.

                      Oscar