14 Replies Latest reply on Mar 3, 2010 3:41 PM by kglad

    I need help extending the MovieClip class

    ankhcomm

      I want to add a property to the MovieClip class. I just have a bunch of MovieClips that are placed on the stage by reading an XML file and creating lots of clips according to the information in them. Now, I need to know which MovieClips were created below previous clips, and I figure that the easiest way to do so would be by extending the MovieClip class and add an order property.

       

      I have some problems though: I don't know how to set or get this order property within the main clip, I don't know how to place this clip within my movie, and I don't know how to create them dynamically (do I just do something like var myNewObjectOfExtendedClass : myExtendedClassName = new myExtendedClassName?)

       

      This is the code I have on my extended class, called Expando.as:

       

      class Expando extends MovieClip {

      private var _order:Number;

      public function get order():Number {

      return _order;

      }

      public function set order(nOrder:Number):Void {

      _order = nOrder;

      }

      }

        • 1. Re: I need help extending the MovieClip class
          kglad Adobe Community Professional & MVP

          i'm not sure it makes sense to "...need to know which MovieClips were created below previous clips...". because all clips previously created are going to be below the most recently created movieclip.

           

          so, what exactly do you want to know?

          • 2. Re: I need help extending the MovieClip class
            ankhcomm Level 1

            Well, I'm creating my version of a Tree component.

             

            Basically, I need a Tree component that allows me to easily place an icon on each entry that will be different from other entries (rather than just replacing the defaultLeaf icon), allows me to have multi-line entries in the text, needs to behave differently if I click on the icon rather than on the text next to it, and some of that text next to the icon will be different links. I've spent a while tinkering with the Flash 8 Tree component and searching through the web and my conclusion is that it just doesn't work for what I need (and yes, this is probably one of the most convoluted things I've ever built, but it's how they want it).

             

            I need to know the order of the clips so that if I close, say, the second node of the Tree, all of its subnodes close as well and all of the nodes below it move up a certain number of pixels. Likewise, if I were to open the third node, the node below the third one should go down as many pixels as necessary to accomodate the subnodes opened by the third node, and so on. I mean, maybe there's an easier solution, but so far this seems to be the simplest one of the possibilities I've considered.

             

            (Edit: When I mean "below", I mean as in lower _y property, not as in lower depth. Sorry for the misunderstanding. Of course, now that I think about it, I could use the depth to figure this out, but backwards right, since the most recently created clips would have the highest depths right?)

            • 3. Re: I need help extending the MovieClip class
              kglad Adobe Community Professional & MVP

              aren't you using arrays to store your tree structure?

              • 4. Re: I need help extending the MovieClip class
                ankhcomm Level 1

                Should I? I already have them all inside the XML object.

                 

                What I am doing is that for every node of that XML, I create a movie clip. Then, I check which of those nodes have subnodes, and I create movieclips for those subnodes and so on. Of course, these "subnodes" are just slightly more indented to the right at this point as I haven't given them a _y yet, which is what I want.

                 

                Maybe I could use nested movieclips to make every node's children exist inside a movieclip representing the parent node, but I didn't think of that, and I'm not sure I know how to implement it that way. With my AS2 experience (new job, much higher use of scripting in this one than my previous one), that's about the best solution I can come up with so far. I must say this is really gonna push my AS2 skills though. Heck, I'm even starting to be interested in AS3, which looked extremely alien the first times I tried some tutorials (and I lost interest) with all of its package and imports and need to explicitly call every library.

                • 5. Re: I need help extending the MovieClip class
                  kglad Adobe Community Professional & MVP

                  you don't iterate through your xml each time a node is clicked, do you?  aren't you storing the xml data in flash?

                  • 6. Re: I need help extending the MovieClip class
                    ankhcomm Level 1

                    I go through every node to build the clips and their data only on the XML's onLoad function.

                     

                    I created a listener object on the mouse's onMouseUp event to serve as the trigger to know when to update the _y's of every movieclip (it's not iterating through the XML, all it will do is create a function that updates the _y of every object once I finally have that down; right now it's just tracing the value of a variable I set to know if it's working at all). I was thinking maybe it would be easier to have every movieclip broadcast a particular event when clicked and to have a listener object check for that event to do the updating rather than on every MouseUp, but I'll have to time to ponder that later (and the how's of doing it). My only concern right now is to properly position the _y's.

                     

                    var xmlExpandos:XML = new XML();  // <--- From my understanding, this variable already holds the XML values right?

                    xmlExpandos.ignoreWhite = true;

                    xmlExpandos.load("xml/expandos.xml"); // <---- The XML is parsed here right?

                    xmlExpandos.onLoad = function():Void  { ..... etc

                    • 7. Re: I need help extending the MovieClip class
                      kglad Adobe Community Professional & MVP

                      when node 1 is clicked how do you determine its subnodes?

                      1 person found this helpful
                      • 8. Re: I need help extending the MovieClip class
                        ankhcomm Level 1

                        Well, I was just planning to fib everything; this doesn't need to work 100%. It just needs to simulate another app for training purposes.

                         

                        Right now when I click the first node, it creates a space between it and the second node. My plan was to take the subnodes that should go there and place them in that space (they're already indented properly). I figured I'd need a variable that tells me how much space is needed as opening subnodes would increase the size of the space to push all other nodes lower on _y. I'd just use the _visible property to show or hide nodes. Basically, every single node exists on the clip on its own, but I was planning to use that "order' value I wanted to create in an extended movieclip to determine where each clip should be.

                         

                        However, I just created a trace function that returns each movieClip, its corresponding label in the XML, and its depth and I now realized that I have repeated depths and repeated movieclips, which means some are cannibalizing others right? Which means back to the drawing board for me; I guess the best solution is to create nested clips for this after all? Do and learn for me on this...

                        • 9. Re: I need help extending the MovieClip class
                          kglad Adobe Community Professional & MVP

                          i recommend you check for tree tutorial so you can see how this should be done.  i think you're missing some basics.

                          • 10. Re: I need help extending the MovieClip class
                            ankhcomm Level 1

                            You mean the Tree component?

                             

                            My concern with the Tree component (at least the AS2 version) is that I don't see a way to have each node in the Tree have different hit areas with different outcomes.

                             

                            The tree that I build must have up to 7 levels within each main branch, and not all of them behave the same way. In some branches, clicking the icon next to the label will have a completely different outcome than clicking on the label, which may or may not return a function. Each of those sublevels also need to support different icons, depending on what information is represented by it.

                             

                            Sample:

                             

                            • Reminders

                            • My Reminders
                            • Manual Reminders
                            • Escalated Reminders

                             

                            • Cases

                            • Name Actions < ---- this is where the problem begins. Clicking on the icon where the bullet should be should do something different than clicking on the name, which should do something different than clicking on the word Actions
                              • This is information about that referral that includes who referred them, the date of the referral, their full address. This information usually takes up 2 lines, sometimes 3
                                • Assignment   <------- you can only open see these leaves if you click on the bullet icon for the previous node; you can't open this by clicking on the text.
                                • Eligibility
                                • Etc., depending on what information has been appended

                            • Suppliers

                             

                             

                            Anyway, if the Tree Component can indeed support these features, I'd like to know where to find information about it please

                            In my search for that information, I concluded that I'd probably be better served by building my own MovieClip that can handle these requirements. I did have a working Tree component pretty quickly as I started this project, but then I got more familiar with the app that I'm building the training for and noticed these requirements.

                             

                            Of course, maybe all these features are supported by the AS3 Tree component. The problem is that I'm a lot worse with AS3 than I am with AS2 heh.

                            • 11. Re: I need help extending the MovieClip class
                              kglad Adobe Community Professional & MVP

                              no, i mean a custom tree app that you build yourself.

                              1 person found this helpful
                              • 12. Re: I need help extending the MovieClip class
                                kglad Adobe Community Professional & MVP

                                or, if you want to hire me to build one for you, that would be even easier for you.  but, you won't learn as much.

                                • 13. Re: I need help extending the MovieClip class
                                  ankhcomm Level 1

                                  Ahh yea. I thought you meant a tree tutorial for the Tree component in Flash.

                                   

                                  Yea, that sounds like a good idea I guess. I thought I could solve it with the methodology I was trying, but that crashed and burned.

                                   

                                  Anyway, many thanks for your help. I'm marking your replies as helpful and correct on the tutorial suggestion.

                                  • 14. Re: I need help extending the MovieClip class
                                    kglad Adobe Community Professional & MVP

                                    you're welcome.