FORUMS: list search recent posts

AS3 and layers

COW Forums : Adobe Flash

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Neil Bradley
AS3 and layers
on Jun 14, 2009 at 4:15:49 am

Can you take a look at this snippet of AS3 and tell me if what I am asking in the if else clause is possible?

greenButton.addEventListener ( MouseEvent.CLICK, clickGreen )
function clickGreen( evt ):void {


if (green_mc is at the front of the stack or has anything behind it) {
green_mc.x = 0;

}else{
addChild(green);
green_mc.x = 200;
}



Return to posts index

Pieter Helsen
Re: AS3 and layers
on Jun 14, 2009 at 9:31:04 am


var index:int = getChildIndex(green_mc) // get the z-position of green_mc
var num:int = numChildren - 1; // get the amount of children and subtract it by one

if(index == num){
// if green_mc has the highest child index
}else{
// green_mc is not on the top layer
}


Kind regards,
Pieter

General notice: from now on, I would like to ask everyone to put [AS2] or [AS3] (corresponding to the version of actionscript you are using on your project) in front of their post titles when the question is actionscript related! Please help us help you faster. Thank you.


Return to posts index

Neil Bradley
Re: AS3 and layers
on Jun 14, 2009 at 10:55:24 pm

Thanks for that,
it looked like it should work but not quite there yet. When green_mc is the first in the stack the if, else statement is not picking it up
Here is the complete snippet:


var index:int = getChildIndex(green_mc) // get the z-position of green_mc
var num:int = numChildren -1; // get the amount of children and subtract it by one

greenButton.addEventListener ( MouseEvent.CLICK, clickGreen )
function clickGreen( evt ):void {

if(index == num){
addChild (green_mc)
green_mc.x = 400;
green_mc.alpha = 1

}else{
addChild (green_mc)
green_mc.x = -70
var myTween4:Tween = new Tween(green_mc, "alpha", Strong.easeOut, 0, 1, 2, true);
}
}


Return to posts index


Pieter Helsen
Re: AS3 and layers
on Jun 15, 2009 at 8:33:40 am

The variables should be declared -inside- the event handler.

Trace both values so you can see if you're getting the right numbers

Kind regards,
Pieter

General notice: from now on, I would like to ask everyone to put [AS2] or [AS3] (corresponding to the version of actionscript you are using on your project) in front of their post titles when the question is actionscript related! Please help us help you faster. Thank you.


Return to posts index

Neil Bradley
Re: AS3 and layers
on Jun 15, 2009 at 8:35:01 pm

Yes, of course.
It works perfectly now. Thanks for your imput.
N



Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2018 CreativeCOW.net All Rights Reserved
[TOP]