I'm trying to call a function in one child class (Circle.as) from another child class (Wedge.as). Circle.as is instantiated by the document class (Tree.as), and Wedge.as is instantiated by Circle.as. How do I do this? This is my code:
Tree.as
package com.treediagram
{
public class Tree extends MovieClip
{
var firstCircle:Circle = new Circle();
addChild(firstCircle);
}
}
Circle.as:
package com.treediagram
{
public class Circle extends MovieClip
{
private var wedge:Wedge;
public function Circle()
{
var circleHolder:MovieClip = new MovieClip();
var circleClip:MovieClip = new MovieClip();
circleClip.addEventListener(MouseEvent.CLICK,circleClickedEvent);
}
private function circleClickedEvent(e:MouseEvent):void
{
var wedgeHolder:MovieClip = new MovieClip();
circleHolderRef.addChildAt(wedgeHolder,1);
var wedge:Wedge = new Wedge(wedgeHolderRef);
wedge.addEventListener(MouseEvent.CLICK,wedgeClickEvent);
}
private function wedgeClickEvent(e.target){
trace ('click'); //NOT WORKING
}
}
}
Wedge.as
package com.treediagram
{
public class Wedge extends MovieClip
{
public function Wedge(wedgeHolderRef)
{
var wedgeClip:MovieClip = new MovieClip();
wedgeClip.addEventListener(Event.ADDED_TO_STAGE, wedgeAddedEvent);
wedgeHolderRef.addChild(wedgeClip);
}
}
}
I saw a similar question to this here:
How to call a function in a Class from another Class?
but it was a bit hard to follow as it relates to my problem. One of the solutions worked, but was commented as being bad form, and another did not work, so I want to make sure I structure my code properly.