Jump to content
Search Community

Swapping layers

robtarren test
Moderator Tag

Recommended Posts

Hi guys, this is probably more of general Actionscript query than a specific Greensock one, but you guys are sooooo good I thought I'd try here first! ;)

 

I have picked out this particular pieces of code from my timeline that will expose an image from underneath another image that is on a different layer -

 

//code that calls the function to bring image to front

timeline.append( TweenMax.to(image_05, 1, {x:320, onStart:bringToFront, onStartParams:[image_05]}));

 

//function that brings the layer to the front

function bringToFront(object:DisplayObject):void {

object.parent.addChild(object);

}

 

This all very nice when first run, but the timeline is on an infinite loop so when it spins back round to the start again, the image that I've exposed is sat on top everything (until other layers start to take precedence)...booo! I'm a complete noob when it comes to Actionscript, I've had a search around and I see lots of things about swapdepths and removechild and I've given them all a whirl but I end up with errors galore!

 

Could someone help me simply reset the layer to it's original state when the loop restarts pleeeease?!

 

Cheers, Rob

Link to comment
Share on other sites

if its just that one image that needs to be sent to the back...

 

import com.greensock.*;

var tl:TimelineMax = new TimelineMax({repeat:-1});

tl.append(TweenLite.to(mc, 2, {x:400, onStart:sendToBack, onStartParams:[bg]}));
tl.append(TweenLite.to(bg, 1, {y:"-150"}));
tl.append(TweenLite.to(bg, 1, {y:"150", onStart:bringToFront, onStartParams:[bg]}));


function bringToFront(object:DisplayObject):void {
object.parent.addChild(object);
}

function sendToBack(object:DisplayObject):void {
//place object at bottom-most depth
object.parent.addChildAt(object, 0);
}


 

fla attached

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...