John Albright
05/04/09
Action Script Independent Study - Project # 13

Source Code:
main
button class
video class
single link

I totally underestimated this one.  I wanted to turn this in last week but the logic was so weird I spent nearly all of the last three days figuring it out, but I did it, it figured it out.  Ok so this one looks simple, just a drop down menu right, nothing fancy there, wrong.  So to make explaining it lets explain one relationship, that between buttons.  There are parent buttons and child buttons.  Like a family tree, the button on top is the parent, it has children, then those children have children of their own making them parents themselves.  Setting mouse over and out triggers on all the buttons it is easy to make the hover states and to enable the children but the disable action is the tricky one.  When do the children need to go away?  When the mouse is no longer on the calling button or the children buttons.  How do we know when this is?  The out trigger is the same no matter if the mouse exits to the left(a parent button), to the right(to a child button), or up or down (to sibling buttons).  My first attempt to this problem was to have a flag on every button indicating if the mouse was above it. It was to be set true by the over event and set false by the out event.  This would have worked except that I learned the hard way that the out event of the parent is called before the over event of the child.  What this means is that there is a gap of time where the child has the mouse but does not yet realize it.  The solution to this was for me to write my own function in the code creating the logic for a child to ask the mouse where it is and then compare that answer with its own size and position returning to the calling function a Boolean answer.  This solved the current problem but revealed a new flaw in my logic.  The program now worked for a parent and any number of children but did not recognize the grand children. The logic for disabling the visibility of the children stated that if the mouse is not on the parent or a child to disable that part of the family tree.  The problem here is that when the mouse is on a grandchild it is neither on the parent or first child thus disabling that section of the family and making it impossible to get to the grandchildren. You could see the grand children but when you left the 1st child en route to the grand children everything disappeared. Because all the buttons including parents or any generation of children are all instances of the same class( and after excessive head scratching )I deduced that a recursive algorithm would solve this problem.  This is where a function calls itself in a repetitive manner working its way down the family tree until it reaches the bottom. The function first asks the current instances children and then itself, if any are true(has the mouse) it returns true.  If no children are found(bottom of the tree) it returns the value of the current node thus terminating the recursive behavior.  This solved my problem and I now had a working dropdown tree like menu.  It is really easy to activate the buttons to make them links but that was not the task at hand here.  As all of the buttons are actually references of external images I could have made a really flashy design for them, but that again was not the task at hand.  I just wanted the logic to work, making them pretty is just basic Photoshop work from here.  It is also important to note that parents contain their children but children are unaware of their parents.  Thus a child can not disable itself but must ask a parent to do it for them.  Logically this is the same concept as when the video ends playing it tells the parent object to dispatch the next video. Because the children are part of their parents, when a child is selected you'll notice this allows the parent to remain highlighted thus indicating all of the links connecting you to the top parent are active.   There is still a slight anomaly in the code that I have not been able to locate where if the mouse while on a child skips to its aunt or uncle the child still remains in place.  I am unsure as to the cause of this but will figure it out when I use this tool in my capstone portfolio project. Using the above logic you can add an indefinite number of children and siblings without modifying the code thus increasing its reusability for future projects. This project was insanely more complex than I expected but I learned so much in the process so I am glad I did it this way.