[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 691
  • Last Modified:

setChildIndex not working

for some reason i cannot get the close btn be on top...
any thoughts

var defaultSWF:URLRequest = new URLRequest("empty.swf");
//*****====================================================*****
contentLoader.load(defaultSWF);
addChild(contentLoader);
TweenMax.to(contentLoader, 1, {x:destX, y:destY, alpha:1});
//*****====================================================***** 
function closeContent(e:MouseEvent):void{
			TweenMax.to(closeBtn, 1, {alpha:0});
			TweenMax.to(contentLoader, 1, {alpha:0, onComplete:onFinishFade});
			function onFinishFade():void {
				buttonsDown.reverse();
				removeChild(contentLoader);
		}
		}
//*****====================================================*****
function looping(e:ProgressEvent):void {
		loadMC.visible = true;
        var perc:Number = Math.round((e.bytesLoaded / e.bytesTotal) * 100);
        loadMC.txtPercent.text = perc + "%";
		}
function clicked(event:MouseEvent):void{
        transLoad(event.target.name + ".swf");
		TweenMax.to(closeBtn, 1, {alpha:1, delay:2});
		setChildIndex(closeBtn,numChildren - 1);
		}
function transLoad(url:String):void{
        if(contentLoader.content){
                buttonsDown.play();
				TweenMax.to(contentLoader, 0, {alpha:0, onComplete: transIn, 
							onCompleteParams: [url], delay:1});
        } else {
                transIn(url);
        }
		}

function transIn(url:String):void{
		addChild(contentLoader);
        contentLoader.load(new URLRequest(url));
		}
function fadeIn(event:Event):void{
		loadMC.visible = false;
        var fader:TimelineMax = new TimelineMax();
			fader.append(TweenMax.to(contentLoader, 0, {alpha:0}));
        	fader.append(TweenMax.to(contentLoader, 0, {x:destX, y:destY}));
        	fader.append(TweenMax.to(contentLoader, 1, {alpha:1, delay:1}));
		}
//*****====================================================*****

Open in new window

0
chefkeifer
Asked:
chefkeifer
  • 4
  • 3
  • 3
  • +1
1 Solution
 
TanLiHaoCommented:
It will better if you post the source file but if for some reason you can't, here's how you can test what setChildIndex did.

Change this function

function clicked(event:MouseEvent):void{
        transLoad(event.target.name + ".swf");
                TweenMax.to(closeBtn, 1, {alpha:1, delay:2});
                setChildIndex(closeBtn,numChildren - 1);
                }


to

function clicked(event:MouseEvent):void{
        transLoad(event.target.name + ".swf");
                TweenMax.to(closeBtn, 1, {alpha:1, delay:2});
                trace(getChildIndex(closeBtn));
                setChildIndex(closeBtn,numChildren - 1);
                trace(getChildIndex(closeBtn));
                trace(numChildren);
}


Tell me what is in the output after this code is changed.

Providing me your source file will make things quicker but if you can't for some reason, we have to go step by step.
0
 
72lionsCommented:
try the following
this.setChildIndex(closeBtn,this.numChildren - 1);

Open in new window

0
 
TanLiHaoCommented:
Actually @72lions, I do not think that will make a difference because the this operator can be omitted so it doesn't makes code look messy. The book Essential Actionscript 3.0 has a section mentioning that actually.

Nevertheless, I think it's worth a try though I'm pretty positive it wouldn't make a difference.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
72lionsCommented:
It would be better to give us the source code so that we can help you better
0
 
72lionsCommented:
@TanLiHao, you are right, but I'm guessing it's worth a try. I would prefer if we could get our hands on the source code.
0
 
chefkeiferAuthor Commented:
TanLiHao:

I am getting the numbers
7
8
9
0
 
chefkeiferAuthor Commented:
here is my source file
body-TDG.fla
0
 
blue-genieCommented:
I just got an email saying this question was neglected but you guys are busy with it.

if you're getting 7,8, and 9 then your code is working perfectly, because you're close btn is at index 7  but you want it at 8 (numChildren - 1) so if it's not displaying correctly maybe you're just confused about what index it actually needs to be at.
0
 
chefkeiferAuthor Commented:
I just want the closeBtn to be on top of everything..
isnt that the code for it?
0
 
blue-genieCommented:
in theory yes. but if you're adding other stuff dynamically at runtime, i.e. using addChild(whatever) - those will always be on top of what's placed on the stage.

what i would recommend is instead of placing the button on the stage, in the library give it a linkageID (properties) - i.e. CloseBtn

you don't need to create a seperate class if you don't want to flash will create one for you.
and then add it when you want it to the stage. that way it will be on top.
0
 
chefkeiferAuthor Commented:
if i bring it in dynamically how do i make it a button..i get errors from the eventListeners i have set up already...

would i just put that code inside of the movieclip instead on the main timeline
0
 
blue-genieCommented:
no you can't put code inside a movieclip anymore in AS3.
I'm assuming you're getting a NULL error.

standard AS3 OOP procedure.

1. declare the object

var objectName:ObjectType;

2. instantiate it

objectName = new ObjectType(); //in your case MovieClip

3. now that it exists add the listeners

objectName.addEventListener ........


4. add to displayList

addChild(objectName)



0
 
TanLiHaoCommented:
@blue-genie, I guess chefkeifer may have meant that whether he should put the code inside the movieclip, not on the movieclip which is not possible anymore in AS3.

I guess he might be getting a compiler error or a runtime error depending if he is compiling in strict or standard mode but anyway @chefkeifer you should do what blue-genie just said though you can very well put inside the movieclip but that will make code not as manageable so it's better to follow what blue-genie just said.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 3
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now