Hi there kirupees…
I’ve got this problem with an app that I’m writing - probably because I’m new to OOP & AS3 so forgive me if it’s just school boy stuff!
I’m trying to show 9 instances of a “BkgMatch” movie which each contain three buttons, A, B & C which will trigger various new “pages” to load. I’ve got the movie to animate onto the stage & each instance contains the 3 buttons, all created by a simpleBtn class, but when the buttons are clicked I get a runtime error;
ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
at flash.display::DisplayObjectContainer/getChildIndex()
at formGuide/::mouseDownHandler()
Here’s some of the code…
package
{
// assume we import all the stuff we need here, and probably loads we don't!
// ...
//
public class formGuide extends MovieClip
{
showMatches()
}
private function showMatches():void
{
// create 9 instances of movie BkgMatch
var i:Number;
for (i = 0; i < 9; i++) {
var y:Number;
y = 300 + (i * 110);
var newMatch:BkgMatch = new BkgMatch();
// set constant for initial y offset for tween start
var start_y:Number= 300;
// Setting the match's X and Y position
newMatch.x = 48;
newMatch.y = start_y;
newMatch.name = "MatchID_" + i;
newMatch.MatchID.text = newMatch.name;
this.addChildAt(newMatch,10);
// add 3 btns to the MC instance
for (var n:Number=1; n <=3; n++)
{
var mName:String = new String();
var xOffSet:Number = new Number();
if (n == 1) {
mName = "A_" + i;
xOffSet = 50;
} else if (n == 2){
mName = "B_" + i;
xOffSet = 250;
} else if (n == 3){
mName = "C_" + i;
xOffSet = 450;
}
// calling the simpleBtn class to draw the btns
var btn:simpleBtn = new simpleBtn();
btn.makeBtns (mName);
// arrange the buttons in the movie
btn.x = xOffSet;
btn.y = 70;
// add the buttons to the Match MC instance
newMatch.addChild (btn);
// add an eventhandler to the button
// I think my problems start here...
btn.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
}
// move the matches on in an orderly fashion
var myPositionTween:Tween;
myPositionTween = new Tween(newMatch, "y", Regular.easeOut, start_y, y, 20, false);
}
}
// main eventhandler
private function mouseDownHandler(event:Object):void
{
// HERE'S THE PROBLEM!!!!
var i:uint = getChildIndex(event.target);
trace (i);
// etc...
}
}
Many thanks…
Ben