PDA

View Full Version : setChildIndex - Stumped



aroundTheBlock
March 11th, 2009, 11:13 PM
This is my fist time posting, please excuse my ignorance.

I’m loading four external swf file and attempting to switch childIndex to 0 with a event listener, listing for Mouse_Down.

I’ve tried several methods and can’t get a positive result.

Any help is greatly appreciated.



//Request Photos and add them to the satge
//Load Photo One to stage
var imageReq:URLRequest = new URLRequest("poloroid.swf");
var imageLoader:Loader = new Loader();
imageLoader.load(imageReq);
addChild(imageLoader);

imageLoader.contentLoaderInfo.addEventListener(Eve nt.COMPLETE, p1Complete);

function p1Complete(event:Event):void{
trace ("I'veloaded photoOne");
var p1:MovieClip = MovieClip(imageLoader.content);
p1.addEventListener(MouseEvent.MOUSE_DOWN, onClick);
p1.addEventListener(MouseEvent.MOUSE_UP, onUp);

function onClick(event:MouseEvent):void{
//need function to change childIndex
event.target.setChildIndex(event.target, numChildren - 1)
p1.startDrag();

}

function onUp(event:MouseEvent):void{
p1.stopDrag();
}

}

//Load Photo Two to stage
var imageReq2:URLRequest = new URLRequest("poloroid2.swf");
var imageLoader2:Loader = new Loader();
imageLoader2.load(imageReq2);
addChild(imageLoader2);

imageLoader2.contentLoaderInfo.addEventListener(Ev ent.COMPLETE, p2Complete);

function p2Complete(event:Event):void{
trace ("I'm loaded photoTwo");
var p2:MovieClip = MovieClip(imageLoader2.content);
p2.addEventListener(MouseEvent.MOUSE_DOWN, onClick);
p2.addEventListener(MouseEvent.MOUSE_UP, onUp);

function onClick(event:MouseEvent):void{
//need function to change childIndex
event.target.setChildIndex(event.target, numChildren - 1)
p2.startDrag();

}
function onUp(event:MouseEvent):void{
p2.stopDrag();
}

}
//Load Photo Three to stage
var imageReq3:URLRequest = new URLRequest("poloroid3.swf");
var imageLoader3:Loader = new Loader();
imageLoader3.load(imageReq3);
addChild(imageLoader3);

imageLoader3.contentLoaderInfo.addEventListener(Ev ent.COMPLETE, p3Complete);

function p3Complete(event:Event):void{
trace ("I'm loaded photoThree");
var p3:MovieClip = MovieClip(imageLoader3.content);
p3.addEventListener(MouseEvent.MOUSE_DOWN, onClick);
p3.addEventListener(MouseEvent.MOUSE_UP, onUp);

function onClick(event:MouseEvent):void{
//need function to change childIndex
event.target.setChildIndex(event.target, numChildren - 1)
p3.startDrag();
}
function onUp(event:MouseEvent):void{
p3.stopDrag();
}

}
//Load Photo Four to stage
var imageReq4:URLRequest = new URLRequest("poloroid4.swf");
var imageLoader4:Loader = new Loader();
imageLoader4.load(imageReq4);
addChild(imageLoader4);

imageLoader4.contentLoaderInfo.addEventListener(Ev ent.COMPLETE, p4Complete);

function p4Complete(event:Event):void{
trace ("I'm loaded photoThree");
var p4:MovieClip = MovieClip(imageLoader4.content);
p4.addEventListener(MouseEvent.MOUSE_DOWN, onClick);
p4.addEventListener(MouseEvent.MOUSE_UP, onUp);

function onClick(event:MouseEvent):void{
//need function to change childIndex
event.target.setChildIndex(event.target, numChildren - 1)
p4.startDrag();

}
function onUp(event:MouseEvent):void{
p4.stopDrag();
}

}I'm using the the following code to get Number of children of Stage, What are children of Stage, Number of children of MainTimeline, What are children of MainTimeline


// GET Object Diplay information

trace("Number of children of Stage: ");

trace(stage.numChildren);

trace("What are children of Stage: ");

trace(stage.getChildAt(0));

trace("What does the keyword this refer to? ");

trace(this);

trace("Number of children of MainTimeline: ");

trace(this.numChildren);

trace("What are children of MainTimeline: ");

trace(this.getChildAt(0));

trace(this.getChildAt(1));

trace(this.getChildAt(2));

trace(this.getChildAt(3));

trace(this.getChildAt(4));

trace(this.getChildAt(5));

trace(this.getChildAt(6));

trace(this.getChildAt(7));

trace(this.getChildAt(8));

trace(this.getChildAt(9));

trace(this.getChildAt(10));

trace(this.getChildAt(11));

trace(this.getChildAt(12));

trace(this.getChildAt(13));

trace(this.getChildAt(14));

trace(this.getChildAt(15));Output:
Number of children of Stage: 1
What are children of Stage: [object MainTimeline]
What does the keyword this refer to? [object MainTimeline]
Number of children of MainTimeline: 16
What are children of MainTimeline:
[object MovieClip]
[object SimpleButton]
[object contactFormMC_3]
[object SimpleButton]
[object SimpleButton]
[object TextField]
[object SimpleButton]
[object SimpleButton]
[object MovieClip]
[object songInfo_mc_43]
[object pineBoard_mc_44]
[object Sprite]
[object Loader]
[object Loader]
[object Loader]
[object Loader]

At this point I'm starting to think I'm coding this whole thing wrong, nesting the eventListener, might be part of my issue.

Again, any help is greatly appreciated.